当我运行 npm run build 失败时,引用 mini-css-extract-plugin:
C:\dev\udemy-restfull\webpack\node_modules\mini-css-extract-plugin\dist\index.js:76
const resource = this._identifier.split('!').pop();
^
TypeError: Cannot read property 'split' of undefined
我试图搜索错误,但只知道它取决于加载程序执行的顺序,所以我只留下了 MiniCssExtractPlugin.loader 和 css-loader,但错误仍然存在。
我浏览了文档并获得了简化的设置,也发生了同样的错误。
我已经在 index.js 中加载了引导程序,所以我删除了它,认为这可能是原因,也不好。
你能帮助我吗?
这是我的 webpack.config.js 文件:
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
entry: ["@babel/polyfill", "./src/index.js"],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
plugins: [
new MiniCssExtractPlugin({
filename: 'style.css'
})
],
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: MiniCssExtractPlugin.loader }, // style-loader
{ loader: "file-loader" }
]
},
{
test: /\.(scss)$/,
use: [
{
loader: MiniCssExtractPlugin.loader, // inject CSS to page / style-loader
},
{
loader: 'css-loader', // translates CSS into CommonJS modules
},
{
loader: 'postcss-loader', // Run post css actions
options: {
plugins: function () { // post css plugins, can be exported to postcss.config.js
return [
require('precss'),
require('autoprefixer')
];
}
}
},
{
loader: 'sass-loader' // compiles Sass to CSS
}]
},
]
},
devServer: {
contentBase: './dist',
port: 9000
}
};
这是我的 package.json 文件:
{
"name": "app-webpack",
"version": "1.0.0",
"description": "teste com webpack",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development"
},
"author": "Johnatan Lopes",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.1.0",
"@babel/core": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"autoprefixer": "^9.1.5",
"babel-loader": "^8.0.4",
"css-loader": "^1.0.0",
"file-loader": "^2.0.0",
"mini-css-extract-plugin": "^0.4.3",
"node-sass": "^4.9.3",
"postcss-loader": "^3.0.0",
"precss": "^3.1.2",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.0",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.9"
},
"dependencies": {
"@babel/polyfill": "^7.0.0",
"bootstrap": "^4.1.3",
"jquery": "^3.3.1",
"popper.js": "^1.14.4"
}
}