vuejs为什么按需加载的模块在开发环境下,正常加载,但是,打包后在生产环境下却不能加载?
我在Vue路由设置中想按需加载一个notfound的页面,但是,生产环境下,总是加载不上。
//使用组建模式,引入vue,vue-router,然后调用vue.use(vue-router)
import Vue from 'vue';
import VueRouter from 'vue-router';
//引入路由组件
import Index from '../views/index/index';
import User from '../views/user/user';
// import NotFound from '../views/notfound';
const NotFound = function(r){
return require.ensure([],function(){
return r(require('../views/notfound.vue'));
},'NotFoundChunk')
};
//调用
Vue.use(VueRouter);
//定义路由,每个路由映射一个组件
const routes = [
{
component: Index,
path: '/'
},
{
component: User,
path: '/user/:id'
},
{
component: NotFound,
path: '*'
}
]
//导出路由实例,传入routes。此路由实例可在入口文件里作为配置参数添加在vue实例中,并在vue实例上挂载根元素
export default new VueRouter({
mode: 'history',
routes:routes,//可简写routes
})
这是我的github地址: (https://github.com/webcainiao/learn_vue/tree/master/project1) 我实在搜不到解决的方法了,求解,谢谢
6 回复
会不会是你 webpack.prod.config.js 的问题,output.filename 可以包含目录吗? 这里: filename: ‘static/js/[name].[chunkhash].js’
haha,搞定了,我将/build/webpack.prod.config.js/中引用的‘chunk-manifest-webpack-plugin’相应插件删除之后,就正常了。但是我不太明白怎么回事,我对这个插件的理解是:使用它,能输出一个manifest.json的文件。谁再解释解释呗。