Skip to content

Symfony Reprise

Edit this page

Webpack Encore gave Symfony first-class asset integration for Webpack. Symfony Reprise brings the same to Vite and Rsbuild.

Tip

Still using Webpack Encore? See Migrating from Webpack Encore below: it maps every Encore.* call to its Vite/Rsbuild or Reprise equivalent. Coming from pentatrion/vite-bundle instead? See Migrating from pentatrion/vite-bundle.

Vite and Rsbuild already handle Sass/Less/PostCSS, TypeScript, JSX/Vue/Svelte, code splitting, content hashing, source maps, minification and HMR on their own, so Symfony Reprise does not reimplement any of that. It covers only the Symfony-side glue the bundlers leave out:

  • Multiple entries: build several independent entry points from one config
  • Style entries: point an entry straight at a .scss/.css file and get CSS only, no stray <script>
  • entrypoints.json: generated in both build and dev-server modes
  • manifest.json: maps each logical filename to its hashed URL
  • Asset versioning: content-hash cache busting, wired into the manifest
  • File copy: copy static files into the build, keyed in the manifest
  • Dev server and HMR: points Twig at the running Vite/Rsbuild server
  • Multiple builds: drive several bundles (e.g. a main app and a separately-built embeddable widget) from one Symfony app
  • Twig tag rendering: reprise_entry_script_tags/reprise_entry_link_tags render straight from entrypoints.json
  • Symfony UX / Stimulus: registers controllers.json and local controllers, eager or lazy
  • CDN support: serve built assets from an absolute publicPath
  • Subresource Integrity: SRI hashes in entrypoints.json
  • Customizable tag attributes: RenderAssetTagEvent lets listeners add, change or remove attributes on every rendered tag

It generates the Encore-compatible entrypoints.json and manifest.json that RepriseBundle reads to render the <script> and <link> tags, wires up the native dev server, and turns your Stimulus controllers into a running application.

Installation

Install the bundle with Composer and Symfony Flex:

1
$ composer require symfony/reprise

Then install the npm package:

1
$ npm install @symfony/reprise --save-dev

Vite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// vite.config.ts
import { defineConfig } from 'vite'
import Symfony from '@symfony/reprise/vite'

export default defineConfig({
  input: {
    app: './assets/app.js',
  },
  plugins: [
    Symfony({
      // options
    }),
  ],
})

On Vite 8.1 and older, configure the entries with build.rollupOptions.input instead.

Rsbuild

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// rsbuild.config.ts
import { defineConfig } from '@rsbuild/core'
import Symfony from '@symfony/reprise/rsbuild'

export default defineConfig({
  source: {
    entry: {
      app: './assets/app.js',
    },
  },
  plugins: [
    Symfony({
      // options
    }),
  ],
})

Keeping both packages in sync

The symfony/reprise Composer package and the @symfony/reprise npm package are tagged together from the same commit and share one version number.

Their only contract is the entrypoints.json and manifest.json files the plugin writes and RepriseBundle reads. That format is covered by the Backward Compatibility promise, so a change on one side does not break the other within a major version. A minor or patch mismatch between the two packages keeps working.

Unlike Symfony UX packages, Symfony Flex does not point your package.json at vendor/symfony/reprise/assets. The npm package is an ordinary registry dependency, so composer update leaves it untouched. This is deliberate: publishing on npm keeps the package free of the constraints that come with shipping JavaScript from a Composer vendor directory.

Upgrade both packages at the same time to the same version, so both halves of a feature land together. Renovate or Dependabot can group the two updates.

Rendering asset tags

This is where Reprise pays off: once entrypoints.json exists, RepriseBundle reads it and renders the <script> and <link> tags for an entry directly in Twig, the same experience WebpackEncoreBundle gives you with encore_entry_script_tags and encore_entry_link_tags.

Five Twig functions come with it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{# templates/base.html.twig #}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}Welcome!{% endblock %}</title>
        <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text><text y=%221.3em%22 x=%220.2em%22 font-size=%2276%22 fill=%22%23fff%22>sf</text></svg>">
        {% block stylesheets %}
            {{ reprise_entry_link_tags('app') }}
        {% endblock %}

        {% block javascripts %}
            {# reprise_entry_script_tags renders <script type="module"> (ESM output from both Vite and Rsbuild) #}
            {{ reprise_entry_script_tags('app') }}
        {% endblock %}
    </head>
    <body>
        {% block body %}{% endblock %}
    </body>
</html>

reprise_entry_js_files('app') and reprise_entry_css_files('app') are the same lookup, minus the HTML: they return the raw URL lists, for the rare case where you need the paths rather than the tags.

reprise_entry_exists('checkout') returns true when the named entry is present in entrypoints.json and false otherwise. Use it to guard a page-specific or optional entry so rendering its tags doesn't error in strict mode:

1
2
3
{% if reprise_entry_exists('checkout') %}
    {{ reprise_entry_script_tags('checkout') }}
{% endif %}

If you're migrating from Webpack Encore, it's a tag-for-tag swap (Reprise is Encore's heritage, so the template shape hasn't changed):

Webpack Encore Symfony Reprise Output
encore_entry_link_tags('app') reprise_entry_link_tags('app') <link rel="stylesheet"> tags
encore_entry_script_tags('app') reprise_entry_script_tags('app') <script type="module"> tags
encore_entry_css_files('app') reprise_entry_css_files('app') CSS URL list
encore_entry_js_files('app') reprise_entry_js_files('app') JS URL list
encore_entry_exists('app') reprise_entry_exists('app') true/false

reprise_entry_script_tags and reprise_entry_link_tags take a fourth attributes argument, merged over the global script_attributes/link_attributes (per-call wins, false drops the attribute). It mirrors Encore's fourth argument; since it follows the optional package name, pass it as a Twig named argument:

1
2
3
{# a fourth `attributes` argument, merged over the configured script_attributes/link_attributes #}
{{ reprise_entry_script_tags('app', attributes={ 'data-turbo-track': 'reload' }) }}
{{ reprise_entry_link_tags('app', attributes={ media: 'print' }) }}

A nonce passed to reprise_entry_script_tags this way, or set in the global script_attributes, also reaches the <link rel="modulepreload"> tags for that entry and their HTTP Link: preload header, since a nonce-based CSP would otherwise block the preload. The rest of attributes (data-turbo-track, defer, and so on) stays off those links.

Nothing to set up for the common case. The tags resolve against Symfony's default asset package, so a standard project needs nothing beyond installing the bundle (see Configuration below for the options). The snippet is the same whether Vite or Rsbuild produced entrypoints.json, and there's nothing to configure for dev either: in dev reprise_entry_script_tags injects the Vite HMR client automatically, while under Rsbuild the client is compiled into the bundle.

Customizing rendered tags

Before Reprise writes any <script> or <link> tag (entry files, CSS, modulepreload links, and the dev-server tags it injects itself, like the Vite HMR client and the React Fast Refresh preamble), it dispatches a RenderAssetTagEvent. A listener can read and mutate $event->attributes to add, change, or remove attributes on that tag.

As one example, stamping a Content-Security-Policy nonce on every tag:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace App\EventListener;

use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Reprise\Event\RenderAssetTagEvent;

#[AsEventListener]
final class CspNonceListener
{
    public function __construct(private NonceGenerator $nonceGenerator)
    {
    }

    public function __invoke(RenderAssetTagEvent $event): void
    {
        $event->attributes['nonce'] = $this->nonceGenerator->getNonce();
    }
}

After the RenderAssetTagEvent listeners run, the tag's final nonce, integrity and crossorigin attributes are all copied onto its HTTP Link: preload header: a nonce-based CSP blocks a preload without the nonce, and the browser discards a preloaded response whose integrity or CORS mode does not match the tag's. If your policy uses separate script and style nonces, a modulepreload link needs the script nonce because the browser fetches it as a script. $event->isModulepreload() identifies those tags; isScript() and isLink() both return false for them.

Features

The rest of what Reprise carries over from Encore is opt-in. Turn on each feature through the plugin options in your vite.config.ts or rsbuild.config.ts, and leave out the ones you don't need.

Symfony UX / Stimulus controllers

This is the Vite/Rsbuild counterpart of what @symfony/stimulus-bridge did for Webpack Encore: it turns your controllers.json into a Stimulus application, with the same enable step, same helper, same local-controllers convention.

Enable it by pointing the plugin at your controllers.json (this is what turns the feature on):

1
2
3
4
5
6
7
8
9
10
Symfony({
  stimulus: 'assets/controllers.json',
})
// or, to override the local controllers dir:
Symfony({
  stimulus: {
    controllersJson: 'assets/controllers.json',
    controllersDir: 'assets/controllers',
  },
})

Then start the app from your entry:

1
2
3
import { startStimulusApp } from '@symfony/reprise/stimulus'

const app = startStimulusApp()

Registering extra controllers. startStimulusApp() returns the Stimulus Application it started, so you can keep it and register controllers that are not declared in controllers.json and do not live in your controllers directory, the same way you would with Webpack Encore:

1
2
3
4
5
6
import { startStimulusApp } from '@symfony/reprise/stimulus'
import Clipboard from '@stimulus-components/clipboard'

const app = startStimulusApp()

app.register('clipboard', Clipboard)

Local controllers. Any assets/controllers/*_controller.{js,jsx,ts,tsx} is registered automatically. The filename becomes the identifier (hello_controller.js becomes hello, admin/user_controller.js becomes admin--user). To load a controller on demand, put a stimulusFetch: 'lazy' comment anywhere in the file; a block or a single-line comment both work, even on dummy controllers that export a plain value instead of a class.

1
2
3
4
import { Controller } from '@hotwired/stimulus'

/* stimulusFetch: 'lazy' */
export default class extends Controller {}

(// stimulusFetch: 'lazy' works too, and so does a preserved /*! stimulusFetch: 'lazy' */ comment: the form tsc and esbuild keep through minification.)

More controllers directories. To register controllers from other directories on top of the default assets/controllers one, list them in controllersDirs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// vite.config.ts
import { defineConfig } from 'vite'
import Symfony from '@symfony/reprise/vite'

export default defineConfig({
  // ...
  plugins: [
    Symfony({
      stimulus: {
        controllersJson: 'assets/controllers.json',
        controllersDirs: {
          admin: 'assets/admin/controllers',
        },
      },
    }),
  ],
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// rsbuild.config.ts
import { defineConfig } from '@rsbuild/core'
import Symfony from '@symfony/reprise/rsbuild'

export default defineConfig({
  // ...
  plugins: [
    Symfony({
      stimulus: {
        controllersJson: 'assets/controllers.json',
        controllersDirs: {
          admin: 'assets/admin/controllers',
        },
      },
    }),
  ],
})

Each key prefixes the identifiers of its directory's controllers: assets/admin/controllers/user_controller.js becomes admin--user, while the default directory keeps no prefix. To replace that default directory, use the empty key '' instead; controllersDirs cannot be combined with controllersDir. If controllers from two directories end up with the same identifier, the build fails and names both files.

In dev. While the Vite or Rsbuild dev server runs, Reprise regenerates the controllers module and reloads the page when a local controller is added or removed, when a controller's stimulusFetch: 'lazy' comment is added or removed, or when controllers.json itself changes (for example right after Symfony Flex updates it following a composer require symfony/ux-*), no dev-server restart needed. This is a full page reload, not hot replacement of the controller.

Third-party UX packages. Controllers declared in controllers.json are resolved from node_modules, so install them with your package manager, the same as you would with Webpack Encore. For example, with Stimulus and UX Leaflet Map:

1
$ npm install @hotwired/stimulus @symfony/ux-leaflet-map

Some packages need a bit of bundler-specific setup on top, the same way they did under Webpack Encore. UX Leaflet Map, for instance, ships a CSS file meant for Webpack's loader and needs an alias to the plain CSS build:

1
2
3
4
5
6
7
8
9
// vite.config.ts
export default defineConfig({
  // ...
  resolve: {
    alias: {
      'leaflet/dist/leaflet.min.css': 'leaflet/dist/leaflet.css',
    },
  },
})

Check each package's own docs for this kind of tweak.

Style entries

An entry can point straight at a stylesheet, the way Encore's addStyleEntry() did. It compiles to CSS and nothing else: reprise_entry_link_tags('theme') renders the <link>, while reprise_entry_script_tags('theme') has nothing to render (in dev it still emits the shared HMR client, once per page).

1
2
3
4
5
6
7
8
9
10
// vite.config.ts
export default defineConfig({
  input: {
    app: './assets/app.js',
    theme: './assets/styles/theme.scss',
  },
  plugins: [
    Symfony(),
  ],
})
1
2
3
4
5
6
7
8
9
10
11
12
13
// rsbuild.config.ts
export default defineConfig({
  source: {
    entry: {
      app: './assets/app.js',
      theme: './assets/styles/theme.scss',
    },
  },
  plugins: [
    pluginSass(),
    Symfony(),
  ],
})

Reprise treats an entry as a style entry when its source file carries a stylesheet extension: .css, .scss, .sass, .less, .styl, .stylus, .postcss or .pcss. Both bundlers still produce a JavaScript file for it internally, but neither keeps it: Vite prunes it before writing the build, and Reprise deletes Rspack's from the compilation. Either way, it stays out of entrypoints.json and manifest.json: no empty <script> tag ever reaches the page.

File copy

Some assets aren't imported from JavaScript or CSS at all: they're referenced by a stable path straight from your templates, like {{ asset('build/images/logo.svg') }}. Point copy at the directories that hold them and Reprise copies each file into the build and records it in manifest.json. Once Symfony is pointed at that manifest (below), the asset() helper resolves the logical path to the hashed URL:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// vite.config.ts
import { defineConfig } from 'vite'
import Symfony from '@symfony/reprise/vite'

export default defineConfig({
  // ...
  plugins: [
    Symfony({
      copy: [
        {
          from: 'assets/images',
          to: 'images',
        },
      ],
    }),
  ],
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// rsbuild.config.ts
import { defineConfig } from '@rsbuild/core'
import Symfony from '@symfony/reprise/rsbuild'

export default defineConfig({
  // ...
  plugins: [
    Symfony({
      copy: [
        {
          from: 'assets/images',
          to: 'images',
        },
      ],
    }),
  ],
})

from and to are both required: from is the source directory (relative to your project root), to is the destination prefix used for the manifest key. Pass an empty to to copy the files at the root of outputPath, for things like favicon.ico or site.webmanifest that have to live at a fixed URL. Restrict which files are copied with pattern, a regular expression tested against each file's path relative to from (by default every file is copied). includeSubdirectories defaults to true; set it to false to turn off recursion.

Some copied files have to keep a stable path on disk: templates referencing them through a hardcoded asset('/build/images/logo.svg'), code reading them from a predictable location, CDN rules, and so on. Set hash: false on the entry and the file keeps its logical path. The content hash then moves to the manifest.json value as a query string, so cache-busting through asset() still works:

1
2
3
4
5
6
7
copy: [
  {
    from: 'assets/images',
    to: 'images',
    hash: false,
  },
],
1
{ "build/images/logo.svg": "/build/images/logo.svg?87dcc351" }

Be aware that proxies or CDNs configured to ignore query strings will not pick up new versions of these files. That is why hashed filenames remain the default.

How copied files are handled depends on the mode:

  • Build: each file gets a content hash in its filename for cache busting, unless the entry sets hash: false.
  • Dev: files are copied verbatim, no hash.

Either way they land in public/build and are served by the Symfony web server, not the Vite/Rsbuild dev server, so they're available whether or not the dev server is running.

For asset() to return the hashed URL, point Symfony's asset component at the generated manifest.json with framework.assets.json_manifest_path:

1
2
3
4
# config/packages/framework.yaml
framework:
    assets:
        json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'

This is Symfony's native manifest support, the same setting Webpack Encore relies on, so it applies to every logical asset reference, not just copied files. The entry references that RepriseBundle renders already carry their hash and aren't manifest keys, so they pass through untouched.

By default the lookup is lenient: a reference missing from the manifest is returned unchanged. Set framework.assets.strict_mode: true to fail loudly on an unknown reference instead. Under strict mode, the entry references RepriseBundle renders would be rejected too, so route them through a package that skips the manifest: set reprise.asset_package to a package with version: false (see Configuration) and keep json_manifest_path on the default package for your other assets.

Using a CDN

To serve your built assets from a CDN, set publicPath to the absolute CDN URL, for the production build only. In dev, the dev server serves assets directly, so keep the local /build/ path there. Both bundlers expose the mode through the function form of their config, so switch on command === 'build':

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// vite.config.ts  (command is 'serve' or 'build')
import { defineConfig } from 'vite'
import Symfony from '@symfony/reprise/vite'

export default defineConfig(({ command }) => ({
  // ...
  plugins: [
    Symfony({
      publicPath:
        command === 'build'
          ? 'https://my-cool-app.com.global.prod.fastly.net/build/'
          : '/build/',
      manifestKeyPrefix: 'build/',
    }),
  ],
}))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// rsbuild.config.ts  (command is 'dev' or 'build')
import { defineConfig } from '@rsbuild/core'
import Symfony from '@symfony/reprise/rsbuild'

export default defineConfig(({ command }) => ({
  // ...
  plugins: [
    Symfony({
      publicPath:
        command === 'build'
          ? 'https://my-cool-app.com.global.prod.fastly.net/build/'
          : '/build/',
      manifestKeyPrefix: 'build/',
    }),
  ],
}))

With an absolute publicPath, manifestKeyPrefix is required: Reprise has no way to guess the right prefix for the manifest.json keys, and throws a clear error if it's missing. Keys stay logical, values point at the CDN:

1
2
3
{
  "build/app.js": "https://my-cool-app.com.global.prod.fastly.net/build/app-1a2b3c.js"
}

entrypoints.json is rewritten the same way, so the <script> and <link> tags render with CDN URLs. You still have to upload the built files to the CDN yourself, or set up origin pull. For a CDN subdirectory, include it in the URL (https://my-cool-app.com.global.prod.fastly.net/awesome-website/build/).

Separating metadata from public assets

By default, Reprise writes entrypoints.json and manifest.json into outputPath. If you want to keep these files separate from your compiled assets (for example, to avoid uploading them to public object storage), set metadataPath:

1
2
3
4
5
6
7
8
9
10
11
12
// vite.config.ts
import { defineConfig } from 'vite'
import Symfony from '@symfony/reprise/vite'

export default defineConfig({
  plugins: [
    Symfony({
      outputPath: 'public/build',
      metadataPath: 'var/reprise',
    }),
  ],
})
1
2
3
4
5
6
7
8
9
10
11
12
// rsbuild.config.ts
import { defineConfig } from '@rsbuild/core'
import Symfony from '@symfony/reprise/rsbuild'

export default defineConfig({
  plugins: [
    Symfony({
      outputPath: 'public/build',
      metadataPath: 'var/reprise',
    }),
  ],
})

Then point Symfony at that directory:

1
2
3
# config/packages/reprise.yaml
reprise:
    output_path: '%kernel.project_dir%/var/reprise'

And, if you rely on manifest.json for asset() calls:

1
2
3
4
# config/packages/framework.yaml
framework:
    assets:
        json_manifest_path: '%kernel.project_dir%/var/reprise/manifest.json'

Warning

If two builds share the same metadataPath, the second one silently overwrites the first, since each write replaces entrypoints.json and manifest.json whole rather than merging them. This used to be impossible because every build had its own outputPath, so give each build its own subdirectory instead, for example var/reprise/app and var/reprise/widget. See Multiple builds for the full setup.

Reaching the dev server through another address

In dev, entrypoints.json points the rendered tags at the dev server's own address, for example http://localhost:5173. When the browser reaches the dev server through another address instead, such as a reverse proxy, a Docker port mapping, or a local domain like https://assets.myapp.test, set devServerOrigin to that public origin.

The browser then loads everything from that origin in dev: the entry files, the HMR client and its WebSocket, and the async chunks. Whatever sits in front of the dev server has to forward WebSocket connections too, or hot reloading stops working.

1
2
3
4
5
6
7
8
9
10
11
// vite.config.ts
import { defineConfig } from 'vite'
import Symfony from '@symfony/reprise/vite'

export default defineConfig({
  plugins: [
    Symfony({
      devServerOrigin: 'https://assets.myapp.test',
    }),
  ],
})
1
2
3
4
5
6
7
8
9
10
11
// rsbuild.config.ts
import { defineConfig } from '@rsbuild/core'
import Symfony from '@symfony/reprise/rsbuild'

export default defineConfig({
  plugins: [
    Symfony({
      devServerOrigin: 'https://assets.myapp.test',
    }),
  ],
})

Subresource Integrity

When enabled, Reprise adds an integrity map to entrypoints.json (asset URL -> SRI hash). RepriseBundle reads that map and renders integrity="..." on the generated <script> and <link> tags, so the browser refuses any asset whose bytes were tampered with.

The integrity option takes an object { enabled, algorithms? }. It only makes sense for the production build: the dev server serves changing in-memory assets, so no hashes are emitted in dev. As with the CDN example, toggle it with command === 'build':

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// vite.config.ts  (command is 'serve' or 'build')
import { defineConfig } from 'vite'
import Symfony from '@symfony/reprise/vite'

export default defineConfig(({ command }) => ({
  // ...
  plugins: [
    Symfony({
      integrity: {
        enabled: command === 'build',
        algorithms: ['sha384'],
      },
    }),
  ],
}))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// rsbuild.config.ts  (command is 'dev' or 'build')
import { defineConfig } from '@rsbuild/core'
import Symfony from '@symfony/reprise/rsbuild'

export default defineConfig(({ command }) => ({
  // ...
  plugins: [
    Symfony({
      integrity: {
        enabled: command === 'build',
        algorithms: ['sha384'],
      },
    }),
  ],
}))

algorithms is optional and defaults to ['sha384']. Accepted values are 'sha256', 'sha384' and 'sha512'. Passing several (e.g. ['sha256', 'sha512']) writes multiple space-separated hashes per file, which the browser treats as "any one of these must match".

The resulting entrypoints.json gets an extra integrity section:

1
2
3
4
5
6
{
  "integrity": {
    "/build/app-1a2b3c.js": "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K...",
    "/build/app-4d5e6f.css": "sha384-9ehJ4G8v3aQ2p1o0..."
  }
}

Hashes cover every referenced file in each entry (js, css, and preloaded/dynamic chunks), and since they're computed from the files actually written to disk, they stay correct through minification and hashing.

Multiple builds

Several areas of one app (a public part, an admin panel) are usually just separate entry points in one config: the Multiple entries case, addressed by name without a build argument. Reach for multiple builds only when a part needs its own bundler config and output directory, like an embeddable widget built apart from the main app.

Give the widget its own config, pointing the plugin at a separate output directory -> with Vite:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// vite.config.widget.ts  -- run with `vite build --config vite.config.widget.ts`
import { defineConfig } from 'vite'
import Symfony from '@symfony/reprise/vite'

export default defineConfig({
  input: {
    widget: './assets/widget.js',
  },
  plugins: [
    Symfony({
      outputPath: 'public/widget-build',
      publicPath: '/widget-build/',
    }),
  ],
})

or with Rsbuild:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// rsbuild.config.widget.ts  -- run with `rsbuild build --config rsbuild.config.widget.ts`
import { defineConfig } from '@rsbuild/core'
import Symfony from '@symfony/reprise/rsbuild'

export default defineConfig({
  source: {
    entry: {
      widget: './assets/widget.js',
    },
  },
  plugins: [
    Symfony({
      outputPath: 'public/widget-build',
      publicPath: '/widget-build/',
    }),
  ],
})

These two blocks are alternatives: pick the one that matches your bundler, you don't use both in one project.

Name that directory in reprise.yaml:

1
2
3
4
5
6
7
# config/packages/reprise.yaml
reprise:
    # the main app (your existing config), addressed without a build name
    output_path: '%kernel.project_dir%/public/build'
    builds:
        # each extra build: name -> the directory its entrypoints.json lives in
        widget: '%kernel.project_dir%/public/widget-build'

In Twig, pass the build name to load from it; omit it for the default build:

1
2
3
4
5
6
7
{# the main app (default build) #}
{{ reprise_entry_script_tags('app') }}
{{ reprise_entry_link_tags('app') }}

{# the widget build, selected with the build argument #}
{{ reprise_entry_script_tags('widget', build='widget') }}
{{ reprise_entry_link_tags('widget', build='widget') }}

The build argument works on every reprise_entry_* function. Each build has its own dev server, so the app's and the widget's can run at once on different ports, each injecting its HMR client once. Set output_path: false for a named-builds-only setup (at least one build is required).

Configuration

Reprise exposes a few optional settings under its own configuration, all shown here at their default value:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# config/packages/reprise.yaml
reprise:
    # Directory the @symfony/reprise plugin writes entrypoints.json and manifest.json into.
    # Set to false when using only named builds (requires at least one entry under builds).
    output_path: '%kernel.project_dir%/public/build'

    # Additional named builds: a map of build name -> output directory (see `Multiple builds`_).
    builds: {}

    # Throw when entrypoints.json or a requested entry is missing, instead of rendering nothing.
    strict_mode: true

    # Cache the parsed entrypoints.json in a compiled PHP file, warmed at cache:warmup (needs symfony/cache).
    cache: false

    # A framework.assets package name used to resolve entry URLs. null uses the default package.
    asset_package: null

    # crossorigin attribute set alongside SRI integrity: false, 'anonymous' or 'use-credentials'.
    crossorigin: false

    # Register rendered assets as WebLink HTTP/2 Link: preload headers (needs symfony/web-link).
    preload: true

    # Default attributes added to every rendered <script> / <link> tag.
    script_attributes: []
    link_attributes: []
  • output_path: the filesystem directory holding entrypoints.json and manifest.json. Must match wherever the plugin actually writes them: its outputPath by default, or its metadataPath when that option is set. Accepts false to disable the default build entirely, which then requires at least one entry under builds.
  • builds: a map of build name -> output directory for additional bundles. Each named build is addressed by passing build='<name>' to the tag and file functions. See Multiple builds.
  • strict_mode: when true (the default), throws a clear exception on a missing file or an unknown entry; when false, renders nothing instead.
  • cache: when true, parse entrypoints.json once at cache:warmup and read it from a compiled PHP file at runtime instead of decoding the JSON on every request. Enable it in production and run cache:clear after rebuilding your assets; it needs symfony/cache (composer require symfony/cache).
  • asset_package: resolve entry URLs through a specific framework.assets package instead of the default one. You only need this if your default package applies a version strategy, which would re-hash files Reprise already content-hashed and break the URLs. Point it at a package with version: false (see below).
  • crossorigin: false, 'anonymous' or 'use-credentials' (any other value is a configuration error), applied together with SRI integrity (see Subresource Integrity).
  • preload: emit WebLink HTTP/2 Link: preload headers when symfony/web-link is installed; false to disable.
  • script_attributes / link_attributes: maps of default attributes added to every generated tag, e.g. defer: true or data-turbo-track: reload.

If you set asset_package, define that package with version: false:

1
2
3
4
5
6
7
8
reprise:
    asset_package: reprise

framework:
    assets:
        packages:
            reprise:
                version: false

Migrating from Webpack Encore

Reprise is Webpack Encore's successor for Vite and Rsbuild, so the move splits in two. The Symfony side (the bundle and your Twig templates) barely changes. Your webpack.config.js mostly goes away: Vite and Rsbuild do natively what most Encore.* calls set up, so you delete those calls rather than translate them. What is left maps to a Reprise plugin option or a bundler plugin.

The Symfony side

Reprise ships its own RepriseBundle and does not use WebpackEncoreBundle, so swap the Composer package:

1
2
$ composer remove symfony/webpack-encore-bundle
$ composer require symfony/reprise

In your templates the Twig functions keep the same shape, with the encore_ prefix becoming reprise_ (the full list is under Rendering asset tags):

1
2
3
4
5
6
7
{# before #}
{{ encore_entry_link_tags('app') }}
{{ encore_entry_script_tags('app') }}

{# after #}
{{ reprise_entry_link_tags('app') }}
{{ reprise_entry_script_tags('app') }}

The bundle config carries over almost key-for-key: webpack_encore.output_path becomes reprise.output_path, and crossorigin, preload, cache, strict_mode, script_attributes and link_attributes all exist under reprise with the same meaning. Encore's builds option maps to Multiple builds.

Your build config

Most of webpack.config.js has no equivalent, because the bundler already does the work. The Symfony glue Encore layered on top of Webpack stays, as a Reprise plugin option:

Webpack Encore Reprise
setOutputPath() / setPublicPath() plugin outputPath / publicPath (the defaults fit a standard project)
setManifestKeyPrefix() plugin manifestKeyPrefix (see Using a CDN)
addEntry() / addEntries() Vite input (Vite 8.1 and older: build.rollupOptions.input); Rsbuild source.entry
enableVersioning() nothing to do, content hashing is on by default
enableIntegrityHashes() plugin integrity: { enabled: true } (see Subresource Integrity)
copyFiles() plugin copy: [ ... ] (see File copy)
enableStimulusBridge() plugin stimulus: 'assets/controllers.json' (see Symfony UX / Stimulus controllers)
configureDevServerOptions() nothing to do: run vite or rsbuild dev and Reprise points Twig at it

Everything Vite and Rsbuild handle themselves, you drop:

Webpack Encore Now handled by the bundler
enableSassLoader() / enableLessLoader() / enableStylusLoader() install the preprocessor and import the file (Vite out of the box, Rsbuild via @rsbuild/plugin-sass and friends)
enablePostCssLoader() add a postcss.config.js, picked up automatically
enableTypeScriptLoader() / configureBabel() / configureBabelPresetEnv() native transpilation (Vite via esbuild, Rsbuild via SWC); set targets with browserslist or build.target
enableForkedTypeScriptTypesChecking() / enableBabelTypeScriptPreset() run tsc --noEmit (or vue-tsc) as its own script, outside the build
splitEntryChunks() / configureSplitChunks() / addCacheGroup() native code splitting
enableSingleRuntimeChunk() / disableSingleRuntimeChunk() native runtime chunk management
enableSourceMaps() native (Vite build.sourcemap)
configureImageRule() / configureFontRule() / configureFilenames() native asset handling and output naming
addStyleEntry() add the stylesheet as an entry input (see Style entries), or import it from a JS entry
configureDefinePlugin() Vite define, Rsbuild source.define
disableCssExtraction() / configureCssLoader() / configureStyleLoader() native CSS handling (extraction, minification)
addAliases() resolve.alias
addExternals() Vite build.rollupOptions.external, Rsbuild output.externals
enableBuildCache() / configureWatchOptions() native build caching and watch
cleanupOutputBeforeBuild() native (Vite build.emptyOutDir, Rsbuild cleans by default)

Framework presets become the bundler's own plugin:

Webpack Encore Vite Rsbuild
enableReactPreset() @vitejs/plugin-react @rsbuild/plugin-react
enableVueLoader() @vitejs/plugin-vue @rsbuild/plugin-vue
enablePreactPreset() @preact/preset-vite @rsbuild/plugin-preact
enableSvelte() @sveltejs/vite-plugin-svelte @rsbuild/plugin-svelte

A few Encore features have no direct replacement:

  • autoProvideVariables() / autoProvidejQuery(): prefer importing what you use. To inject a global anyway, use @rollup/plugin-inject under Vite or rspack.ProvidePlugin (through Rsbuild's tools.rspack).
  • enableBuildNotifications() and the ESLint integration are gone: run your linter as its own script, outside the build.
  • Encore.isProduction() / isDev() / isDevServer() / when(): branch on the bundler mode instead, e.g. defineConfig(({ command }) => ...) where command is 'build' or the dev command.
  • addLoader() / addRule() / addPlugin() / configureLoaderRule(): these were escape hatches into the raw Webpack config; edit the bundler config directly (Vite plugins, Rsbuild tools.rspack).
  • enableHandlebarsLoader(): add the bundler's own Handlebars plugin if you still need it.
  • configureRuntimeEnvironment() / clearRuntimeEnvironment() / isRuntimeEnvironmentConfigured() / reset(): Encore's own bootstrap and reset plumbing, no counterpart here.
  • The remaining configure*Plugin() calls (configureManifestPlugin(), configureMiniCssExtractPlugin(), configureCssMinimizerPlugin(), configureJsMinimizerPlugin(), configureFriendlyErrorsPlugin()): tuned Webpack internals that Reprise and the bundlers now own; nothing to port.

Migrating from pentatrion/vite-bundle

pentatrion/vite-bundle and its companion vite-plugin-symfony brought Vite to Symfony long before Reprise existed, and most of their shape carries over: Twig functions that render an entry's tags, a plugin that writes the file the bundle reads, Stimulus controllers registered from controllers.json. Moving to Reprise means swapping both packages, renaming the Twig functions and deleting the setup Reprise now does on its own. A few features have no counterpart. They are listed in No direct replacement, so check them before you start.

Before you start

Reprise needs PHP 8.4 or later, Symfony 7.4 or 8, Vite 7 or 8, and Node.js 22.18+, 24.11+ or 26+. The pentatrion packages run down to PHP 8.0, Symfony 4.4 and Vite 3, so upgrade those first if needed.

Reprise only renders ES modules. If you build with @vitejs/plugin-legacy, there is no equivalent.

The examples below keep Vite. Once you are on Reprise, moving to Rsbuild only means swapping the bundler config (see Installation).

Swapping the bundle

Commit your work first. When Symfony Flex removes pentatrion/vite-bundle, it deletes the files its recipe created, even if you edited them since: package.json, vite.config.js, assets/app.js, assets/app.css and config/routes/pentatrion_vite.yaml. It also removes the vite_entry_* tags from templates/base.html.twig.

Then remove what still refers to the bundle, or the cache:clear that Composer runs after the removal fails: the pentatrion_vite configuration, usually config/packages/pentatrion_vite.yaml (port its settings with the table below; it stays in your Git history), and the Pentatrion\ViteBundle\Asset\ViteAssetVersionStrategy version strategy under framework.assets, if you used it. Restore the files you keep before installing Reprise, whose recipe never overwrites an existing file:

1
2
3
$ composer remove pentatrion/vite-bundle
$ git restore package.json vite.config.js assets/
$ composer require symfony/reprise

Leave config/routes/pentatrion_vite.yaml deleted: Reprise has no dev-server proxy route, because the browser loads assets from the dev server directly.

The Reprise recipe adds reprise_entry_link_tags('app') and reprise_entry_script_tags('app') to templates/base.html.twig. In your other templates, rename the functions:

pentatrion/vite-bundle Symfony Reprise
vite_entry_link_tags('app') reprise_entry_link_tags('app')
vite_entry_script_tags('app') reprise_entry_script_tags('app')
vite_entry_script_tags('app', { attr: { defer: true } }) reprise_entry_script_tags('app', attributes={ defer: true })
vite_entry_script_tags('app', {}, 'admin') reprise_entry_script_tags('app', build='admin')
vite_entry_script_tags('app', { dependency: 'react' }) reprise_entry_script_tags('app')
vite_mode() none, see No direct replacement

dependency: 'react' is no longer needed: when @vitejs/plugin-react is in your Vite plugins, Reprise renders the React Fast Refresh preamble in dev on its own.

The bundle configuration moves from pentatrion_vite to reprise (see Configuration):

pentatrion_vite reprise
public_directory and build_directory output_path, a single absolute path (default %kernel.project_dir%/public/build)
configs and default_config builds, selected with the build Twig argument (see Multiple builds)
throw_on_missing_entry strict_mode, now true by default
throw_on_missing_asset framework.assets.strict_mode, lenient by default (see Behavior changes)
cache cache
preload: link-header preload: true
crossorigin crossorigin, applied only together with SRI
script_attributes and link_attributes script_attributes and link_attributes
absolute_url none: framework.assets.base_urls gives a fixed absolute host, not the current request's
proxy_origin the plugin's devServerOrigin (see Reaching the dev server through another address)
preload_attributes none, see No direct replacement

For asset(), point Symfony at Reprise's manifest.json with framework.assets.json_manifest_path (see File copy). Manifest keys start with the public path: an image imported from your JavaScript or CSS as assets/images/avatar.jpg is now asset('build/assets/images/avatar.jpg'). However, imported files only get a manifest key in the production build, since in dev they live in the dev server's memory. For files your templates reference directly, list their directory under the plugin's copy option instead: copied files are on disk and in the manifest in both modes.

Swapping the Vite plugin

Swap the npm package:

1
2
$ npm uninstall vite-plugin-symfony
$ npm install @symfony/reprise --save-dev

Then swap the plugin in vite.config.js. Your entries stay as they are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// vite.config.js
import { defineConfig } from 'vite'
import Symfony from '@symfony/reprise/vite'

export default defineConfig({
  build: {
    rollupOptions: {
      input: {
        app: './assets/app.js',
      },
    },
  },
  plugins: [
    Symfony(),
  ],
})

Like vite-plugin-symfony, Reprise builds into public/build and serves it under /build/ by default, so a standard project needs no option. Reprise sets Vite's base and build.outDir itself. If you changed them, move the values to the plugin's publicPath and outputPath options.

vite-plugin-symfony @symfony/reprise/vite
stimulus: true or stimulus: { controllersFilePath } stimulus: 'assets/controllers.json' (see Moving Stimulus controllers)
sriAlgorithm: 'sha384' integrity: { enabled: true } (see Subresource Integrity)
originOverride devServerOrigin
viteDevServerHostname nothing to port, or devServerOrigin
exposedEnvVars Vite's define or envPrefix
refresh none, see No direct replacement
servePublic, debug nothing to port
enforcePluginOrderingPosition nothing to port
enforceServerOriginAfterListening nothing to port, Reprise always does it

Moving Stimulus controllers

Point the plugin at your controllers.json. The path is required, stimulus: true is not accepted:

1
2
3
Symfony({
  stimulus: 'assets/controllers.json',
})

Reprise registers your local controllers itself, so the bootstrap code shrinks to one call:

1
2
3
4
5
6
7
8
9
10
// before
import { startStimulusApp, registerControllers } from 'vite-plugin-symfony/stimulus/helpers'

const app = startStimulusApp()
registerControllers(app, import.meta.glob('./controllers/*_controller.js', { query: '?stimulus', eager: true }))

// after
import { startStimulusApp } from '@symfony/reprise/stimulus'

const app = startStimulusApp()

Then, in your controllers:

  • Replace import.meta.stimulusFetch = 'lazy' with a /* stimulusFetch: 'lazy' */ comment (see Symfony UX / Stimulus controllers), and drop the vite-plugin-symfony/stimulus/env type reference.
  • Register controllers you imported with ?stimulus through the returned application instead: app.register('clipboard', Clipboard).
  • Identifiers still come from the filename, relative to the controllers directory: hello_controller.js is hello, admin/user_controller.js is admin--user.

For UX React and UX Vue, import registerReactControllerComponents and registerVueControllerComponents from @symfony/ux-react and @symfony/ux-vue instead of vite-plugin-symfony/stimulus/helpers/react and vite-plugin-symfony/stimulus/helpers/vue:

1
2
3
4
5
6
import { startStimulusApp } from '@symfony/reprise/stimulus'
import { registerReactControllerComponents } from '@symfony/ux-react'

registerReactControllerComponents(import.meta.glob('./react/controllers/**/*.{jsx,tsx}', { eager: true }))

startStimulusApp()

In controllers.json, a controller without an enabled key now counts as enabled, and the module override is not supported. Third-party controllers resolve from node_modules, including @symfony/ux-react and @symfony/ux-svelte, which vite-plugin-symfony used to provide itself.

Behavior changes

Some defaults and behaviors change without any error to tell you:

  • Missing entries throw. strict_mode defaults to true, while throw_on_missing_entry defaulted to false. Set strict_mode: false to keep rendering nothing, or guard optional entries with reprise_entry_exists().
  • crossorigin follows SRI. It is only added to tags that carry an integrity attribute, and true is not a valid value anymore. pentatrion added it to every tag by default; use script_attributes and link_attributes to keep that.
  • Preload links come with the scripts. reprise_entry_script_tags renders the <link rel="modulepreload"> tags, not reprise_entry_link_tags, and always renders them: preload: false only turns off the HTTP Link: header.
  • asset() keys change, and lookups turn lenient. Keys start with the public path (see Swapping the bundle). pentatrion threw on an unknown asset() path by default, while Symfony's manifest lookup returns it unchanged. Setting framework.assets.strict_mode: true brings the error back, but also rejects the entry tags unless reprise.asset_package points at a package with version: false (see File copy).
  • RenderAssetTagEvent moved to Symfony\Reprise\Event\RenderAssetTagEvent, with a smaller API: listeners read and write $event->attributes and check isScript(), isLink() or isModulepreload(). There is no getTag(), isBuild() or render flag (see Customizing rendered tags).
  • Stimulus reloads the page in dev when a controller changes, instead of hot-replacing it.

No direct replacement

  • vite_mode(): no Twig function tells dev from build. Branch on app.environment for dev-only markup.
  • refresh (reloading the page when a Twig template changes): add a Vite plugin such as vite-plugin-full-reload watching templates/**/*.twig.
  • @vitejs/plugin-legacy: Reprise renders ES modules only, with no nomodule or polyfill tags.
  • Hot replacement of Stimulus controllers (the hmr option): a change reloads the page.
  • identifierResolutionMethod, import.meta.stimulusIdentifier and import.meta.stimulusEnabled: the identifier always comes from the filename. Rename the file to change it, or move it out of the controllers directory to disable it.
  • vite-plugin-symfony/stimulus/helpers/svelte and svelte4: Reprise has no Svelte helper of its own.
  • preloadDynamicImports: dynamic imports are not preloaded.
  • preload: none and preload_attributes: modulepreload links are always rendered, and only receive the nonce. Set other attributes from a RenderAssetTagEvent listener, using isModulepreload().
  • Per-config script_attributes and link_attributes: they are global. Pass attributes per call, or use a listener.
  • The profiler panel.

Backward Compatibility promise

This bundle aims at following the same Backward Compatibility promise as the Symfony framework: https://symfony.com/doc/current/contributing/code/bc.html

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version