我将mterial-components-web.css添加到我的index.html文件头。
<script src="node_modules/material-components-web/dist/material-components-web.js"></script>
<script src="dist/bundle.js"></script>
css组件工作得很好。现在我通过webpack添加了几个javscript组件。现在我想我可以把所有的vai webpack都加到我的bundle.js里了。
import 'material-components-web/dist/material-components-web.js';
没有错误,但没有加载任何样式!问题出在哪里?
问候
我的webpack配置。
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
entry: './src/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: [
new ExtractTextPlugin('style.css')
],
devServer: {
contentBase: "./build"
}
};
发布于 2017-12-09 03:29:58
如果不看一下webpack的配置,很难确定确切的原因。
然而,CSS需要webpack docs中建议的两个加载器。我只能猜测装载机没有就位。
还可以使用内联导入,如here所述
尽管不是很接近您正在尝试的内容,但是您可以随意浏览一下this中包含的简单代码。它基本上有通过webpack捆绑的引导css。但是请注意,我使用的是require()
,而不是import
。在webpack配置中添加适当的js预编译器,切换起来应该不难。
https://stackoverflow.com/questions/47720151
复制相似问题