Skip to content

Commit 1c03d7f

Browse files
committed
documentation #58 [Docs] Add a migration guide from Webpack Encore (Kocal)
This PR was merged into the main branch. Discussion ---------- [Docs] Add a migration guide from Webpack Encore | Q | A | -------------- | --- | Bug fix? | no | New feature? | no <!-- please update CHANGELOG.md file --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and CHANGELOG.md files --> | Documentation? | yes <!-- required for new features, or documentation updates --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Commits ------- 8f71314 [Docs] Add a migration guide from Webpack Encore
2 parents 49cc5de + 8f71314 commit 1c03d7f

1 file changed

Lines changed: 122 additions & 0 deletions

File tree

doc/index.rst

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ or even change drastically.
77
Webpack Encore gave Symfony first-class asset integration for Webpack. Symfony Reprise brings the same to `Vite`_
88
and `Rsbuild`_.
99

10+
.. tip::
11+
12+
Still using Webpack Encore? See `Migrating from Webpack Encore`_ below: it maps every ``Encore.*`` call to its
13+
Vite/Rsbuild or Reprise equivalent.
14+
1015
Vite and Rsbuild already handle **Sass/Less/PostCSS**, **TypeScript**, **JSX/Vue/Svelte**, **code splitting**,
1116
**content hashing**, **source maps**, **minification** and **HMR** on their own, so Symfony Reprise does not
1217
reimplement any of that. It covers only the Symfony-side glue the bundlers leave out:
@@ -608,6 +613,123 @@ If you set ``asset_package``, define that package with ``version: false``:
608613
reprise:
609614
version: false
610615
616+
Migrating from Webpack Encore
617+
-----------------------------
618+
619+
Reprise is Webpack Encore's successor for Vite and Rsbuild, so the move splits in two. The Symfony side (the bundle
620+
and your Twig templates) barely changes. Your ``webpack.config.js`` mostly goes away: Vite and Rsbuild do natively
621+
what most ``Encore.*`` calls set up, so you delete those calls rather than translate them. What is left maps to a
622+
Reprise plugin option or a bundler plugin.
623+
624+
The Symfony side
625+
~~~~~~~~~~~~~~~~
626+
627+
Reprise ships its own ``RepriseBundle`` and does not use `WebpackEncoreBundle`_, so swap the Composer package:
628+
629+
.. code-block:: terminal
630+
631+
$ composer remove symfony/webpack-encore-bundle
632+
$ composer require symfony/reprise
633+
634+
In your templates the Twig functions keep the same shape, with the ``encore_`` prefix becoming ``reprise_`` (the full
635+
list is under `Rendering asset tags`_):
636+
637+
.. code-block:: twig
638+
639+
{# before #}
640+
{{ encore_entry_link_tags('app') }}
641+
{{ encore_entry_script_tags('app') }}
642+
643+
{# after #}
644+
{{ reprise_entry_link_tags('app') }}
645+
{{ reprise_entry_script_tags('app') }}
646+
647+
The bundle config carries over almost key-for-key: ``webpack_encore.output_path`` becomes ``reprise.output_path``,
648+
and ``crossorigin``, ``preload``, ``cache``, ``strict_mode``, ``script_attributes`` and ``link_attributes`` all exist
649+
under ``reprise`` with the same meaning. Encore's ``builds`` option maps to `Multiple builds`_.
650+
651+
Your build config
652+
~~~~~~~~~~~~~~~~~
653+
654+
Most of ``webpack.config.js`` has no equivalent, because the bundler already does the work. The Symfony glue Encore
655+
layered on top of Webpack stays, as a Reprise plugin option:
656+
657+
.. list-table::
658+
:header-rows: 1
659+
660+
* - Webpack Encore
661+
- Reprise
662+
* - ``setOutputPath()`` / ``setPublicPath()``
663+
- plugin ``outputPath`` / ``publicPath`` (the defaults fit a standard project)
664+
* - ``addEntry()`` / ``addEntries()``
665+
- the bundler's own entry input: Vite ``build.rollupOptions.input``, Rsbuild ``source.entry``
666+
* - ``enableVersioning()``
667+
- nothing to do, content hashing is on by default
668+
* - ``enableIntegrityHashes()``
669+
- plugin ``integrity: { enabled: true }`` (see `Subresource Integrity`_)
670+
* - ``copyFiles()``
671+
- plugin ``copy: [ ... ]`` (see `File copy`_)
672+
* - ``enableStimulusBridge()``
673+
- plugin ``stimulus: 'assets/controllers.json'`` (see `Symfony UX / Stimulus controllers`_)
674+
* - ``configureDevServerOptions()``
675+
- nothing to do: run ``vite`` or ``rsbuild dev`` and Reprise points Twig at it
676+
677+
Everything Vite and Rsbuild handle themselves, you drop:
678+
679+
.. list-table::
680+
:header-rows: 1
681+
682+
* - Webpack Encore
683+
- Now handled by the bundler
684+
* - ``enableSassLoader()`` / ``enableLessLoader()`` / ``enableStylusLoader()``
685+
- install the preprocessor and import the file (Vite out of the box, Rsbuild via ``@rsbuild/plugin-sass`` and friends)
686+
* - ``enablePostCssLoader()``
687+
- add a ``postcss.config.js``, picked up automatically
688+
* - ``enableTypeScriptLoader()`` / ``configureBabel()`` / ``configureBabelPresetEnv()``
689+
- native transpilation (Vite via esbuild, Rsbuild via SWC); set targets with ``browserslist`` or ``build.target``
690+
* - ``splitEntryChunks()`` / ``configureSplitChunks()``
691+
- native code splitting
692+
* - ``enableSourceMaps()``
693+
- native (Vite ``build.sourcemap``)
694+
* - ``configureImageRule()`` / ``configureFontRule()`` / ``configureFilenames()``
695+
- native asset handling and output naming
696+
* - ``addAliases()``
697+
- ``resolve.alias``
698+
* - ``addExternals()``
699+
- Vite ``build.rollupOptions.external``, Rsbuild ``output.externals``
700+
* - ``cleanupOutputBeforeBuild()``
701+
- native (Vite ``build.emptyOutDir``, Rsbuild cleans by default)
702+
703+
Framework presets become the bundler's own plugin:
704+
705+
.. list-table::
706+
:header-rows: 1
707+
708+
* - Webpack Encore
709+
- Vite
710+
- Rsbuild
711+
* - ``enableReactPreset()``
712+
- ``@vitejs/plugin-react``
713+
- ``@rsbuild/plugin-react``
714+
* - ``enableVueLoader()``
715+
- ``@vitejs/plugin-vue``
716+
- ``@rsbuild/plugin-vue``
717+
* - ``enablePreactPreset()``
718+
- ``@preact/preset-vite``
719+
- ``@rsbuild/plugin-preact``
720+
* - ``enableSvelte()``
721+
- ``@sveltejs/vite-plugin-svelte``
722+
- ``@rsbuild/plugin-svelte``
723+
724+
A few Encore features have no direct replacement:
725+
726+
- ``autoProvideVariables()`` / ``autoProvidejQuery()``: prefer importing what you use. To inject a global anyway, use
727+
``@rollup/plugin-inject`` under Vite or ``rspack.ProvidePlugin`` (through Rsbuild's ``tools.rspack``).
728+
- ``enableBuildNotifications()`` and the ESLint integration are gone: run your linter as its own script, outside the
729+
build.
730+
- ``Encore.isProduction()`` / ``isDev()`` / ``when()``: branch on the bundler mode instead, e.g.
731+
``defineConfig(({ command }) => ...)`` where ``command`` is ``'build'`` or the dev command.
732+
611733
.. _Vite: https://vite.dev/
612734
.. _Rsbuild: https://rsbuild.dev/
613735
.. _`@symfony/stimulus-bridge`: https://github.com/symfony/stimulus-bridge

0 commit comments

Comments
 (0)