实现方式:
1、webpack method
require.ensure([''], callback, chunkName) ;
2、es6 motehod
import()
import().then()
import(/* webpackChunkName: async-chunk-name */ /* webpackMode: lazy */ modulename)
需要安装bable插件 syntax-dynamic-import,因为import只能出现在页面顶部
具体实现:
第一种、
var component = (resolve) => { import(/* webpackChunkName:'vendor'*/'组件路径').then(module => { resolve(module) }) }
第二种、
var component = (resolve) => { require(['组件路径'], resolve) }
第三种、
var component = (resolve) => { require.ensure([], () =>{ resolve(reauire('组件路径')); }, chunkName) }