Webpack copy-webpack-plugin运行太早

时间:2018-03-28 15:21:54

标签: webpack

我有一个带有以下插件结构的wepback.config.js文件:

 /**************************************************
 Plugins imported:
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
    const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
    const CopyWebpackPlugin = require('copy-webpack-plugin');
    *********************************************************/

plugins: [
        new HtmlWebpackPlugin({
          inlineSource: '(main.bundle.js)',
          template: './web/leafletReact.html',
          inject: 'body'
        }),
        new webpack.optimize.UglifyJsPlugin({

          // Eliminate comments
             comments: false,

         // Compression specific options
            compress: {
              // remove warnings
                 warnings: false,

              // Drop console statements
                 drop_console: true
            },
         }),
        new HtmlWebpackInlineSourcePlugin(),
        new CopyWebpackPlugin([
                {
                    from: path.join(__dirname, '/build/*.html'),
                    to: path.join(__dirname, '/assets/dist'),
                    toType: 'dir',
                    flatten: true
                }
            ])
    ]

尽管最后列出了CopyWebpackPlugin,但它在HtmlWebpackInlineSourcePlugin完成之前运行。有没有办法强制CopyWebpackPlugin等到所有其他插件都完成?

1 个答案:

答案 0 :(得分:0)

对于有此问题的任何人,请使用FileManagerWebpackPlugin。由于copy-webpack-plugin并不是为了等待构建完成而设计的,因此会出现错误。希望这可以帮助任何有相同问题的人。干杯,辛辣的。