运行构建时出现此错误。
Invalid CSS after "module.exports": expected "{", was '= "data:text/x-scss'
我也尝试使用vanilla JS webpack配置并获得相同的错误,因此它不是TypeScript配置。还尝试了extract-text-webpack-plugin但得到了同样的错误。实际的应用程序工作正常,但显然没有CSS。这是配置。
import * as path from 'path';
import * as webpack from 'webpack'
const config: webpack.Configuration = {
entry: {
app: ['./js/main.ts']
},
output: {
path: path.resolve(__dirname, './dist/js'),
filename: '[name].js'
},
module: {
rules:[
{
test: /\.html$/,
loader: 'ngtemplate-loader?prefix=/&module=app&relativeTo=' + (path.resolve(__dirname, './js/app')) + '/!html-loader'
},
{
test: /\.ts$/,
loader: 'awesome-typescript-loader'
},
{
test: /\.(sass|scss|ttf|svg|woff)$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader",
}, {
loader: "url-loader"
}]
}
]
}
}
export default config
这是主要sass文件的片段。
@import "utilities/variables";
@import "utilities/animations";
@import "utilities/helpers";
使用以下内容在主应用文件中导入:
import '../sass/sass.scss';
答案 0 :(得分:6)
我认为错误是因为您以某种方式对url-loader
文件使用Sass
。拆分(sass|scss|ttf|svg|woff)
的webpack.config规则,使其如下所示:
{
test: /\.(ttf|svg|woff)$/,
use: [{
loader: "url-loader"
}]
},
{
test: /\.(sass|scss)$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader",
}]
}