异步按需加载,需要做以下两个操作
1.在webpack.config中,output增加以下配置
output: {
path: config.build.assetsRoot,
publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath,
filename: '[name].js',
chunkFilename:"[name]-[hash:8].js"
}
chunkFilename:"[name]-[hash:8].js"
2.配置router
参考:按需加载
//import Index from './components/Index'
const Index = resolve => require(['./components/Index'], resolve)
//import Draf from './components/Draf'
const Draf = resolve => require(['./components/Draf'], resolve)
//import CreateQues from './components/create/CreateQues'
const CreateQues = resolve => require(['./components/create/CreateQues'], resolve)
//import published from './components/published'
const published = resolve => require(['./components/published'], resolve)
网友评论