Wednesday, September 6, 2017

Webpack: Different (Define Plugin) settings per entry point

Leave a Comment

For some of my bundle files I would like to build different versions (for example one with admin functionality and one without).

It seems the DefinePlugin is usually used for this kind of thing, but there are also loaders like the if-loader or the ifdef-loader available.

Now the problem is that they all seem to share a configuration among all entry points. I would need a way to set a different configuration (like {with_admin_mode: true} and {with_admin_mode: false}) for the different entry points.

I though of putting the configuration at the top of the actual entry point JS files, but I don't know how to correctly create a global variable across all modules that will be detected as true == false and removed.

1 Answers

Answers 1

Try to look at webpack-mergeSmart Merging should helps you to solve your case.

It can helps to make dynamic configuration with specific entry points, plugins and what ever you want that would be depends on some variable on env.

Good practice to split configuration into different files. You can make some common configuration with the same things through all entry points, e.g loaders and then make custom configurations for with_admin_mode and without_admin_node modes.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment