我一直在寻找解决我的问题,但无法找到为什么我的CSS没有被加载。 我有一个简单的Angluar 2应用程序需要在组件中的HTML和CSS。 webpack正在捆绑并创建html和js文件的bundle.js。但是,它不会加载包中的css文件。相反,我实际的CSS却让:未加载原始CSS我的bundle.js Angular 2应用程序
function(module, exports) {
module.exports = "// style-loader: Adds some css to the DOM by adding a <style> tag\n\n// load the styles\nvar content = require(\"!!./../../node_modules/css-loader/index.js!./print.css\");\nif(typeof content === 'string') content = [[module.id, content, '']];\n// add the styles to the DOM\nvar update = require(\"!./../../node_modules/style-loader/addStyles.js\")(content, {});\nif(content.locals) module.exports = content.locals;\n// Hot Module Replacement\nif(module.hot) {\n\t// When the styles change, update the <style> tags\n\tif(!content.locals) {\n\t\tmodule.hot.accept(\"!!./../../node_modules/css-loader/index.js!./print.css\", function() {\n\t\t\tvar newContent = require(\"!!./../../node_modules/css-loader/index.js!./print.css\");\n\t\t\tif(typeof newContent === 'string') newContent = [[module.id, newContent, '']];\n\t\t\tupdate(newContent);\n\t\t});\n\t}\n\t// When the module is disposed, remove the <style> tags\n\tmodule.hot.dispose(function() { update(); });\n}"/***/ }
这里是与我webpack.config文件的CSS部分我使用:
{
test: /\.css$/,
loader: 'raw'
},
{
test: /\.css$/,
loader: 'style!css'
},
{
test:/\.gif|png/, loader: "file-loader"
},
{
test: /\.html$/,
loader: 'raw'
}
resolve: {
extensions: ['', '.ts', '.js', '.json','.css', '.html']
}
,并在我的组件我只是需要html和css文件。
@Component({
selector: 'my-app',
styles: [require('./my.css')],
template: require('./my.html')
})
放在bundle.js的文字就像是装载机找不到css文件,但他们是在正在加载我的HTML文件相同的相对路径。
有谁知道可能是什么问题?
欣赏任何建议,我尝试了不同的事情而处于亏损状态。