You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chainWebpack(config){config.when(nodeEnv!=='development',config=>{config.plugin('ScriptExtHtmlWebpackPlugin').after('html').use('script-ext-html-webpack-plugin',[{// `runtime` must same as runtimeChunk name. default is `runtime`inline: /runtime\..*\.js$/}]).end()})config.optimization.runtimeChunk('single')}
今天重新搭建项目时,看到后台系统vue.config.js中有这样一段代码,不知道是干什么用的,于是搜索一下了解
ScriptExtHtmlWebpackPlugin
ScriptExtHtmlWebpackPlugin是webpack插件,用于在html文件中添加脚本
上面的代码是什么作用呢?
runtimeChunk
所以结论就是,运行时代码通常不会经常变化,并且可以被多个模块共享。通过optimization.runtimeChunk将运行时代码从模块中分离出来,可以减小每个模块的体积,并且在浏览器缓存中保持稳定。
runtimeChunk:'single'
指示webpack将运行时代码提取到一个单独的文件中,但会增加额外的HTTP请求,浏览器每次都需要重新请求它,它的 http 耗时远大于它的执行时间,所以使用ScriptExtHtmlWebpackPlugin将它内联到index.html中The text was updated successfully, but these errors were encountered: