安装Sass-Loader
我正在尝试为我的angularjs应用程序创建WebPack构建。我不断得到:
ERROR in ./client/app/app.scss
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
| @import "common/common";
|
| .app {
@ ./client/app/app.scss 4:14-37
@ ./client/app/app.component.js
@ ./client/app/app.js
@ multi (webpack)-dev-server/client?http://localhost:9000 ./client/app/app.js
重复几次此类型的错误...
我正在尝试使用dllReference插件,这是我的应用。配置:
var path = require("path");
var webpack = require("webpack");
module.exports = {
devServer: {
contentBase: path.join(__dirname, "build"),
compress: true,
port: 9000
},
node: {
fs: 'empty'
},
cache: true,
devtool: "eval", //or cheap-module-eval-source-map
entry: {
app: path.join(__dirname, "client/app", "app.js")
},
output: {
path: path.join(__dirname, "build"),
filename: "newapp.js",
chunkFilename: "[name].js"
},
plugins: [
//Typically you'd have plenty of other plugins here as well
new webpack.DllReferencePlugin({
context: path.join(__dirname, "client"),
manifest: require("./build/vendor-manifest.json")
}),
],
module: {
loaders: [
{
test: /.js?$/,
loader: "babel-loader",
include: [
path.join(__dirname, "client") //important for performance!
],
query: {
cacheDirectory: true, //important for performance
plugins: ["transform-regenerator"],
presets: ["es2015", "stage-0"]
}
},
{ test: /.(scss|sass)$/, loader: 'style-loader' },
{ test: /.html$/, loader: 'raw-loader' },
{ test: /.css$/, loader: 'css-loader' }
]
},
resolve: {
extensions: [".js"]
}
};
和我的dll.config:
var path = require("path");
var webpack = require("webpack");
module.exports = {
entry: {
dependencies: ["angular","lodash","style-loader","sass-loader","fs","fs-walk","node-sass","css-loader"],
},
node: {
fs: 'empty'
},
output: {
filename: 'vendor.bundle.js',
path: '/Users/dimitri/NG6-starter/build',
library: 'vendor_lib',
},
plugins: [new webpack.DllPlugin({
name: 'vendor_lib',
path: 'build/vendor-manifest.json',
})]
};
如何解决此类错误?
您当前仅指定加载SASS文件的style-loader
。您将需要包括css-loader
和sass-loader
。
{
test: /.(scss|sass)$/,
loader: ['style-loader', 'css-loader', 'sass-loader']
}
style-loader:从JS字符串创建样式节点
css-loader:将CSS转换为commonjs
sass-loader:将SASS编译到CSS
注意:不要忘记使用npm install --save sass-loader