Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the "disabled" option #88

Closed
dstarosta opened this issue Apr 4, 2018 · 3 comments
Closed

Add the "disabled" option #88

dstarosta opened this issue Apr 4, 2018 · 3 comments

Comments

@dstarosta
Copy link

ExtractTextPlugin has a disabled option that can be used to easily disable it during hot reload or watch builds. It would be a nice enhancement to the MiniCssExtractPlugin as well.

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Apr 4, 2018

webpack.config.js

const env = process.env.NODE_ENV  || 'development'

const config = {
   mode: env, 
   ...
   plugins: [
     this.mode === 'production' ? new MiniCSSPlugin() : false 
   ].filter(Boolean)
}

That's the 'generic' way to do it within webpack.config.js applicable to all kind of env || mode related settings, no need to add an extra option here...

@dstarosta
Copy link
Author

dstarosta commented Apr 4, 2018

The problem is you would have to add the same conditional logic to the loader which gets messy especially if you support multiple CSS formats (CSS, LESS...).

Otherwise, webpack throws the following error:

Module build failed: TypeError: this[NS] is not a function

@michael-ciniawsky
Copy link
Member

It seems that MiniCSSExtractPlugin doesn't support the fallback anymore, so a disable option wouldn't add any benefit here since you need to handle the loader part manually anyways...

webpack.config.js

const css = (env = 'development', extend = []) => [
   env === 'production' ? MiniCSS.loader : 'style-loader',
   'css-loader',
].concat(extend)

const config = {
   module: {
      ...
         use: css(this.mode, [ 'some-loader' ])
      ...
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants