我正在尝试让webpack输出一个css文件,而不是内联样式。我一直在使用extract-text-webpack-plugin。
我已根据文档进行了设置,并查看了有关stackoverflow的类似问题,但无法弄清楚为什么我的下面的webpack配置文件没有输出文件或在index.html中放入任何内容
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: [
'webpack/hot/only-dev-server',
'./app/main.js'
],
output: {
path: __dirname + '/dist',
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.js?$/,
loaders: ['react-hot', 'babel'],
exclude: /node_modules/
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style', 'css!less')
//loader: "style!css!less"
}
]
},
plugins: [
new webpack.NoErrorsPlugin(),
new ExtractTextPlugin('[name].css', {
allChunks: true
})
]
};
答案 0 :(得分:1)
实际上,在当前状态下,您需要手动嵌入CSS。
但是,如果您使用HTML Webpack Plugin(我强烈推荐它( - :),它会自动注入,如文档所述:
如果你在webpack的输出中有任何css资源(例如,使用ExtractTextPlugin提取的css),那么这些资产将包含在HTML头中的
<link>
标记中。
答案 1 :(得分:0)
根据我的理解使用装载机:
{
test: /\.less$/,
loaders: ['style', 'css', 'less']
}
通过npm安装css-loader,style-loader和less-loader。 在您的入口点,需要较少的文件,它们将作为样式应用于index.html文件。无需添加任何html标签。