chore: use babel-plugin-dynamic-import-node to lazy-loading (#727)
detail see https://panjiachen.github.io/vue-element-admin-site/#/zh-cn/lazy-loading?id=%E8%B7%AF%E7%94%B1%E6%87%92%E5%8A%A0%E8%BD%BD
This commit is contained in:
parent
0375542009
commit
d0f6d3f1f6
7
.babelrc
7
.babelrc
|
@ -8,5 +8,10 @@
|
||||||
}],
|
}],
|
||||||
"stage-2"
|
"stage-2"
|
||||||
],
|
],
|
||||||
"plugins": ["transform-vue-jsx", "transform-runtime"]
|
"plugins": ["transform-vue-jsx", "transform-runtime"],
|
||||||
|
"env": {
|
||||||
|
"development":{
|
||||||
|
"plugins": ["dynamic-import-node"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"author": "Pan <panfree23@gmail.com>",
|
"author": "Pan <panfree23@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
|
"dev": "cross-env BABEL_ENV=development webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
|
||||||
"build:prod": "cross-env NODE_ENV=production env_config=prod node build/build.js",
|
"build:prod": "cross-env NODE_ENV=production env_config=prod node build/build.js",
|
||||||
"build:sit": "cross-env NODE_ENV=production env_config=sit node build/build.js",
|
"build:sit": "cross-env NODE_ENV=production env_config=sit node build/build.js",
|
||||||
"lint": "eslint --ext .js,.vue src",
|
"lint": "eslint --ext .js,.vue src",
|
||||||
|
@ -61,6 +61,7 @@
|
||||||
"babel-eslint": "8.0.3",
|
"babel-eslint": "8.0.3",
|
||||||
"babel-helper-vue-jsx-merge-props": "2.0.3",
|
"babel-helper-vue-jsx-merge-props": "2.0.3",
|
||||||
"babel-loader": "7.1.2",
|
"babel-loader": "7.1.2",
|
||||||
|
"babel-plugin-dynamic-import-node": "^1.2.0",
|
||||||
"babel-plugin-syntax-jsx": "6.18.0",
|
"babel-plugin-syntax-jsx": "6.18.0",
|
||||||
"babel-plugin-transform-runtime": "6.23.0",
|
"babel-plugin-transform-runtime": "6.23.0",
|
||||||
"babel-plugin-transform-vue-jsx": "3.5.0",
|
"babel-plugin-transform-vue-jsx": "3.5.0",
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Router from 'vue-router'
|
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
|
|
||||||
|
|
||||||
Vue.use(Router)
|
Vue.use(Router)
|
||||||
|
|
||||||
/* Layout */
|
/* Layout */
|
||||||
import Layout from '../views/layout/Layout'
|
import Layout from '@/views/layout/Layout'
|
||||||
|
|
||||||
/** note: submenu only apppear when children.length>=1
|
/** note: submenu only apppear when children.length>=1
|
||||||
* detail see https://panjiachen.github.io/vue-element-admin-site/#/router-and-nav?id=sidebar
|
* detail see https://panjiachen.github.io/vue-element-admin-site/#/router-and-nav?id=sidebar
|
||||||
|
@ -28,17 +25,17 @@ import Layout from '../views/layout/Layout'
|
||||||
}
|
}
|
||||||
**/
|
**/
|
||||||
export const constantRouterMap = [
|
export const constantRouterMap = [
|
||||||
{ path: '/login', component: _import('login/index'), hidden: true },
|
{ path: '/login', component: () => import('@/views/login/index'), hidden: true },
|
||||||
{ path: '/authredirect', component: _import('login/authredirect'), hidden: true },
|
{ path: '/authredirect', component: () => import('@/views/login/authredirect'), hidden: true },
|
||||||
{ path: '/404', component: _import('errorPage/404'), hidden: true },
|
{ path: '/404', component: () => import('@/views/errorPage/404'), hidden: true },
|
||||||
{ path: '/401', component: _import('errorPage/401'), hidden: true },
|
{ path: '/401', component: () => import('@/views/errorPage/401'), hidden: true },
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
redirect: 'dashboard',
|
redirect: 'dashboard',
|
||||||
children: [{
|
children: [{
|
||||||
path: 'dashboard',
|
path: 'dashboard',
|
||||||
component: _import('dashboard/index'),
|
component: () => import('@/views/dashboard/index'),
|
||||||
name: 'dashboard',
|
name: 'dashboard',
|
||||||
meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
|
meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
|
||||||
}]
|
}]
|
||||||
|
@ -49,7 +46,7 @@ export const constantRouterMap = [
|
||||||
redirect: '/documentation/index',
|
redirect: '/documentation/index',
|
||||||
children: [{
|
children: [{
|
||||||
path: 'index',
|
path: 'index',
|
||||||
component: _import('documentation/index'),
|
component: () => import('@/views/documentation/index'),
|
||||||
name: 'documentation',
|
name: 'documentation',
|
||||||
meta: { title: 'documentation', icon: 'documentation', noCache: true }
|
meta: { title: 'documentation', icon: 'documentation', noCache: true }
|
||||||
}]
|
}]
|
||||||
|
@ -60,7 +57,7 @@ export const constantRouterMap = [
|
||||||
redirect: '/guide/index',
|
redirect: '/guide/index',
|
||||||
children: [{
|
children: [{
|
||||||
path: 'index',
|
path: 'index',
|
||||||
component: _import('guide/index'),
|
component: () => import('@/views/guide/index'),
|
||||||
name: 'guide',
|
name: 'guide',
|
||||||
meta: { title: 'guide', icon: 'guide', noCache: true }
|
meta: { title: 'guide', icon: 'guide', noCache: true }
|
||||||
}]
|
}]
|
||||||
|
@ -86,7 +83,7 @@ export const asyncRouterMap = [
|
||||||
},
|
},
|
||||||
children: [{
|
children: [{
|
||||||
path: 'page',
|
path: 'page',
|
||||||
component: _import('permission/page'),
|
component: () => import('@/views/permission/page'),
|
||||||
name: 'pagePermission',
|
name: 'pagePermission',
|
||||||
meta: {
|
meta: {
|
||||||
title: 'pagePermission',
|
title: 'pagePermission',
|
||||||
|
@ -94,7 +91,7 @@ export const asyncRouterMap = [
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
path: 'directive',
|
path: 'directive',
|
||||||
component: _import('permission/directive'),
|
component: () => import('@/views/permission/directive'),
|
||||||
name: 'directivePermission',
|
name: 'directivePermission',
|
||||||
meta: {
|
meta: {
|
||||||
title: 'directivePermission'
|
title: 'directivePermission'
|
||||||
|
@ -108,7 +105,7 @@ export const asyncRouterMap = [
|
||||||
component: Layout,
|
component: Layout,
|
||||||
children: [{
|
children: [{
|
||||||
path: 'index',
|
path: 'index',
|
||||||
component: _import('svg-icons/index'),
|
component: () => import('@/views/svg-icons/index'),
|
||||||
name: 'icons',
|
name: 'icons',
|
||||||
meta: { title: 'icons', icon: 'icon', noCache: true }
|
meta: { title: 'icons', icon: 'icon', noCache: true }
|
||||||
}]
|
}]
|
||||||
|
@ -124,19 +121,19 @@ export const asyncRouterMap = [
|
||||||
icon: 'component'
|
icon: 'component'
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{ path: 'tinymce', component: _import('components-demo/tinymce'), name: 'tinymce-demo', meta: { title: 'tinymce' }},
|
{ path: 'tinymce', component: () => import('@/views/components-demo/tinymce'), name: 'tinymce-demo', meta: { title: 'tinymce' }},
|
||||||
{ path: 'markdown', component: _import('components-demo/markdown'), name: 'markdown-demo', meta: { title: 'markdown' }},
|
{ path: 'markdown', component: () => import('@/views/components-demo/markdown'), name: 'markdown-demo', meta: { title: 'markdown' }},
|
||||||
{ path: 'json-editor', component: _import('components-demo/jsonEditor'), name: 'jsonEditor-demo', meta: { title: 'jsonEditor' }},
|
{ path: 'json-editor', component: () => import('@/views/components-demo/jsonEditor'), name: 'jsonEditor-demo', meta: { title: 'jsonEditor' }},
|
||||||
{ path: 'splitpane', component: _import('components-demo/splitpane'), name: 'splitpane-demo', meta: { title: 'splitPane' }},
|
{ path: 'splitpane', component: () => import('@/views/components-demo/splitpane'), name: 'splitpane-demo', meta: { title: 'splitPane' }},
|
||||||
{ path: 'avatar-upload', component: _import('components-demo/avatarUpload'), name: 'avatarUpload-demo', meta: { title: 'avatarUpload' }},
|
{ path: 'avatar-upload', component: () => import('@/views/components-demo/avatarUpload'), name: 'avatarUpload-demo', meta: { title: 'avatarUpload' }},
|
||||||
{ path: 'dropzone', component: _import('components-demo/dropzone'), name: 'dropzone-demo', meta: { title: 'dropzone' }},
|
{ path: 'dropzone', component: () => import('@/views/components-demo/dropzone'), name: 'dropzone-demo', meta: { title: 'dropzone' }},
|
||||||
{ path: 'sticky', component: _import('components-demo/sticky'), name: 'sticky-demo', meta: { title: 'sticky' }},
|
{ path: 'sticky', component: () => import('@/views/components-demo/sticky'), name: 'sticky-demo', meta: { title: 'sticky' }},
|
||||||
{ path: 'count-to', component: _import('components-demo/countTo'), name: 'countTo-demo', meta: { title: 'countTo' }},
|
{ path: 'count-to', component: () => import('@/views/components-demo/countTo'), name: 'countTo-demo', meta: { title: 'countTo' }},
|
||||||
{ path: 'mixin', component: _import('components-demo/mixin'), name: 'componentMixin-demo', meta: { title: 'componentMixin' }},
|
{ path: 'mixin', component: () => import('@/views/components-demo/mixin'), name: 'componentMixin-demo', meta: { title: 'componentMixin' }},
|
||||||
{ path: 'back-to-top', component: _import('components-demo/backToTop'), name: 'backToTop-demo', meta: { title: 'backToTop' }},
|
{ path: 'back-to-top', component: () => import('@/views/components-demo/backToTop'), name: 'backToTop-demo', meta: { title: 'backToTop' }},
|
||||||
{ path: 'drag-dialog', component: _import('components-demo/dragDialog'), name: 'dragDialog-demo', meta: { title: 'dragDialog' }},
|
{ path: 'drag-dialog', component: () => import('@/views/components-demo/dragDialog'), name: 'dragDialog-demo', meta: { title: 'dragDialog' }},
|
||||||
{ path: 'dnd-list', component: _import('components-demo/dndList'), name: 'dndList-demo', meta: { title: 'dndList' }},
|
{ path: 'dnd-list', component: () => import('@/views/components-demo/dndList'), name: 'dndList-demo', meta: { title: 'dndList' }},
|
||||||
{ path: 'drag-kanban', component: _import('components-demo/dragKanban'), name: 'dragKanban-demo', meta: { title: 'dragKanban' }}
|
{ path: 'drag-kanban', component: () => import('@/views/components-demo/dragKanban'), name: 'dragKanban-demo', meta: { title: 'dragKanban' }}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -150,9 +147,9 @@ export const asyncRouterMap = [
|
||||||
icon: 'chart'
|
icon: 'chart'
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{ path: 'keyboard', component: _import('charts/keyboard'), name: 'keyboardChart', meta: { title: 'keyboardChart', noCache: true }},
|
{ path: 'keyboard', component: () => import('@/views/charts/keyboard'), name: 'keyboardChart', meta: { title: 'keyboardChart', noCache: true }},
|
||||||
{ path: 'line', component: _import('charts/line'), name: 'lineChart', meta: { title: 'lineChart', noCache: true }},
|
{ path: 'line', component: () => import('@/views/charts/line'), name: 'lineChart', meta: { title: 'lineChart', noCache: true }},
|
||||||
{ path: 'mixchart', component: _import('charts/mixChart'), name: 'mixChart', meta: { title: 'mixChart', noCache: true }}
|
{ path: 'mixchart', component: () => import('@/views/charts/mixChart'), name: 'mixChart', meta: { title: 'mixChart', noCache: true }}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -161,7 +158,7 @@ export const asyncRouterMap = [
|
||||||
component: Layout,
|
component: Layout,
|
||||||
children: [{
|
children: [{
|
||||||
path: 'index',
|
path: 'index',
|
||||||
component: _import('tab/index'),
|
component: () => import('@/views/tab/index'),
|
||||||
name: 'tab',
|
name: 'tab',
|
||||||
meta: { title: 'tab', icon: 'tab' }
|
meta: { title: 'tab', icon: 'tab' }
|
||||||
}]
|
}]
|
||||||
|
@ -177,12 +174,12 @@ export const asyncRouterMap = [
|
||||||
icon: 'table'
|
icon: 'table'
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{ path: 'dynamic-table', component: _import('table/dynamicTable/index'), name: 'dynamicTable', meta: { title: 'dynamicTable' }},
|
{ path: 'dynamic-table', component: () => import('@/views/table/dynamicTable/index'), name: 'dynamicTable', meta: { title: 'dynamicTable' }},
|
||||||
{ path: 'drag-table', component: _import('table/dragTable'), name: 'dragTable', meta: { title: 'dragTable' }},
|
{ path: 'drag-table', component: () => import('@/views/table/dragTable'), name: 'dragTable', meta: { title: 'dragTable' }},
|
||||||
{ path: 'inline-edit-table', component: _import('table/inlineEditTable'), name: 'inlineEditTable', meta: { title: 'inlineEditTable' }},
|
{ path: 'inline-edit-table', component: () => import('@/views/table/inlineEditTable'), name: 'inlineEditTable', meta: { title: 'inlineEditTable' }},
|
||||||
{ path: 'tree-table', component: _import('table/treeTable/treeTable'), name: 'treeTableDemo', meta: { title: 'treeTable' }},
|
{ path: 'tree-table', component: () => import('@/views/table/treeTable/treeTable'), name: 'treeTableDemo', meta: { title: 'treeTable' }},
|
||||||
{ path: 'custom-tree-table', component: _import('table/treeTable/customTreeTable'), name: 'customTreeTableDemo', meta: { title: 'customTreeTable' }},
|
{ path: 'custom-tree-table', component: () => import('@/views/table/treeTable/customTreeTable'), name: 'customTreeTableDemo', meta: { title: 'customTreeTable' }},
|
||||||
{ path: 'complex-table', component: _import('table/complexTable'), name: 'complexTable', meta: { title: 'complexTable' }}
|
{ path: 'complex-table', component: () => import('@/views/table/complexTable'), name: 'complexTable', meta: { title: 'complexTable' }}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -196,9 +193,9 @@ export const asyncRouterMap = [
|
||||||
icon: 'example'
|
icon: 'example'
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{ path: 'create', component: _import('example/create'), name: 'createArticle', meta: { title: 'createArticle', icon: 'edit' }},
|
{ path: 'create', component: () => import('@/views/example/create'), name: 'createArticle', meta: { title: 'createArticle', icon: 'edit' }},
|
||||||
{ path: 'edit/:id(\\d+)', component: _import('example/edit'), name: 'editArticle', meta: { title: 'editArticle', noCache: true }, hidden: true },
|
{ path: 'edit/:id(\\d+)', component: () => import('@/views/example/edit'), name: 'editArticle', meta: { title: 'editArticle', noCache: true }, hidden: true },
|
||||||
{ path: 'list', component: _import('example/list'), name: 'articleList', meta: { title: 'articleList', icon: 'list' }}
|
{ path: 'list', component: () => import('@/views/example/list'), name: 'articleList', meta: { title: 'articleList', icon: 'list' }}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -212,8 +209,8 @@ export const asyncRouterMap = [
|
||||||
icon: '404'
|
icon: '404'
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{ path: '401', component: _import('errorPage/401'), name: 'page401', meta: { title: 'page401', noCache: true }},
|
{ path: '401', component: () => import('@/views/errorPage/401'), name: 'page401', meta: { title: 'page401', noCache: true }},
|
||||||
{ path: '404', component: _import('errorPage/404'), name: 'page404', meta: { title: 'page404', noCache: true }}
|
{ path: '404', component: () => import('@/views/errorPage/404'), name: 'page404', meta: { title: 'page404', noCache: true }}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -221,7 +218,7 @@ export const asyncRouterMap = [
|
||||||
path: '/error-log',
|
path: '/error-log',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
redirect: 'noredirect',
|
redirect: 'noredirect',
|
||||||
children: [{ path: 'log', component: _import('errorLog/index'), name: 'errorLog', meta: { title: 'errorLog', icon: 'bug' }}]
|
children: [{ path: 'log', component: () => import('@/views/errorLog/index'), name: 'errorLog', meta: { title: 'errorLog', icon: 'bug' }}]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -234,9 +231,9 @@ export const asyncRouterMap = [
|
||||||
icon: 'excel'
|
icon: 'excel'
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{ path: 'export-excel', component: _import('excel/exportExcel'), name: 'exportExcel', meta: { title: 'exportExcel' }},
|
{ path: 'export-excel', component: () => import('@/views/excel/exportExcel'), name: 'exportExcel', meta: { title: 'exportExcel' }},
|
||||||
{ path: 'export-selected-excel', component: _import('excel/selectExcel'), name: 'selectExcel', meta: { title: 'selectExcel' }},
|
{ path: 'export-selected-excel', component: () => import('@/views/excel/selectExcel'), name: 'selectExcel', meta: { title: 'selectExcel' }},
|
||||||
{ path: 'upload-excel', component: _import('excel/uploadExcel'), name: 'uploadExcel', meta: { title: 'uploadExcel' }}
|
{ path: 'upload-excel', component: () => import('@/views/excel/uploadExcel'), name: 'uploadExcel', meta: { title: 'uploadExcel' }}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -246,27 +243,27 @@ export const asyncRouterMap = [
|
||||||
redirect: '/zip/download',
|
redirect: '/zip/download',
|
||||||
alwaysShow: true,
|
alwaysShow: true,
|
||||||
meta: { title: 'zip', icon: 'zip' },
|
meta: { title: 'zip', icon: 'zip' },
|
||||||
children: [{ path: 'download', component: _import('zip/index'), name: 'exportZip', meta: { title: 'exportZip' }}]
|
children: [{ path: 'download', component: () => import('@/views/zip/index'), name: 'exportZip', meta: { title: 'exportZip' }}]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
path: '/theme',
|
path: '/theme',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
redirect: 'noredirect',
|
redirect: 'noredirect',
|
||||||
children: [{ path: 'index', component: _import('theme/index'), name: 'theme', meta: { title: 'theme', icon: 'theme' }}]
|
children: [{ path: 'index', component: () => import('@/views/theme/index'), name: 'theme', meta: { title: 'theme', icon: 'theme' }}]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
path: '/clipboard',
|
path: '/clipboard',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
redirect: 'noredirect',
|
redirect: 'noredirect',
|
||||||
children: [{ path: 'index', component: _import('clipboard/index'), name: 'clipboardDemo', meta: { title: 'clipboardDemo', icon: 'clipboard' }}]
|
children: [{ path: 'index', component: () => import('@/views/clipboard/index'), name: 'clipboardDemo', meta: { title: 'clipboardDemo', icon: 'clipboard' }}]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
path: '/i18n',
|
path: '/i18n',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
children: [{ path: 'index', component: _import('i18n-demo/index'), name: 'i18n', meta: { title: 'i18n', icon: 'international' }}]
|
children: [{ path: 'index', component: () => import('@/views/i18n-demo/index'), name: 'i18n', meta: { title: 'i18n', icon: 'international' }}]
|
||||||
},
|
},
|
||||||
|
|
||||||
{ path: '*', redirect: '/404', hidden: true }
|
{ path: '*', redirect: '/404', hidden: true }
|
||||||
|
|
Loading…
Reference in New Issue