配置 js 代码分割
// 配置 js 代码分割
// 第一种
entry:{
// lodash:'./src/lodash.js' ,
main:'./src/index.js'
},
// 第二种 optimization:{ splitChunks:{ chunks:"all" } }, plugins:[] // 第三种 异步的代码 会自动执行代码分割 不需要单独配置 function getComponent(){ return import('lodash').then(({default:_})=>{ var element = document.createElement('div') element.innerHTML = _.join(['E','r','i','c'],'***') return element }) }
getComponent().then(element=>{ document.body.appendChild(element) })
// 第二种 optimization:{ splitChunks:{ chunks:"all" } }, plugins:[] // 第三种 异步的代码 会自动执行代码分割 不需要单独配置 function getComponent(){ return import('lodash').then(({default:_})=>{ var element = document.createElement('div') element.innerHTML = _.join(['E','r','i','c'],'***') return element }) }
getComponent().then(element=>{ document.body.appendChild(element) })