Quellcode durchsuchen

refactor router

Pan vor 7 Jahren
Ursprung
Commit
cc069d18a4
5 geänderte Dateien mit 12 neuen und 16 gelöschten Zeilen
  1. 2 4
      .babelrc
  2. 3 3
      package.json
  3. 0 1
      src/router/_import_development.js
  4. 0 1
      src/router/_import_production.js
  5. 7 7
      src/router/index.js

+ 2 - 4
.babelrc

@@ -8,12 +8,10 @@
8 8
     }],
9 9
     "stage-2"
10 10
   ],
11
+  "plugins":["transform-vue-jsx", "transform-runtime"],
11 12
   "env": {
12 13
     "development":{
13
-      "plugins": ["transform-vue-jsx", "transform-runtime", "dynamic-import-node"]
14
-    },
15
-    "production": {
16
-      "plugins": ["transform-vue-jsx", "transform-runtime"]
14
+      "plugins": ["dynamic-import-node"]
17 15
     }
18 16
   }
19 17
 }

+ 3 - 3
package.json

@@ -7,8 +7,8 @@
7 7
   "scripts": {
8 8
     "dev": "cross-env BABEL_ENV=development webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 9
     "start": "npm run dev",
10
-    "build": "cross-env BABEL_ENV=production node build/build.js",
11
-    "build:report": "cross-env BABEL_ENV=production npm_config_report=true node build/build.js",
10
+    "build": "node build/build.js",
11
+    "build:report": "npm_config_report=true node build/build.js",
12 12
     "lint": "eslint --ext .js,.vue src",
13 13
     "test": "npm run lint"
14 14
   },
@@ -36,7 +36,7 @@
36 36
     "babel-preset-stage-2": "6.24.1",
37 37
     "chalk": "2.3.0",
38 38
     "copy-webpack-plugin": "4.2.3",
39
-    "cross-env": "^5.1.1",
39
+    "cross-env": "5.1.1",
40 40
     "css-loader": "0.28.7",
41 41
     "eslint": "4.13.1",
42 42
     "eslint-friendly-formatter": "3.0.0",

+ 0 - 1
src/router/_import_development.js

@@ -1 +0,0 @@
1
-module.exports = file => require('@/views/' + file + '.vue').default // vue-loader at least v13.0.0+

+ 0 - 1
src/router/_import_production.js

@@ -1 +0,0 @@
1
-module.exports = file => () => import('@/views/' + file + '.vue')

+ 7 - 7
src/router/index.js

@@ -1,6 +1,6 @@
1 1
 import Vue from 'vue'
2 2
 import Router from 'vue-router'
3
-const _import = require('./_import_' + process.env.NODE_ENV)
3
+
4 4
 // 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;
5 5
 // detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading
6 6
 
@@ -19,8 +19,8 @@ import Layout from '../views/layout/Layout'
19 19
   }
20 20
 **/
21 21
 export const constantRouterMap = [
22
-  { path: '/login', component: _import('login/index'), hidden: true },
23
-  { path: '/404', component: _import('404'), hidden: true },
22
+  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
23
+  { path: '/404', component: () => import('@/views/404'), hidden: true },
24 24
 
25 25
   {
26 26
     path: '/',
@@ -30,7 +30,7 @@ export const constantRouterMap = [
30 30
     hidden: true,
31 31
     children: [{
32 32
       path: 'dashboard',
33
-      component: _import('dashboard/index')
33
+      component: () => import('@/views/dashboard/index')
34 34
     }]
35 35
   },
36 36
 
@@ -44,13 +44,13 @@ export const constantRouterMap = [
44 44
       {
45 45
         path: 'table',
46 46
         name: 'Table',
47
-        component: _import('table/index'),
47
+        component: () => import('@/views/table/index'),
48 48
         meta: { title: 'Table', icon: 'table' }
49 49
       },
50 50
       {
51 51
         path: 'tree',
52 52
         name: 'Tree',
53
-        component: _import('tree/index'),
53
+        component: () => import('@/views/tree/index'),
54 54
         meta: { title: 'Tree', icon: 'tree' }
55 55
       }
56 56
     ]
@@ -63,7 +63,7 @@ export const constantRouterMap = [
63 63
       {
64 64
         path: 'index',
65 65
         name: 'Form',
66
-        component: _import('form/index'),
66
+        component: () => import('@/views/form/index'),
67 67
         meta: { title: 'Form', icon: 'form' }
68 68
       }
69 69
     ]