gpt4 book ai didi

sass - 加载器列表中的元素应该有 'loader' 或 'loaders' 与 sass-loader webpack

转载 作者:行者123 更新时间:2023-12-04 02:16:51 30 4
gpt4 key购买 nike

我的 webpack 加载器数组中有这个加载器:

{ test: /\.scss$/, exclude: /node_modules/, loaders: ExtractTextPlugin('style-loader', 'css-loader!sass-loader') }

我正在尝试让 webpack 将我的 SCSS 构建为 CSS,但出现此错误:

/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/webpack-core/lib/LoadersList.js:60
throw new Error("Element from loaders list should have one of the fields 'loader' or 'loaders'");
^

Error: Element from loaders list should have one of the fields 'loader' or 'loaders'
at getLoadersFromObject (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/webpack-core/lib/LoadersList.js:60:8)
at LoadersList.<anonymous> (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/webpack-core/lib/LoadersList.js:78:12)
at Array.map (native)
at LoadersList.match (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/webpack-core/lib/LoadersList.js:70:19)
at NormalModuleFactory.<anonymous> (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/lib/NormalModuleFactory.js:109:65)
at /Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:697:13
at /Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:52:16
at done (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:248:21)
at /Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:44:16
at /Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:694:17

这是我的完整 webpack 配置:

var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
var ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
entry: [
'./app/index'
],

output: {
path: path.resolve('./public/bundles/'),
filename: "[name]-[hash].js",
},

plugins: [
new BundleTracker({filename: './webpack-stats.json'}),
],

module: {
loaders: [
{ test: /\.css$/, exclude: /node_modules/, loader: 'style!css' },
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.jsx$/, loaders: ['react-hot', 'babel-loader'], include: path.join(__dirname, 'app') },
{ test: /\.es6$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
{ test: /\.scss$/, exclude: /node_modules/, loaders: ExtractTextPlugin('style-loader', 'css-loader!sass-loader') }
]
},
}

最佳答案

Sokra 在此处提供了如何使用 ExtractTextPlugin 的示例:https://github.com/webpack/extract-text-webpack-plugin/blob/master/example/webpack.config.js

如您所见,您的示例与他的示例之间存在一些差异。

  • ExtractTextPlugin 构造函数在“plugins: [ ]”数组中用new 调用
  • 插件在loaders数组中的使用方式是调用静态方法.extract(),而不是简单的调用插件构造函数
  • “loader object”中的引用是针对“loader:”属性的,而不是如您所说的“loaders:”(loaders 是一个选项,但需要一个数组)

希望对您有所帮助!

关于sass - 加载器列表中的元素应该有 'loader' 或 'loaders' 与 sass-loader webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33316484/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com