使用webpack不熟悉,遇到一个问题,我认为css-loader无法解决我的@import
?
const config = {
entry: {
main: __dirname + '/js/index.jsx'
},
devtool: 'eval-source-map',
plugins: [
new MiniCssExtractPlugin({
filename: isDevelopment ? '[name].css' : '[name].[hash].css',
chunkFilename: isDevelopment ? '[id].css' : '[id].[hash].css'
})
],
module: {
rules: [
{
test: /\.jsx?/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.s(a|c)ss$/m,
include: [
resolve(__dirname, '/sass'),
],
use: [
{
loader: isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: isDevelopment,
implementation: require('sass')
}
}
]
}
]
}
}
application
|
|___static
| |____dist
|____js
| |____react components in here
|____sass
| |____abstracts
| | |____variables.scss
| |____pages
| | |_____app.scss
| |____main.scss
|____package-lock.json
|____package.json
|____webpack.config.js
main.scss
的内容有误。
ERROR in ./sass/main.scss 1:0
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> @import 'abstracts/variables';
| @import 'pages/app';
|
@ ./js/components/App.jsx 20:0-37 35:19-25
@ ./js/routes.js
@ ./js/index.jsx
任何指针都很棒!谢谢!
亚历克斯
答案 0 :(得分:0)
问题是
include: [
resolve(__dirname, '/sass'),
],
已移除并按预期工作。