我正在努力让 Webpack 4.0 编译我想使用 Google 材料设计 SASS 文件的 SASS。我认为这是无法访问 node_modules 文件夹中的 SASS 文件的问题。
var ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
module.exports = {
//entry: path.resolve(__dirname, 'react/test/index.js'),
entry: [path.resolve(__dirname, 'react/test/index.js'),
path.resolve(__dirname, 'styles/main.scss')],
output: {
path:path.resolve(__dirname, 'web/webroot/_ui/desktop//js'),
filename: 'testOutput.js'
},
devtool: 'sourcemap',
watch: true,
module: {
rules: [
{
test: /\.(css|sass|scss)$/,
//exclude: /node_modules/,
include: path.resolve(__dirname, 'node_modules/@material'),
use:ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader','sass-loader'],
})
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.css$/,
exclude: /node_modules/,
use: ['css-loader']
}
]
},
plugins: [
new ExtractTextPlugin({
filename: 'style-soutput.css'
})
]
}
我想通过使用:
包括:path.resolve(__dirname, 'node_modules/@material'),
将使 webpack 能够获取 Material SASS 文件。但我得到了错误:
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
@import 'themeColors';
@import "@material/button/mdc-button";
感谢能够包含 Google 材料 SASS 文件夹的任何帮助。