doracms项目在测试环境运行成功,在生产环境运行报错:
执行运行命令:
是哪里出问题了?
前端路由:
import Vue from 'vue'
import VueRouter from 'vue-router'
import Meta from 'vue-meta'
import { ArticleList, CmsCase, Article, AdminLogin, UserLoginForm, UserRegForm, UserCenter, UserPwd, UserMessage, UserReplies, SiteMap } from 'create-route'
Vue.use(VueRouter)
Vue.use(Meta)
const scrollBehavior = (to, from, savedPosition) => {
if (savedPosition) {
// savedPosition is only available for popstate navigations.
return savedPosition
} else {
const position = {}
// new navigation.
// scroll to anchor by returning the selector
if (to.hash) {
position.selector = to.hash
}
// check if any matched route config has meta that requires scrolling to top
if (to.matched.some(m => m.meta.scrollToTop)) {
// cords will be used if no selector is provided,
// or if the selector didn't match any element.
position.x = 0
position.y = 0
}
// if the returned position is falsy or an empty object,
// will retain current scroll position.
return position
}
}
export function createRouter() {
const router = new VueRouter({
mode: 'history',
scrollBehavior,
routes: [
{ name: 'index', path: '/home', component: ArticleList, meta: { typeId: 'indexPage', scrollToTop: true } },
{ name: 'index', path: '/page/:current(\\d+)?', component: ArticleList, meta: { typeId: 'indexPage', scrollToTop: true } },
{ name: 'cmscase', path: '/cmscase___:typeId?/:current(\\d+)?', component: CmsCase },
{ name: 'category', path: '/:cate1?___:typeId?/:current(\\d+)?', component: ArticleList, meta: { scrollToTop: true } },
{ name: 'college', path: '/home/college/:name?', component: ArticleList, meta: { scrollToTop: true } },
{ name: 'schoolserve', path: '/home/schoolserve/:name?', component: ArticleList, meta: { scrollToTop: true } },
{ name: 'category', path: '/:cate0/:cate1?___:typeId?/:current(\\d+)?', component: ArticleList, meta: { scrollToTop: true } },
{ name: 'search', path: '/search/:searchkey/:current(\\d+)?', component: ArticleList, meta: { typeId: 'search', scrollToTop: true } },
{ name: 'article', path: '/details/:id', component: Article, meta: { notKeepAlive: true, scrollToTop: true } },
{ name: 'login', path: '/users/login', component: UserLoginForm },
{ name: 'reg', path: '/users/reg', component: UserRegForm },
{ name: 'ucenter', path: '/users/center', component: UserCenter },
{ name: 'upassword', path: '/users/password', component: UserPwd },
{ name: 'umessage', path: '/users/messages', component: UserMessage },
{ name: 'uReplies', path: '/users/replies', component: UserReplies },
{ name: 'adminlogin', path: '/dr-admin', component: AdminLogin, meta: { typeId: 'adminlogin' } },
{ name: 'sitemap', path: '/sitemap.html', component: SiteMap },
{ name: 'tagPage', path: '/tag/:tagName/:current(\\d+)?', component: ArticleList, meta: { typeId: 'tags', scrollToTop: true } }
]
})
return router;
}
前端入口文件:
app.js
import Vue from 'vue'
import App from './index/App.vue'
import { createStore } from './index/store'
import { createRouter } from './index/router'
import { sync } from 'vuex-router-sync'
import * as filters from './filters'
import titleMixin from './mixins'
import ElementUI from 'element-ui'
import Header from './index/components/header'
import Footer from './index/components/Footer'
Object.keys(filters).forEach(key => {
Vue.filter(key, filters[key])
})
Vue.mixin(titleMixin)
Vue.use(ElementUI)
const preFetchComponent = [
Header,
Footer
]
export function createApp() {
const router = createRouter()
const store = createStore()
sync(store, router)
const app = new Vue({
router,
store,
...App
})
return { app, router, store, preFetchComponent }
}
entry-client.js
import Vue from 'vue'
import { createApp } from './app'
import ProgressBar from './index/components/ProgressBar.vue'
import '../node_modules/element-ui/lib/theme-chalk/index.css'
import '../node_modules/element-ui/lib/theme-chalk/display.css';
import '../node_modules/font-awesome/css/font-awesome.min.css'
// 全局的进度条,在组件中可通过 $loading 访问
const loading = Vue.prototype.$loading = new Vue(ProgressBar).$mount()
document.body.appendChild(loading.$el)
const { app, router, store } = createApp()
if (window.__INITIAL_STATE__) {
store.replaceState(window.__INITIAL_STATE__)
}
// 此时异步组件已经加载完成
router.beforeResolve((to, from, next) => {
const matched = router.getMatchedComponents(to)
const prevMatched = router.getMatchedComponents(from)
let diffed = false
const activated = matched.filter((c, i) => diffed || (diffed = prevMatched[i] !== c))
if (!activated.length) {
return next()
}
loading.start()
Promise.all(activated.map(c => {
/**
* 两种情况下执行asyncData:
* 1. 非keep-alive组件每次都需要执行
* 2. keep-alive组件首次执行,执行后添加标志
*/
if (c.asyncData && (!c.asyncDataFetched || to.meta.notKeepAlive)) {
return c.asyncData({
store,
route: to,
isServer: false,
isClient: true
}).then(() => {
c.asyncDataFetched = true
})
}
})).then(() => {
loading.finish()
next()
}).catch(next)
})
router.onReady(() => app.$mount('#app'))
// only https
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator && window.location.hostname !== 'localhost') {
navigator.serviceWorker.register('/service-worker.js')
}
在本地我修改的项目npm run build