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.

WebPack 4 should use "mini-css-extract-plugin" instead of "extract-text-webpack-plugin"

See original GitHub issue

I’m submitting a bug report

  • Library Version: 0.33.1

Please tell us about your environment:

  • Operating System: Windows 10

  • Node Version: 9.11.1

  • NPM Version: 5.6.0

  • Browser: all

  • Language: all

  • Loader/bundler: Webpack 4

Current behavior:

  • What is the expected behavior? Try to run a Prod build with au build --env prod or npm run build and you will get the following warning
DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead

Also on the extract-text-webpack-plugin GitHub it is mentioned that this package is deprecated with WebPack 4

Since webpack v4 the extract-text-webpack-plugin should not be used for css. Use mini-css-extract-plugin instead.

  • What is the motivation / use case for changing the behavior? Get a working build/bundle

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

9reactions
ghiscodingcommented, Jul 7, 2018

So it took me about 2 hours to get it working, but the good news is I got it working. I’m not sure if it’s the most efficient way and if the settings are correct.

Step 1 (package.json)

in package.json do the following change

  "devDependencies": {
-    "extract-text-webpack-plugin": "^3.0.2",
+    "mini-css-extract-plugin": "^0.4.1",

Step 2 (webpack.config.js)

in webpack.config.js I changed the following

-const ExtractTextPlugin = require('extract-text-webpack-plugin');
+const MiniCssExtractPlugin = require('mini-css-extract-plugin');

// ....
   module: {
     rules: [
       {
         test: /\.css$/i,
         issuer: [{ not: [{ test: /\.html$/i }] }],
-        use: extractCss ? ExtractTextPlugin.extract({
-          fallback: 'style-loader',
-          use: cssRules
-        }) : ['style-loader', ...cssRules],
+        use: extractCss ? [
+          {
+            loader: MiniCssExtractPlugin.loader
+          },
+          'css-loader'
+        ] : ['style-loader', ...cssRules]

// ...
     new CopyWebpackPlugin([{ from: 'assets/', to: 'assets/' }]),
-    ...when(extractCss, new ExtractTextPlugin({
+    ...when(extractCss, new MiniCssExtractPlugin({
       filename: production ? '[contenthash].css' : '[id].css',
       allChunks: true
     })),

So the good news is that if I try to do a yarn run build and/or yarn run, they both work (Dev/Prod). It would be great if Aurelia CLI would be updated to support these changes since again they do mention that the old plugin is deprecated and we should move to the new mini version

Since webpack v4 the extract-text-webpack-plugin should not be used for css. Use mini-css-extract-plugin instead.

0reactions
doktordirkcommented, Jul 19, 2018

@JeroenVinke just collection quickly

prevent eg bluebird to be included in both, vendor and app bundle

optimization: production ? {
    splitChunks: {
      cacheGroups: {
        commons: {
          test: /[\\/]node_modules[\\/]/,
          name: 'vendor',
          chunks: 'all',
        },
      },
    },
  } : {},

don’t parse json twice. needed eg for aurelia-i18n with build-in loader

 {
        type: 'javascript/auto',
        test: /\.json$/,
        use: ['json-loader'],
      },

i think over css setting isn’t minifing, se needs eg

    ...when(production, new OptimizeCssAssetsPlugin({
      cssProcessorOptions: {
        safe: true,
        discardComments: { removeAll: true },
      },
    })),

it could be explored if following could be added with some useful defaults

  • PreloadWebpackPlugin
  • ResourceHintWebpackPlugin
Read more comments on GitHub >

github_iconTop Results From Across the Web

setup MiniCssExtractPlugin from ExtractTextPlugin
I was using the plugin incorrectly it seems. I changed by adding this to my build configs new MiniCssExtractPlugin({ filename: ...
Read more >
MiniCssExtractPlugin
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 4 | Mobify DevCenter
As of Webpack 4, mini-css-extract-plugin should be used for CSS in place of extract-text-webpack-plugin. To comply, make these changes to these four files:....
Read more >
Step-by-step Guide to Upgrading to Webpack 4 - Oleg Chursin
Sub extract-text-webpack-plugin with mini-css-extract-plugin ... by default it use publicPath in webpackOptions.output publicPath: '../'
Read more >
extract-text-webpack-plugin > JavaScript for PHP Geeks
... instead of embedding CSS in JavaScript. Tip. In Webpack 4 you can use the beta version extract-text-webpack-plugin@4.0.0-beta.0 or there is a new...
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