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.

Webpack5 uses speed-measure-webpack5-plugin mini-css-extract-plugin to fail

See original GitHub issue

package.json

{
  "name": "webpack-demo",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "webpack-dev-server",
    "build": "webpack"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "css-loader": "^5.2.1",
    "html-webpack-plugin": "4.5.2",
    "mini-css-extract-plugin": "^1.5.0",
    "speed-measure-webpack5-plugin": "^1.3.3",
    "style-loader": "^2.0.0",
    "tapable": "^2.2.0",
    "webpack": "5.0.0-rc0.6",
    "webpack-cli": "^4.6.0",
    "webpack-dev-server": "^2.9.4"
  }
}

webpack.config.js

var webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin'); // 生成html
var path = require('path')

const MiniCssExtractPlugin = require('mini-css-extract-plugin'); // 将CSS提取出来,而不是和js混在一起
const ROOT_PATH = path.resolve(__dirname)
const OUTPUT_PATH =path.resolve(ROOT_PATH,'bundle')
const SpeedMeasurePlugin = require('speed-measure-webpack5-plugin'); // 测量各个插件和loader所花费的时间
const bmp = new SpeedMeasurePlugin();
const prodConfig = {
  mode: 'production',
    entry: {
      index: "./src/index.js",
      utils: './src/utils.js',
    },
    output:{
        publicPath:'/',
        path:OUTPUT_PATH,
        filename: "[name].[hash].js",  // 改为 hash
    },
    devtool:'inline-source-map',
    devServer:{
        hot:true,
        publicPath:'/',
        contentBase:path.resolve(OUTPUT_PATH)
    },

    module:{
        rules:[
            {
                test:/\.js?$/,
                loader:'babel-loader',
                exclude:/node_modules/
            },
          {
            // .css 解析
            test: /\.css$/,
            use: [MiniCssExtractPlugin.loader, 'css-loader'],
          },
        ]
    },

    plugins:[
      new MiniCssExtractPlugin({
        filename: 'css/[name].[contenthash].css',
        chunkFilename: 'css/[id].[contenthash].css',
        ignoreOrder: false,
      }),
      new HtmlWebpackPlugin({
        filename: 'index.html', // 生成的html存放路径,相对于 output.path
        template: './public/index.html', // html模板路径
      }),
    ],
    resolve:{
        extensions:['.js']
    }
}

module.exports = bmp.wrap(prodConfig);

error info

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
Error: You forgot to add 'mini-css-extract-plugin' plugin (i.e. `{ plugins: [new MiniCssExtractPlugin()] }`), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started
    at Object.pitch (/Users/chunhaiguo/study/react-latest/node_modules/mini-css-extract-plugin/dist/loader.js:50:14)

My usage follows the example. Told me there was no new MinicsSexTractPlugin ()

I hope to ask the reason

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
alexander-akaitcommented, Apr 28, 2021

webpack already do it without plugin, try to use webpack --profile or Profile plugin, in v5 we improve plugin and now calculate loaders/plugins/etc, so you don’t need this plugin anymore

1reaction
getSpiddcommented, Apr 27, 2021

@alexander-akait Do you mean speed-measure-webpack5-plugin? I wanted to use this plugin to analyze the Webpack packaging process and time, and optimize it accordingly

Read more comments on GitHub >

github_iconTop Results From Across the Web

MiniCssExtractPlugin - webpack
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 erroring on mini-css-extract-plugin loader
I understand getAssets is only available since webpack 4.40.0 https://webpack.js.org/api/compilation-object/#getassets. You could try:.
Read more >
6. PostCSS & Mini CSS Extract Plugin - YouTube
We start with an empty directory and built up a complete Webpack starter k... ... PostCSS & Mini CSS Extract Plugin.
Read more >
mini-css-extract-plugin - npm
extracts CSS into separate files. Latest version: 2.7.2, last published: 23 days ago. Start using mini-css-extract-plugin in your project by ...
Read more >
Webpack error after upgrading mini-css-extract-plugin@1.6.2
Webpack error after upgrading mini-css-extract-plugin@1.6.2 ... npx webpack --mode development [hardsource:e5a41f90] Using 16 MB of disk ...
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