本项目使用nodev14.17.0
npm i node-sass@4.14.1 --save-dev
npm i sass-loader@10.1.1 --save-dev
webpack.config.js配置
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.html$/,
use: [{
loader: 'html-loader',
}, ],
},
{
test: /\.css$/,
use: [{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: true
}
}
],
},
{
test: /\.node$/,
loader: 'node-loader',
},
{
test: /\.s[ac]ss$/i,
use: [
// 将 JS 字符串生成为 style 节点
'style-loader',
// 将 CSS 转化成 CommonJS 模块
'css-loader',
// 将 Sass 编译成 CSS
'sass-loader',
],
},
],
},
详细查看https://webpack.docschina.org/loaders/sass-loader/
详细查看https://webpack.docschina.org/loaders/node-loader/