question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing entries from plugins

See original GitHub issue

Do 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
wmertenscommented, Mar 8, 2019

This issue is basically me talking to myself 😃. Would be great if someone else could chime in on the technical details.

1reaction
wmertenscommented, Mar 8, 2018

I finally realized that the best place to change options.entry is from plugin.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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to do Search and Replace in WordPress with a Plugin
First thing you need to do is install and activate the Better Search Replace plugin. Upon activation, you need to visit Tools »...
Read more >
plugin development - Programatically Changing Entry Types?
Something like this should work. I've also cleaned up the code a bit to be correct PHP syntax as my assumption is that...
Read more >
Post Type Switcher – WordPress plugin
The plugin can convert nearly every combination of posts, pages, and even custom post types: ... As of 3.0.0, support for switching to...
Read more >
How to Convert or Change Custom Post Types in WordPress
This plugins adds a function to posts that lets you change the type before or after publishing. Let's take a look at how...
Read more >
Updating Plugins for Craft 4 | Craft CMS Documentation | 4.x
# Changed ; elements/save-element, elements/save ; entries/delete-entry, elements/delete ; entries/delete-for-site, elements/delete-for-site ; entries/duplicate- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found