Module build failed: Error: "extract-text-webpack-plugin" when import .scss file
Module build failed: Error: "extract-text-webpack-plugin" when import .scss file
在react组件中导入.scss文件时出现此问题
package.json
"scripts": {
"dev": "source ./.env && nodemon server.js"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.11",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"nodemon": "^1.17.2",
"sass-loader": "^6.0.7",
"style-loader": "^0.20.3",
"webpack": "^4.4.1",
"webpack-dev-middleware": "^3.1.0",
"webpack-dev-server": "^3.1.1"
}
webpack.config.js
module.exports = {
mode: 'development',
entry: './client/app/index.js',
output: {
path: `${__dirname}/dist`,
publicPath: '/',
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.jsx?$/,
include: `${__dirname}/client`,
loader: 'babel-loader',
},
{
test: /\.scss$/,
loaders: [
'style-loader',
'css-loader',
'sass-loader'
]
}
]
}
};
server.js
-----
if (process.env.NODE_ENV === 'development') {
const compiler = webpack(webpackConf);
app.use(webpackMiddleware(compiler, {
publicPath: webpackConf.output.publicPath,
contentBase: './client',
hot: true,
stats: {
colors: true
}
}));
}
----
它非常有线。我不使用 extract-text-webpack-plugin.
但问题在于它。
我尝试将 webpack 降级到 v3。但还是失败了...
谁能帮我解决一下...
第一。如果您使用 sass-loader
,则需要使用此 configuration
来自 github.
的推荐
其次:rule.loaders
配置错误。参见 link
第三:extract-text-webpack-plugin
是webpack的依赖。
在react组件中导入.scss文件时出现此问题
package.json
"scripts": {
"dev": "source ./.env && nodemon server.js"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.11",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"nodemon": "^1.17.2",
"sass-loader": "^6.0.7",
"style-loader": "^0.20.3",
"webpack": "^4.4.1",
"webpack-dev-middleware": "^3.1.0",
"webpack-dev-server": "^3.1.1"
}
webpack.config.js
module.exports = {
mode: 'development',
entry: './client/app/index.js',
output: {
path: `${__dirname}/dist`,
publicPath: '/',
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.jsx?$/,
include: `${__dirname}/client`,
loader: 'babel-loader',
},
{
test: /\.scss$/,
loaders: [
'style-loader',
'css-loader',
'sass-loader'
]
}
]
}
};
server.js
-----
if (process.env.NODE_ENV === 'development') {
const compiler = webpack(webpackConf);
app.use(webpackMiddleware(compiler, {
publicPath: webpackConf.output.publicPath,
contentBase: './client',
hot: true,
stats: {
colors: true
}
}));
}
----
它非常有线。我不使用 extract-text-webpack-plugin.
但问题在于它。
我尝试将 webpack 降级到 v3。但还是失败了...
谁能帮我解决一下...
第一。如果您使用 sass-loader
,则需要使用此 configuration
来自 github.
其次:rule.loaders
配置错误。参见 link
第三:extract-text-webpack-plugin
是webpack的依赖。