我有两个项目:Project A
和Project B
。
项目A
Webpack@2.2.1
Extract-text-webpack-plugin@2.0.0-rc.3
Angular 2.4.3
项目B
Project B
为Project A
提供了一系列模块/组件。
代码由Project B
编译(未捆绑)到dist文件夹中,然后由Project A
通过npm link
使用。
现在,使用webpack.common.js
设置使用ExtractTextPlugin
,浏览器会抛出异常:
Angular 2抛出此异常,但使用此插件时仅。
我这样说,因为如果我使用.css
加载raw-loader
个扩展程序,一切正常,但使用ExtractTextPlugin时,它就会中断。
webpack.config.js
module: {
rules: [
{
test: /\.css$/,
use: [ "raw-loader" ],
}
]
}
输出:
webpack.config.js
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract( {
fallback: "raw-loader",
use: [ "raw-loader" ]
} )
}
}
},
plugins: [
new ExtractTextPlugin( "[name].css" ),
]
输出:
抛出异常:
Uncaught TypeError: cssText.replace is not a function
at extractStyleUrls (http://localhost:8080/vendor.js:75001:52)
节点:6.2.0 操作系统:macOS Sierra(10.12.2)
答案 0 :(得分:0)
我刚遇到此问题,因为我有@Component
styleUrl
引用了有效的样式表文件,但该文件为空。删除不必要的styleUrl
为我解决了这个问题。
答案 1 :(得分:0)
检查此Webpack SASS build issue, everything compiles fine, then I get a JS error
中的答案除了答案,您可以使用require
,也可以在component.ts文件的基础上import
.css
个文件。
赞import '../assets/app.css';
答案 2 :(得分:0)
尝试在"angular2-template-loader":"^0.6.2"
dependencies
中添加package.json
,然后执行npm i
。这解决了我同样的问题