无法将我的应用程序部署到Heroku。错误:clean-webpack-plugin仅接受一个选项对象

时间:2019-07-01 21:13:55

标签: javascript reactjs git heroku webpack

const path = require("path");
const webpackMerge = require("webpack-merge");
const autoprefixer = require("autoprefixer");
const webpackCommon = require("./common.config");

// webpack plugins
const HtmlWebpackPlugin = require("html-webpack-plugin");
const DefinePlugin = require("webpack/lib/DefinePlugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const LoaderOptionsPlugin = require("webpack/lib/LoaderOptionsPlugin");

module.exports = webpackMerge(webpackCommon, {
  bail: true,

  devtool: "source-map",
  mode: "production",
  output: {
    path: path.resolve(__dirname, "../dist"),

    filename: "[name]-[hash].min.js",

    sourceMapFilename: "[name]-[hash].map",

    chunkFilename: "[id]-[chunkhash].js",

    publicPath: "/"
  },

  module: {
    rules: [
      {
        test: /\.s?css$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: [
            {
              loader: "css-loader",
              options: {
                sourceMap: true,
                importLoaders: 2
              }
            },
            {
              loader: "postcss-loader",
              options: {
                config: {
                  path: path.resolve(__dirname, "postcss.config.js")
                },
                sourceMap: true
              }
            },
            {
              loader: "sass-loader",
              options: {
                outputStyle: "expanded",
                sourceMap: true,
                sourceMapContents: true
              }
            }
          ]
        })
      }
    ]
  },

  plugins: [
    new HtmlWebpackPlugin({
      inject: true,
      template: path.resolve(__dirname, "../static/index.html"),
      favicon: path.resolve(__dirname, "../static/favicon.ico"),
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeRedundantAttributes: true,
        useShortDoctype: true,
        removeEmptyAttributes: true,
        removeStyleLinkTypeAttributes: true,
        keepClosingSlash: true,
        minifyJS: true,
        minifyCSS: true,
        minifyURLs: true
      }
    }),
    new CopyWebpackPlugin([{ from: path.resolve(__dirname, "../static") }], {
      ignore: ["index.html", "favicon.ico"]
    }),
    new CleanWebpackPlugin(['dist'], {
      root: path.resolve(__dirname, '..'),
      exclude: '.gitignore'
}),
    new DefinePlugin({
      "process.env": {
        NODE_ENV: '"production"'
      }
    }),
    new ExtractTextPlugin("[name]-[chunkhash].min.css"),
    new UglifyJsPlugin({
      uglifyOptions: {
        compress: {
          ie8: true,
          warnings: false
        },
        mangle: {
          ie8: true
        },
        output: {
          comments: false,
          ie8: true
        }
      },
      sourceMap: true
    }),
    new LoaderOptionsPlugin({
      options: {
        context: "/",
        sassLoader: {
          includePaths: [path.resolve(__dirname, "../src")]
        }
      }
    })
  ]
});

无法将我的应用程序部署到Heroku。错误:clean-webpack-plugin仅接受一个选项对象。有什么想法可以帮助我解决此错误吗?我检查了clean-webpack-plugin文档是否更新了某些部分,但仍然存在相同的错误。

1 个答案:

答案 0 :(得分:0)

看看clean-webpack-plugin可选配置。您的CleanWebpackPlugin抛出此错误:

kind-projector

您是否尝试过将CleanWebpackPlugin选项添加到webpack.config文件中?像这样:

x.mapK(Lambda[Eval ~> IO](IO.eval(_)))

如果其他所有方法均失败,请查看CleanWebpackPlugin的完整选项/默认值。我认为您可以删除[dist]并简单地传入配置对象:https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional

我认为您的这段代码可能有问题。尝试不使用['dist']:

    constructor(options: Options = {}) {
        if (isPlainObject(options) === false) {
          throw new Error(`clean-webpack-plugin 
         // only accepts an options object. See:
         // https://github.com/johnagan/clean- 
         // webpack-plugin#options-and-defaults- 
         // optional`);
        }
    }

我尚未使用过webpack合并,因此我要补充一点,您应该确保已正确安装,安装了正确的依赖项,以及是否存在任何冲突。

注意事项:配置为零时,clean-webpack-plugin将删除您指定的路径目录中的文件。