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.

[DefinePlugin] Be able to define globals by entry points ?

See original GitHub issue

Do you want to request a feature or report a bug? feature

If this is a feature request, what is motivation or use case for changing the behavior? My main goal is to create a bundle per role on my app. I discovered the DefinePlugin, and looks pretty cool but it would be better if we could define globals by entry points. This way i could have multiple entry on the same file but something like :

/* webpack config */
entry: {
    "user": "path_to_client_index",
    "admin": "path_to_client_index",
}

new webpack.DefinePlugin({
    entry: {
        "user" : {
            __ROLE__: "'" + "user" + "'",
        },
        "admin" : {
            __ROLE__: "'" + "admin" + "'",
        },
    }
})

/* entry index.js */
import route from "routes/" + __ROLE__;

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:7

github_iconTop GitHub Comments

14reactions
johnnysprinklescommented, Sep 25, 2018

+1 to this. When building “multipage” isomorphic React apps where you have one clientside bundle per page, it would be handy to do it all in one configuration with entry points.

7reactions
blizzardzhengcommented, Apr 2, 2018

Is there any other way to get custom variables into individual entries? i do not wanner to create mulitiple configs, just the define plugin

Read more comments on GitHub >

github_iconTop Results From Across the Web

DefinePlugin | webpack
The DefinePlugin replaces variables in your code with other values or expressions at compile time. This can be useful for allowing different behavior ......
Read more >
Define global variable with webpack - Stack Overflow
There are several way to approach globals: 1. Put your variables in a module. Webpack evaluates modules only once, so your instance remains ......
Read more >
Optimizing your JavaScript Bundle | DefinePlugin Webpack
Here we define a constant which would be available in the global scope of our bundle -- ... This file will be the...
Read more >
Environment Variables : Webpack config using DefinePlugin
“The DefinePlugin allows you to create global constants which can be configured at compile time.” We can use Define plugin in webpack.config ...
Read more >
Environment Variables - SurviveJS
Webpack's DefinePlugin enables replacing free variables so that you can convert if (process.env. ... Starting from webpack 4, process.env.
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