young B
young B

Reputation: 129

Webpack. Pass parameters to entry point

I have a multi-page app. And I have configured multi-entry points with one js file. The reason for making this: these two pages have a lot of the same code. So far, I have already read about webpack-plugins and webpack configuration without any result.

Question: Can I pass some parameter to page1 entry point and page2 entry point in order to my index.js file will resolve what exactly it should do? Is it possible? And could anyone give advice on this issue?

...
entry: {
    page1: "./index.js",
    page2: "./index.js"
},
...

Upvotes: 3

Views: 2156

Answers (2)

tuomassalo
tuomassalo

Reputation: 9101

webpack-hot-middleware/client uses a magic __resourceQuery for the job:

if (__resourceQuery) { var querystring = require('querystring'); var overrides = querystring.parse(__resourceQuery.slice(1)); setOverrides(overrides); }

Here, overrides gets the querystring as an object.

Source: https://github.com/glenjamin/webpack-hot-middleware/blob/8984fa2845da68b8b9652669f738d6d49ce8e4b5/client.js#L16-L20

Upvotes: 1

Andrea Carraro
Andrea Carraro

Reputation: 10419

I would suggest to create an entry point for each page and require index.js from there.

Cleaner and easily readable.

Upvotes: 0

Related Questions