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.

Merge webpack plugin configuration / DefinePlugin

See original GitHub issue

Current Behavior

If you add a DefinePlugin section to your webpack.haul.js / config plugins, it will override the default DefinePlugin stuff set up for you by makeReactNativeConfig. For example, you could have a webpack.haul.js like:

module.exports = ({ platform }) => ({
  entry: `./index.js`,
  plugins: [
    new webpack.DefinePlugin({
      'API_HOST': JSON.stringify(process.env.API_HOST),
    }),
  ]
});

If you try to run your app, you’ll get mysterious errors such as undefined variable __DEV__, but after looking into it the problem is that the plugins are overridden.

Expected Behavior

I think there are a few options here.

  1. haul should be able to intelligently merge plugins
  2. haul should provide documentation / a clear path for merging of plugins
  3. Just for my specific case, haul should provide the ability to forward environment variables or other fine grained configuration.

Haul Configuration (webpack.haul.js)

Sufficient to reproduce:

module.exports = ({ platform }) => ({
  entry: `./index.js`,
  plugins: [],
});

Your Environment

software version
Haul v1.0.0-beta.13
react-native 0.53.0
node 9.5
npm or yarn 1.3.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
baygeldincommented, Mar 6, 2018

That’s a good point. Although looking at webpack-merge sources I’m not sure if it can merge plugins configuration, but it can swap plugins though. Anyway, babel-plugin-transform-inline-environment-variables works perfectly for my usecase, so it’s okay. Thanks for your help. Keep it up, Haul is a great tool 😃

1reaction
satya164commented, Mar 6, 2018

@baygeldin with the new config format you can use something like webpack-merge to do the merging. I think it’s better that we don’t try to solve this problem because there are other tools which try to solve it already.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DefinePlugin
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 >
How to use the webpack-merge.strategy function in ...
To help you get started, we've selected a few webpack-merge.strategy ... the settings that are common to prod and dev /** * Webpack...
Read more >
webpack merge definePlugin process.env.NODE_ENV ...
config files. I am trying to pass the node_env (or any other variabels);. How can I access the process env variable from the...
Read more >
webpack-merge JavaScript and Node.js code examples
configs/webpack.renderer.dev.js/merge.smart. merge.smart(baseConfig, { mode: "development", plugins: [ new webpack.DefinePlugin({ 'process.env.
Read more >
webpack 4 - How to have separate build outputs ... - Ed Spencer
This is because the mode flag can only be used in the DefinePlugin phase, where it is mapped to the NODE_ENV variable. The...
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