Skip to content

Commit fa26b79

Browse files
committed
update
2 parents 1d22adb + 81a1452 commit fa26b79

File tree

23 files changed

+247
-149
lines changed

23 files changed

+247
-149
lines changed

.env.development

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,3 @@ ENV = 'development'
33

44
# base api
55
VUE_APP_BASE_API = '/dev-api'
6-
7-
# vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable,
8-
# to control whether the babel-plugin-dynamic-import-node plugin is enabled.
9-
# It only does one thing by converting all import() to require().
10-
# This configuration can significantly increase the speed of hot updates,
11-
# when you have a large number of pages.
12-
# Detail: https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/babel-preset-app/index.js
13-
14-
VUE_CLI_BABEL_TRANSPILE_MODULES = true

babel.config.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
module.exports = {
22
presets: [
3-
'@vue/app'
4-
]
3+
// https://github.com/vuejs/vue-cli/tree/master/packages/@vue/babel-preset-app
4+
'@vue/cli-plugin-babel/preset'
5+
],
6+
'env': {
7+
'development': {
8+
// babel-plugin-dynamic-import-node plugin only does one thing by converting all import() to require().
9+
// This plugin can significantly increase the speed of hot updates, when you have a large number of pages.
10+
// https://panjiachen.github.io/vue-element-admin-site/guide/advanced/lazy-loading.html
11+
'plugins': ['dynamic-import-node']
12+
}
13+
}
514
}

mock/article.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Mock from 'mockjs'
1+
const Mock = require('mockjs')
22

33
const List = []
44
const count = 100
@@ -27,7 +27,7 @@ for (let i = 0; i < count; i++) {
2727
}))
2828
}
2929

30-
export default [
30+
module.exports = [
3131
{
3232
url: '/vue-element-admin/article/list',
3333
type: 'get',

mock/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Mock from 'mockjs'
2-
import { param2Obj } from '../src/utils'
1+
const Mock = require('mockjs')
2+
const { param2Obj } = require('./utils')
33

4-
import user from './user'
5-
import role from './role'
6-
import article from './article'
7-
import search from './remote-search'
4+
const user = require('./user')
5+
const role = require('./role')
6+
const article = require('./article')
7+
const search = require('./remote-search')
88

99
const mocks = [
1010
...user,
@@ -16,7 +16,7 @@ const mocks = [
1616
// for front mock
1717
// please use it cautiously, it will redefine XMLHttpRequest,
1818
// which will cause many of your third-party libraries to be invalidated(like progress event).
19-
export function mockXHR() {
19+
function mockXHR() {
2020
// mock patch
2121
// https://github.com/nuysoft/Mock/issues/300
2222
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
@@ -54,4 +54,7 @@ export function mockXHR() {
5454
}
5555
}
5656

57-
export default mocks
57+
module.exports = {
58+
mocks,
59+
mockXHR
60+
}

mock/mock-server.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const mockDir = path.join(process.cwd(), 'mock')
88

99
function registerRoutes(app) {
1010
let mockLastIndex
11-
const { default: mocks } = require('./index.js')
11+
const { mocks } = require('./index.js')
1212
const mocksForServer = mocks.map(route => {
1313
return responseFake(route.url, route.type, route.response)
1414
})
@@ -44,9 +44,6 @@ const responseFake = (url, type, respond) => {
4444
}
4545

4646
module.exports = app => {
47-
// es6 polyfill
48-
require('@babel/register')
49-
5047
// parse app.body
5148
// https://expressjs.com/en/4x/api.html#req.body
5249
app.use(bodyParser.json())

mock/remote-search.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Mock from 'mockjs'
1+
const Mock = require('mockjs')
22

33
const NameList = []
44
const count = 100
@@ -10,7 +10,7 @@ for (let i = 0; i < count; i++) {
1010
}
1111
NameList.push({ name: 'mock-Pan' })
1212

13-
export default [
13+
module.exports = [
1414
// username search
1515
{
1616
url: '/vue-element-admin/search/user',

mock/role/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Mock from 'mockjs'
2-
import { deepClone } from '../../src/utils/index.js'
3-
import { asyncRoutes, constantRoutes } from './routes.js'
1+
const Mock = require('mockjs')
2+
const { deepClone } = require('../utils')
3+
const { asyncRoutes, constantRoutes } = require('./routes.js')
44

55
const routes = deepClone([...constantRoutes, ...asyncRoutes])
66

@@ -35,7 +35,7 @@ const roles = [
3535
}
3636
]
3737

38-
export default [
38+
module.exports = [
3939
// mock get all routes form server
4040
{
4141
url: '/vue-element-admin/routes',

mock/role/routes.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Just a mock data
22

3-
export const constantRoutes = [
3+
const constantRoutes = [
44
{
55
path: '/redirect',
66
component: 'layout/Layout',
@@ -72,7 +72,7 @@ export const constantRoutes = [
7272
}
7373
]
7474

75-
export const asyncRoutes = [
75+
const asyncRoutes = [
7676
{
7777
path: '/permission',
7878
component: 'layout/Layout',
@@ -523,3 +523,8 @@ export const asyncRoutes = [
523523

524524
{ path: '*', redirect: '/404', hidden: true }
525525
]
526+
527+
module.exports = {
528+
constantRoutes,
529+
asyncRoutes
530+
}

mock/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const users = {
2323
}
2424
}
2525

26-
export default [
26+
module.exports = [
2727
// user login
2828
{
2929
url: '/vue-element-admin/user/login',

mock/utils.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @param {string} url
3+
* @returns {Object}
4+
*/
5+
function param2Obj(url) {
6+
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
7+
if (!search) {
8+
return {}
9+
}
10+
const obj = {}
11+
const searchArr = search.split('&')
12+
searchArr.forEach(v => {
13+
const index = v.indexOf('=')
14+
if (index !== -1) {
15+
const name = v.substring(0, index)
16+
const val = v.substring(index + 1, v.length)
17+
obj[name] = val
18+
}
19+
})
20+
return obj
21+
}
22+
23+
/**
24+
* This is just a simple version of deep copy
25+
* Has a lot of edge cases bug
26+
* If you want to use a perfect deep copy, use lodash's _.cloneDeep
27+
* @param {Object} source
28+
* @returns {Object}
29+
*/
30+
function deepClone(source) {
31+
if (!source && typeof source !== 'object') {
32+
throw new Error('error arguments', 'deepClone')
33+
}
34+
const targetObj = source.constructor === Array ? [] : {}
35+
Object.keys(source).forEach(keys => {
36+
if (source[keys] && typeof source[keys] === 'object') {
37+
targetObj[keys] = deepClone(source[keys])
38+
} else {
39+
targetObj[keys] = source[keys]
40+
}
41+
})
42+
return targetObj
43+
}
44+
45+
module.exports = {
46+
param2Obj,
47+
deepClone
48+
}

0 commit comments

Comments
 (0)