kdu*_*312 4 javascript node.js webpack mini-css-extract-plugin
当我尝试为 mini-css-extract-plugin 使用加载器时,webpack 返回以下错误:
/node_modules/mini-css-extract-plugin/dist/loader.js:122
for (const asset of compilation.getAssets()) {
^
TypeError: compilation.getAssets(...) is not a function or its return value is not iterable
Run Code Online (Sandbox Code Playgroud)
我需要插件并在我的 prod 配置文件中调用加载程序:
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const path = require("path");
const common = require("./webpack.common");
const merge = require("webpack-merge");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = merge(common, {
mode: "production",
output: {
filename: "[name].[contentHash].bundle.js",
path: path.resolve(__dirname, "dist")
},
plugins: [
new MiniCssExtractPlugin({filename: "[name].[contentHash].css"}),
new CleanWebpackPlugin()
],
module: {
rules: [
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader, //3. Extract css into files
"css-loader", //2. Turns css into commonjs
"sass-loader" //1. Turns sass into css
],
},
],
},
});
Run Code Online (Sandbox Code Playgroud)
我将它包含在我的 devDependencies 中:
"mini-css-extract-plugin": "^1.3.6",
Run Code Online (Sandbox Code Playgroud)
但我仍然收到错误。我没有在 [文档][1] 中找到任何内容来表明可能发生的情况。这段代码有什么我忽略的地方吗?
为什么 loader.js 中的方法会被标记为“不是函数”?[1]:https : //www.npmjs.com/package/mini-css-extract-plugin
我知道 getAssets 仅在 webpack 4.40.0 https://webpack.js.org/api/compilation-object/#getassets 之后可用
你可以试试:
webpack至少更新版本4.40.0min-css-extract-plugin到1.3.0我尝试了第二个,并为我工作,但升级 webpack 也应该工作。
| 归档时间: |
|
| 查看次数: |
2545 次 |
| 最近记录: |