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.

[6.x] Add Webpack rules per environment basis (using the Webpack template)

See original GitHub issue
  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Please describe your issue:

I’ve setup a small project using electron-forge, version 6. I’ve added css-loader, style-loader and mini-css-extract-plugin to my project in order to import css files and resolve them properly.

However, style-loader is only relevant in development and the mini-css-extract-plugin is only relevant in production. Since I only have one entrypoint per process, how do I separate configuration between environments?

According to the documentation, I shouldn’t need to care, but in this case I do need to care. Is there any example or guidelines for how one go about adding environment specific options using the Webpack template?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
b-zurgcommented, Apr 15, 2020

There’s other benefits to indicating production vs development. The most recent version of webpack uses a “mode” flag (see https://webpack.js.org/configuration/mode/) which runs some good optimizations based on the environment.

This can greatly impact the performance of a production app and is pretty much the only reason I use webpack.

I think some of the plugins it mentions like the TerserPlugin are really important to configure well as well.

3reactions
hovsatercommented, Jun 2, 2019

@MarshallOfSound thanks for the quick response.

Heh, well put 💯 If the webpack plugin set process.env.NODE_ENV to production while loading your config for prod packaging would that suit your use case?

I’m not entirely sure what you’re saying here. Are you asking me if using process.env.NODE_ENV would be enough if it reflected the current environment? If so, the short answer is yes.

No, that behavior is specific to the webpack cli rather than the webpack API that we consume.

I see. Would it be of interested supporting the behavior? It would align nicely with how Webpack currently works and make the transitions easier for people already using it. I’d be up for helping out with a pull request if we decide to move forward with that approach. 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

[6.x] Add Webpack rules per environment basis (using the ...
Is there any example or guidelines for how one go about adding environment specific options using the Webpack template?
Read more >
Module | webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
webpack Tutorial: How to Set Up webpack 5 From Scratch
Create a plugins property of your config and you'll add the plugin, filename to output ( index.html ), and link to the template...
Read more >
How to customize webpack in Rails apps - rossta.net
Still, the base webpack configuration provided by ... for all Rails environments, so is config/webpack/environment.js for each of the ...
Read more >
Creating a React app with Webpack - JavaScript Ramblings
Add Webpack and bundle a simple JS file; Add Babel for ES6 support; Add React. Without further ado, let's get started! Step 1:...
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