使用webpack打包生成的filename: '[name].[chunkhash].js'怎么放到html文件中

plugins: [
        // new CleanWebpackPlugin(['static']),
        new CleanWebpackPlugin(pathsToClean, cleanOptions),

        new webpack.optimize.CommonsChunkPlugin({
            // names: ['jquery','vendor','runtime'],
            // names: ['jquery','echarts','highcharts','vendor'],//跟页面插入的顺序相反
            // names: ['echarts','highcharts','vendor'],
            // names: ['highcharts','vendor'],
            names: ['vendor'],
            minChunks: Infinity
        }),

        new HtmlWebpackPlugin({
            title: 'Output Management',
            //excludeAssets: [/style.*.js/] // exclude style.js or style.[chunkhash].js
        }),
        new HtmlWebpackExcludeAssetsPlugin(),
        new webpack.DefinePlugin({
            'process.env':{
                'NODE_ENV': JSON.stringify('production')
            }
        })


        /*
        new webpack.ProvidePlugin({ // 将 $ 变量挂载到 window 下面,可以在项目中直接使用 $ 不用再引用
            $:"jquery",
            jQuery:"jquery",
            "window.jQuery":"jquery"
        })
        */

    ]
阅读 5.4k
2 个回答

vue-cli的配置

new HtmlWebpackPlugin({
      filename: process.env.NODE_ENV === 'testing'
        ? 'index.html'
        : config.build.index,
      template: 'index.html',
      inject: true,
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
        // more options:
        // https://github.com/kangax/html-minifier#options-quick-reference
      },
      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
      chunksSortMode: 'dependency'
    })

另有一篇文章

在 HtmlWebpackPlugin配置html模板,生成的js就会自动插入到这个模板中。 更详细的可以参考https://github.com/jantimon/h... 官方文档

new HtmlWebpackPlugin({
    title: 'Output Management',
    template: 'template.html'
}),
推荐问题
宣传栏