开发过程中,我们经常需要引入大量第三方库,这些库并不需要随时修改或调试,我们可以使用DllPlugin和DllReferencePlugin单独构建它们。 具体使用如下:

const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
    entry: {
        vendor: [
            'axios',
            'vue-i18n',
            'vue-router',
            'vuex'
        ]
    },
    output: {
        path: path.resolve(__dirname, '../static/'),
        filename: '[name].dll.js',
        library: '[name]_library'
    },
    plugins: [
        new webpack.DllPlugin({
            path: path.join(__dirname, 'build', '[name]-manifest.json'),
            name: '[name]_library'
        })
    ]
}

 

执行webpack命令,build目录下即可生成 dll.js 文件和对应的 manifest 文件,使用 DLLReferencePlugin 引入:

plugins: [
    new webpack.DllReferencePlugin({
        context: __dirname,
        manifest: require('./build/vendor-manifest.json')
    })
]

 

相关文章:

  • 2022-12-23
  • 2022-01-13
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2021-09-16
  • 2022-01-18
猜你喜欢
  • 2021-10-20
  • 2022-12-23
  • 2021-07-07
  • 2021-07-10
  • 2022-12-23
  • 2022-02-23
  • 2021-10-21
相关资源
相似解决方案