symfony / stimulus-bridge

Stimulus integration bridge for Symfony projects
https://symfony.com/ux
75 stars 15 forks source link

Replacing virtual-modules with a loader for controller.json #14

Closed weaverryan closed 3 years ago

weaverryan commented 3 years ago

Hi!

The motivation behind this was a few things:

1) the wepback-virtual-modules plugin emits a worrying warning in Webpack 5 and, in general, doesn't seem to be super-actively developed. 2) sokra says that a loader is the correct solution: https://github.com/webpack/webpack/issues/11074#issuecomment-648658214 3) Since loaders are native/normal, this works well with watch mode and should work just fine with Webpack 5 persistent build caching.

This also includes a tricky NormalModuleReplacementPlugin() so that we can continue to handling the parsing of the user's controller.json inside this library (instead of putting the import + loader code in their app).

This will require a partner PR in webpack-encore (https://github.com/symfony/webpack-encore/pull/888). The only line users will need to change in their app is to remove import '@symfony/autoimport'; from their assets/bootstrap.js file.

Cheers!

weaverryan commented 3 years ago

I've just tested this in a real project along with its sister PR in Encore. It works great!

tgalopin commented 3 years ago

Thanks @weaverryan.