Changing entries from plugins
See original GitHub issueDo you want to request a feature or report a bug?
A feature
What is the current behavior?
The first tap hook that runs is “entry-option”, which converts the entry
option into either a single, multi, or dynamic plugin. This plugin then is called by the hook make
to create entries with compilation.addEntry
. This means it’s not possible to manipulate the entries in options
This is the list of hooks that gets called from the start:
apply entry-option
apply after-resolvers
apply watch-run
apply context-module-factory
apply compile
apply this-compilation
apply compilation
apply make
apply build-module
...
What is the expected behavior?
It would be great if there was a hook somewhere that lets you manipulate compilation.entries
before they are processed. Look at all the hoops https://github.com/singapore/webpack-entries-plugin/blob/master/lib/index.js has to jump through…
If this is a feature request, what is motivation or use case for changing the behavior?
It is very hard to change entries before they are emitted. In my use case, I want to add some code at the bottom of an entry, but simply appending it to the entry fails because the entry is wrapped in the library export.
Right now I push the module to the dependencies during the first build-module
call. This works, but is far from ideal: It’s hard to know which entry this is, and it causes the last module result to be returned. Ideally I’d be able to wrap the entry in a new one.
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Webpack v3 but looks like v4 works in the same way.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:10 (8 by maintainers)
This issue is basically me talking to myself 😃. Would be great if someone else could chime in on the technical details.
I finally realized that the best place to change
options.entry
is fromplugin.apply(compiler)
: It runs before all other hooks and has the compiler.Example:
https://github.com/ericclemmons/start-server-webpack-plugin/blob/3e585edd326a6d79bfee640b71e1f5d95b580e6e/src/StartServerPlugin.js#L149-L173
However, it is still a lot of code to amend. It would be great if entries were normalized in EntryOptionPlugin so that there is a hook
afterEntriesNormalize(compiler)
which always gets an object with per-entry keys that are arrays. That would mean always using the DynamicEntryPlugin.