Skip to content

Add asset script transform hooks - #11622

Open
swernerx wants to merge 3 commits into
remix-run:mainfrom
swernerx:codex/asset-script-transforms
Open

Add asset script transform hooks#11622
swernerx wants to merge 3 commits into
remix-run:mainfrom
swernerx:codex/asset-script-transforms

Conversation

@swernerx

@swernerx swernerx commented Jul 22, 2026

Copy link
Copy Markdown

Adds a public, ordered script transform hook to @remix-run/assets so integrations can transform browser-delivered application source without wrapping or proxying the asset server.

  • Adds scripts.transforms, which runs before Remix lowers TypeScript and JSX
  • Provides each transform with the absolute file path, public URL pathname, source format, dependency status, and current source map
  • Composes returned source maps with earlier transforms and the existing Oxc/minifier pipeline
  • Registers returned watchFiles with the existing module cache and watcher invalidation flow
  • Transforms symlinked npm, pnpm, and Yarn workspace packages by default while skipping installed or copied dependencies unless includeDependencies is enabled
  • Documents the API and adds package/remix change notes

Closes #11580.

import { createAssetServer } from 'remix/assets'
import { compileMessages } from './app/compile-messages.ts'

let assetServer = createAssetServer({
  basePath: '/assets',
  fileMap: {
    '/app/*path': 'app/*path',
    '/npm/*path': 'node_modules/*path',
  },
  allowFiles: ['app/assets/**'],
  allowPackages: ['remix'],
  sourceMaps: 'external',
  scripts: {
    transforms: [
      {
        name: 'messages',
        async transform(code, context) {
          if (context.format !== 'tsx') return null

          let result = await compileMessages(code, {
            filePath: context.filePath,
            format: context.format,
          })
          return {
            code: result.code,
            sourceMap: result.sourceMap,
            watchFiles: result.dependencies,
          }
        },
      },
    ],
  },
})

@swernerx
swernerx marked this pull request as ready for review July 22, 2026 19:11
@swernerx
swernerx force-pushed the codex/asset-script-transforms branch from 142241d to adf8376 Compare July 22, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an asset pipeline hook for script transforms

1 participant