【问题标题】:webpack bootstrap-loader will emit bootstrap.js but not bootstrap.css file?webpack bootstrap-loader 会发出 bootstrap.js 但不会发出 bootstrap.css 文件?
【发布时间】:2017-10-08 19:00:15
【问题描述】:

简而言之,我正在尝试使用 extract-text-webpack-plugin 输出我的 css 资产。我希望引导加载程序会吐出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'。这意味着我的引导入口点看起来像 entry : {..., bootstrap : 'bootstrap-loader'}

【问题讨论】:

    标签: css twitter-bootstrap webpack sass bootstrap-loader


    【解决方案1】:

    解决方案 - 我将.bootstraprc 中的extractStyles 变量设置为true。我现在可以安心入睡了。

    【讨论】:

      猜你喜欢
      • 2020-02-21
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      相关资源
      最近更新 更多