我无法使用webpack将已编译的CSS编译为单个CSS文件

时间:2018-06-23 15:40:23

标签: webpack webpack-2 webpack-style-loader

Нere是我的webpack.config.js:

我运行npm后运行手表

 const MiniCssExtractPlugin = require("mini-css-extract-plugin");
    module.exports = {
      mode: 'production',
      entry: './catalog/view/theme/default/sas/common.scss',
      plugins: [
        new MiniCssExtractPlugin({
          // Options similar to the same options in webpackOptions.output
          // both options are optional
          filename: "./catalog/view/theme/default/stylesheet/stylesheet.css",


        })
      ],
      module: {
        rules: [
          {
            test: /\.scss$/,
            use: [
              MiniCssExtractPlugin.loader,
              {
                loader: "css-loader",
                options: {
                  modules: true,
                  sourceMap: true,
                  importLoader: 2
                }
              },
              'postcss-loader',
              "sass-loader"
            ],
          }
        ]
      }
      ,
      watch: true,
    }

我已经阅读了很多示例,但仍然感到困惑-没有一个是行不通的。

1 个答案:

答案 0 :(得分:0)

已通过添加配置解决了该问题:

 output: {
path: path.resolve(__dirname, "catalog/view/theme/default/css"),

},

我没有注意到带有css的文件已保存到'./src/.../catalog/view/theme/default/sas/common.scss'文件夹中,因此“ output.path”是强制性财产。