美文网首页
Vue模块异步加载探索

Vue模块异步加载探索

作者: Nicholasway | 来源:发表于2017-03-10 11:09 被阅读376次

    异步按需加载,需要做以下两个操作

    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)
    
    

    相关文章

      网友评论

          本文标题:Vue模块异步加载探索

          本文链接:https://www.haomeiwen.com/subject/ykungttx.html