可是,這種狀況下一個組件生成一個js文件。
舉例以下:html
{ path: '/promisedemo', name: 'PromiseDemo', component: resolve => require(['../components/PromiseDemo'], resolve) }
vue官方文檔:路由懶加載(使用import())vue
// 下面2行代碼,沒有指定webpackChunkName,每一個組件打包成一個js文件。 const ImportFuncDemo1 = () => import('../components/ImportFuncDemo1') const ImportFuncDemo2 = () => import('../components/ImportFuncDemo2') // 下面2行代碼,指定了相同的webpackChunkName,會合並打包成一個js文件。 // const ImportFuncDemo = () => import(/* webpackChunkName: 'ImportFuncDemo' */ '../components/ImportFuncDemo') // const ImportFuncDemo2 = () => import(/* webpackChunkName: 'ImportFuncDemo' */ '../components/ImportFuncDemo2') export default new Router({ routes: [ { path: '/importfuncdemo1', name: 'ImportFuncDemo1', component: ImportFuncDemo1 }, { path: '/importfuncdemo2', name: 'ImportFuncDemo2', component: ImportFuncDemo2 } ] })
這種狀況下,多個路由指定相同的chunkName,會合並打包成一個js文件。
舉例以下:webpack
{ path: '/promisedemo', name: 'PromiseDemo', component: resolve => require.ensure([], () => resolve(require('../components/PromiseDemo')), 'demo') }, { path: '/hello', name: 'Hello', // component: Hello component: resolve => require.ensure([], () => resolve(require('../components/Hello')), 'demo') }
項目路由配置文件:https://github.com/cag2050/vu...git