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.

Expose the `mode` option for loaders

See original GitHub issue

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

What is the current behavior? Currently, loaders don’t have access to webpack’s mode option.

What is the expected behavior? Loaders should have access to mode.

If this is a feature request, what is motivation or use case for changing the behavior? Does it make sense to expose the mode option to loaders? Loaders might use it to apply mode-specific optimizations – e.g., css-loader could enable minification in the production mode automatically.

This decreases the number of things a user has to know about and configure to make things work right.

(If the option is already exposed – sorry, just point me to it, I haven’t found it.)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:25 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Oct 24, 2018

Feel free to send a PR to expose the mode option for loaders

1reaction
terminalqocommented, Jun 5, 2018

webpack.common.js:

const devMode = process.env.NODE_ENV !== 'production';    //devMode = undefined
 module.exports = {
    module: {
        rules: [
         {
           test: /\.css$/,
           use: [
             devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
             'css-loader'
            ]
          }
        ]
    }
  },

webpack.prod.js:

module.exports = merge(common, {
   mode: 'production'
})

package.json:

 "build": "webpack --config webpack.prod.js",  // not work
// "build": "webpack --mode=production --config webpack.prod.js", // not work
// "build": "cross-env NODE_ENV=production webpack --config webpack.prod.js", // work
Read more comments on GitHub >

github_iconTop Results From Across the Web

expose-loader - webpack
The expose-loader loader allows to expose a module (in whole or in part) to global object ( self , window and global )....
Read more >
Webpack migration from v4 to v5, expose-loader throwing error
Here is how we could finally get this to work: (by using exposes= keyword) client: [ "./ts/client-polyfills.ts", ...
Read more >
Extending with Loaders - SurviveJS
The official documentation covers the loader API in detail. You can see all fields available through this there. For example, mode is exposed....
Read more >
README.md - UNPKG
Getting Started To begin, you'll need to install `expose-loader`: ```console $ npm install expose-loader ... Options | Name | Type | Default |...
Read more >
Options Reference - vue-loader
The config format is the same as loaders , but postLoaders are applied after the default loaders. You can use this to post-process...
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