配置 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)
    })
posted @ 2021-11-26 11:09  13522679763-任国强  阅读(85)  评论(0)    收藏  举报