Vue模块异步加载探索

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

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)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,798评论 19 139
  • GitChat技术杂谈 前言 本文较长,为了节省你的阅读时间,在文前列写作思路如下: 什么是 webpack,它要...
    萧玄辞阅读 14,336评论 7 110
  • webpack 介绍 webpack 是什么 为什么引入新的打包工具 webpack 核心思想 webpack 安...
    yxsGert阅读 11,552评论 2 71
  • 版权声明:本文为博主原创文章,未经博主允许不得转载。 webpack介绍和使用 一、webpack介绍 1、由来 ...
    it筱竹阅读 13,850评论 0 21
  • 我以为在泥泞路上遇上的风景是意外恩赐,我以为花儿开了就不会枯萎,我以为我的努力能换来上天的宽待,我以为我付出的善良...
    在冬天梦醒阅读 1,215评论 0 0