Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2021

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Jan 22, 2021

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: v5 module dep invalidation not working in cases that do in v4 webpack/webpack#11074 (comment)
  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 (symfony/webpack-encore#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
Copy link
Member Author

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

Copy link
Contributor

@tgalopin tgalopin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, thanks Ryan!

src/index.js Outdated
// this import is be replaced by the NormalModuleReplacementPlugin
// to point to the real controllers.json file
// See create-controllers-module.js
import symfonyControllers from './webpack/loader!../controllers-placeholder.json';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the loader necessary here? If the NormalModuleReplacementPlugin pass before modules, we could have a nicer syntax here, like @symfony/controllers :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per your recommendation, NormalModuleReplacementPlugin is gone in favor of an alias :).

So, the loader IS needed here and I think it's helpful: it helps clarify (for a curious reader) that we are not parsing this as JSON, but doing something trickier.

Copy link
Contributor

@tgalopin tgalopin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works really well with aliases, that's nice!

@tgalopin tgalopin force-pushed the virtual-module-to-loader branch from 5f6a96b to fb5aaf7 Compare January 22, 2021 20:40
@tgalopin
Copy link
Contributor

Thanks @weaverryan.

@tgalopin tgalopin merged commit a720035 into symfony:main Jan 22, 2021
tgalopin added a commit that referenced this pull request Jan 24, 2021
This PR was merged into the main branch.

Discussion
----------

removing old files for the plugin

These are extra files I missed in #14

After these are deleted, the error in I added to the readme in #17 will occur if you use the updated version of this lib with an outdated Encore version.

Thanks!

Commits
-------

017ff71 removing old files for the plugin
weaverryan added a commit to symfony/webpack-encore that referenced this pull request Jan 27, 2021
…w loader (weaverryan)

This PR was squashed before being merged into the main branch.

Discussion
----------

updating stimulus-bridge plugin to work with proposed new loader

Partner to symfony/stimulus-bridge#14

* [x] Wait for partner PR to be merged

Commits
-------

5640760 updating stimulus-bridge plugin to work with proposed new loader
@weaverryan weaverryan deleted the virtual-module-to-loader branch February 1, 2021 18:10
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.

2 participants