From cc069d18a49cb26f81f3dd84ce5dd93c007759a5 Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 20 Dec 2017 11:43:32 +0800 Subject: [PATCH] refactor router --- .babelrc | 6 ++---- package.json | 6 +++--- src/router/_import_development.js | 1 - src/router/_import_production.js | 1 - src/router/index.js | 14 +++++++------- 5 files changed, 12 insertions(+), 16 deletions(-) delete mode 100644 src/router/_import_development.js delete mode 100644 src/router/_import_production.js diff --git a/.babelrc b/.babelrc index b884d8a..26c173e 100644 --- a/.babelrc +++ b/.babelrc @@ -8,12 +8,10 @@ }], "stage-2" ], + "plugins":["transform-vue-jsx", "transform-runtime"], "env": { "development":{ - "plugins": ["transform-vue-jsx", "transform-runtime", "dynamic-import-node"] - }, - "production": { - "plugins": ["transform-vue-jsx", "transform-runtime"] + "plugins": ["dynamic-import-node"] } } } diff --git a/package.json b/package.json index 5980e3d..cc287c6 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "scripts": { "dev": "cross-env BABEL_ENV=development webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", "start": "npm run dev", - "build": "cross-env BABEL_ENV=production node build/build.js", - "build:report": "cross-env BABEL_ENV=production npm_config_report=true node build/build.js", + "build": "node build/build.js", + "build:report": "npm_config_report=true node build/build.js", "lint": "eslint --ext .js,.vue src", "test": "npm run lint" }, @@ -36,7 +36,7 @@ "babel-preset-stage-2": "6.24.1", "chalk": "2.3.0", "copy-webpack-plugin": "4.2.3", - "cross-env": "^5.1.1", + "cross-env": "5.1.1", "css-loader": "0.28.7", "eslint": "4.13.1", "eslint-friendly-formatter": "3.0.0", diff --git a/src/router/_import_development.js b/src/router/_import_development.js deleted file mode 100644 index 7c8b5e6..0000000 --- a/src/router/_import_development.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = file => require('@/views/' + file + '.vue').default // vue-loader at least v13.0.0+ diff --git a/src/router/_import_production.js b/src/router/_import_production.js deleted file mode 100644 index 331acba..0000000 --- a/src/router/_import_production.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = file => () => import('@/views/' + file + '.vue') diff --git a/src/router/index.js b/src/router/index.js index 2b78858..cb5edfe 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,6 +1,6 @@ import Vue from 'vue' import Router from 'vue-router' -const _import = require('./_import_' + process.env.NODE_ENV) + // in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading; // detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading @@ -19,8 +19,8 @@ import Layout from '../views/layout/Layout' } **/ export const constantRouterMap = [ - { path: '/login', component: _import('login/index'), hidden: true }, - { path: '/404', component: _import('404'), hidden: true }, + { path: '/login', component: () => import('@/views/login/index'), hidden: true }, + { path: '/404', component: () => import('@/views/404'), hidden: true }, { path: '/', @@ -30,7 +30,7 @@ export const constantRouterMap = [ hidden: true, children: [{ path: 'dashboard', - component: _import('dashboard/index') + component: () => import('@/views/dashboard/index') }] }, @@ -44,13 +44,13 @@ export const constantRouterMap = [ { path: 'table', name: 'Table', - component: _import('table/index'), + component: () => import('@/views/table/index'), meta: { title: 'Table', icon: 'table' } }, { path: 'tree', name: 'Tree', - component: _import('tree/index'), + component: () => import('@/views/tree/index'), meta: { title: 'Tree', icon: 'tree' } } ] @@ -63,7 +63,7 @@ export const constantRouterMap = [ { path: 'index', name: 'Form', - component: _import('form/index'), + component: () => import('@/views/form/index'), meta: { title: 'Form', icon: 'form' } } ]