我一直在尝试使用webpack的sass装载机,我遵循了这个指令,->,https://github.com/webpack-contrib/extract-text-webpack-plugin#extracting-sass-or-less,但这不起作用。
有人能帮我吗?
仓库
https://github.com/gpincheiraa/boolean-html-js-exercises/tree/dev
误差
ERROR in Error: Child compilation failed:
Module build failed: Error: "extract-text-webpack-plugin" loader is used without the corresponding plugin, refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example
- Error: "extract-text-webpack-plugin" loader is used without the corresponding plugin, refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example属地
node v6.11.1
npm 5.3.0
├── babel-cli@6.26.0
├── babel-loader@7.1.2
├── babel-plugin-transform-class-properties@6.24.1
├── babel-polyfill@6.26.0
├── babel-preset-es2015@6.24.1
├── babel-preset-stage-3@6.24.1
├── css-loader@0.28.7
├── extract-text-webpack-plugin@3.0.0
├── html-loader@0.5.1
├── html-webpack-plugin@2.30.1
├── markdown-loader@2.0.1
├── node-sass@4.5.3
├── sass-loader@6.0.6
├── style-loader@0.18.2
├── webpack@3.5.6
└── webpack-dev-server@2.7.1webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: [
"./index.js"
],
output: {
path: __dirname + "/dist",
filename: "index.bundle.js"
},
module: {
rules: [
{ test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" },
{ test: /\.md$/, loaders: [ "html-loader", "markdown-loader" ] },
{ test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: [
new ExtractTextPlugin('style.css'),
new HtmlWebpackPlugin({
template: 'index.html',
inject: 'body'
})
],
devtool: "eval-source-map",
devServer: {
filename: "index.bundle.js",
contentBase: "./",
port: 3000,
publicPath: "/",
stats: {
colors: true
}
}
};发布于 2017-09-12 21:25:03
这个问题来自于index.html。index.html由html-webpack-plugin处理,出于某种原因,它仍然试图处理需求调用(第9行和第11行)。原因可能是html-webpack-plugin的自定义EJS加载器。
最简单的解决方案是从index.html中完全删除注释的代码。
通过导入一个.scss文件,您所配置的规则将被应用于它。但是在这个过程中,实际的extract-text-webpack-plugin实例似乎是不可用的。在这些要求调用中,您正在使用内联加载程序,但配置的规则仍将应用于此。若要防止应用其他加载程序,可以在导入前加上一个!。
通过在请求中添加
!前缀,可以省略(重写)所有普通加载程序。 通过在请求中添加-!前缀,可以省略(重写)所有普通加载器和预加载器。 通过在请求中添加!!前缀,可以省略(重写)所有普通加载器、post加载程序和预加载器。
为了能够在HTML中正确地使用CSS,您还需要在css-loader之后使用sass-loader,因为EJS希望在这里使用JavaScript,而不是单独使用CSS。这一要求将成为:
<%= require("!css-loader!sass-loader!\./sass/index.scss") %>在实际应用程序中导入index.scss也比html-webpack-plugin使用的模板更好。
发布于 2018-01-12 20:41:36
我来这里是因为我和Webpack 3+ Sass + React的配置也不起作用。
然而,就我而言,这个问题是非常愚蠢的。我必须说,我使用create-react-app工具创建了这个项目,它设置了一个具有安静、复杂/完整配置的webpack.config.dev.js文件。
问题是,我在sass规则之后添加了 exclude one,它在注释(hah)中明确指出,之后的每个加载程序都不能工作。
所以现在看起来是这样的,它起作用了:
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [require.resolve('css-loader'), require.resolve('sass-loader')],
})
},
{
exclude: [/\.js$/, /\.html$/, /\.json$/],
loader: require.resolve('file-loader'),
options: {
name: 'static/media/[name].[hash:8].[ext]',
},
},希望这对将来的人有帮助。
https://stackoverflow.com/questions/46179720
复制相似问题