gpt4 book ai didi

css - Webpack 在 SCSS @import SCSS 上抛出错误

转载 作者:太空狗 更新时间:2023-10-29 12:22:42 28 4
gpt4 key购买 nike

我正在尝试将多个 SCSS 文件处理成 Webpack (3.6.0) 中的单个外部 CSS 文件,但我在解析 @import 语句时遇到问题。

条目 index.js 包含:

import './styles/main.scss';

入口 SCSS:

@import 'reset.scss';
@import 'global.scss';
@import 'fonts.scss';
@import 'system.scss';

当前的网络包:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
entry: {
app: './src/index.js'
},
context: path.resolve(__dirname),

output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js',
},

plugins: [
new CleanWebpackPlugin(['app']),
new HtmlWebpackPlugin({
title: 'Minimum-Viable',
filename: 'index.html',
template: './public/index.html',
}),
],

module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'es2015',
'react',
],
plugins: ['transform-class-properties'],
},
},
},
{
test: /\.scss$/,
include: [
path.resolve(__dirname, 'styles')
],
use: [
{loader:'style-loader'},
{loader:'css-loader'},
{loader:'sass-loader'}
]
},
],
},
resolve: {
extensions: ['.js','.scss']
}
};

抛出的错误是:

ERROR in ./src/styles/main.scss Module parse failed: Unexpected character '@' (1:0)

You may need an appropriate loader to handle this file type. | @import 'reset.scss';

感谢收到的任何指示。

最佳答案

我设法重现了错误,它似乎来自:

include: [
path.resolve(__dirname, 'styles')
],

路径是导致加载程序在 ./styles 中搜索 /styles 但查看您的入口点的问题:

entry: {
app: './src/index.js'
},

它实际上应该是 ./src/styles 所以:

include: [
path.resolve(__dirname, 'src', 'styles')
],

关于css - Webpack 在 SCSS @import SCSS 上抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47291727/

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