-
Notifications
You must be signed in to change notification settings - Fork 3
/
.webpackrc.js
executable file
·82 lines (77 loc) · 1.77 KB
/
.webpackrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import fs from 'fs'
import path from 'path'
import { proxy } from './mock/utils'
import isString from 'lodash/isString'
const methodFilter = method => (pathname, req) => {
return method ? req.method === method : true;
}
const parseMocks = (mocks) => {
if (!mocks) {
return {}
}
return mocks.reduce((acc, [key, value]) => {
let [method, uri] = key.split(/\s+/)
if (!uri) {
uri = method
method = null
}
const { target } = value
acc[uri] = isString(target)
? {
target,
changeOrigin: true,
}
: {
changeOrigin: true,
...target,
}
return acc
}, {})
}
const proxyMock = fs.readdirSync(path.join(__dirname + '/mock'))
.filter(file => file !== 'utils.js' && file.endsWith('.js'))
.reduce((acc, file) => {
const module = require('./mock/' + file)
let mocks = (module.default || module)
for (const key in mocks) {
if (proxy.is(mocks[key])) {
acc.push([key, mocks[key]])
}
}
return acc
}, [])
const proxyObject = parseMocks(proxyMock)
// console.log('所有代理接口:')
// console.log(Object.keys(proxyMock))
export default {
proxy: proxyObject,
entry: 'src/index.js',
extraBabelPlugins: [
['module-resolver', {
'alias': {
'src': './src'
}
}],
'transform-decorators-legacy',
['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]
],
env: {
development: {
extraBabelPlugins: [
'dva-hmr'
],
devtool: 'cheap-module-eval-source-map'
},
// production: {
// devtool: 'source-map'
// }
},
ignoreMomentLocale: true,
theme: './src/theme.js',
html: {
template: './src/index.ejs'
},
publicPath: '/',
disableDynamicImport: false,
hash: true
}