简而言之,我正在尝试使用 extract-text-webpack-plugin
输出我的 css Assets 。我希望 Bootstrap 加载程序会吐出 bootstrap.css
但事实并非如此。我在想我可能必须在我的 app.js
中添加一个 include 'webpack-loader/path/to/css'
,但有些东西感觉很俗气和反对webpack 的目的。
下面是我可以创建的代表问题的最小 webpack.config.js
。配置假定 webpack.bootstrap.config.js
和 .bootstraprc
文件位于与 webpack.config.js
const path = require("path");
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const bootstrapEntryPoints = require('./webpack.bootstrap.config');
const extractCssPlugin = new ExtractTextPlugin({
filename : '[name].css'
});
module.exports = {
entry : {
app : "./src/js/app.js",
bootstrap : bootstrapEntryPoints.dev
},
output : {
path : path.resolve(__dirname, 'dist'),
filename : "[name].bundle.js"
},
module : {
rules : [
{ test: /\.css$/, use : extractCssPlugin.extract({use : [{loader: "css-loader"}]})},
{ test: /\.(woff2?|svg)$/, loader: 'url-loader?limit=10000' },
{ test: /\.(ttf|eot)$/, loader: 'file-loader' },
]
},
devServer : {
contentBase : path.join(__dirname, "dist"),
hot : true,
},
plugins : [
extractCssPlugin,
],
};
注意事项:
bootstrapEntryPoints.dev
解析为'bootstrap-loader'
。这意味着我的 Bootstrap 入口点看起来像entry : {..., bootstrap : 'bootstrap-loader'}
最佳答案
解决方案 - 我将 .bootstraprc
中的 extractStyles
变量设置为 true
。我现在可以安心休眠了。
关于css - webpack bootstrap-loader 会发出 bootstrap.js 而不是 bootstrap.css 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46634936/