【问题标题】:Write MiniCssExtractPlugin in webpack-chain way以 webpack-chain 方式编写 MiniCssExtractPlugin
【发布时间】:2019-05-06 10:48:23
【问题描述】:

如何在 webpack-chain 中编写如下代码

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
  plugins: [
    new MiniCssExtractPlugin({
      // Options similar to the same options in webpackOptions.output
      // both options are optional
      filename: '[name].css',
      chunkFilename: '[id].css',
    }),
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              // you can specify a publicPath here
              // by default it uses publicPath in webpackOptions.output
              publicPath: '../',
              hmr: process.env.NODE_ENV === 'development',
            },
          },
          'css-loader',
        ],
      },
    ],
  },
};

如果有一点解释会很棒,我认为这会帮助很多人

【问题讨论】:

    标签: webpack webpack-chain


    【解决方案1】:
    config.plugin('css').use(MiniCssExtractPlugin, [{
           filename: '[name].css',
           chunkFilename: '[id].css',
    }])
    config.module.rule('css')
          .test(/\.css$/)
          .use('mini-css')
          .loader(MiniCssExtractPlugin.loader)
          .options({
               publicPath: '../',
               hmr: process.env.NODE_ENV === 'development',
           })
           .end()
           .use('css-loader')
           .loader('css-loader')
    

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2018-10-29
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 1970-01-01
      • 2013-02-09
      • 2011-07-11
      • 1970-01-01
      相关资源
      最近更新 更多