Skip to content

Commit deb7c8f

Browse files
committed
feat: forbid set asset config
1 parent 631aa4c commit deb7c8f

3 files changed

Lines changed: 35 additions & 51 deletions

File tree

bin/config.js

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,6 @@ function getPath(folder) {
66
}
77

88
const defaultConfig = {
9-
asset: {
10-
path: 'static/',
11-
src: {
12-
path: 'src/',
13-
js: 'src/static/js',
14-
img: 'src/static/img',
15-
view: 'src/template',
16-
},
17-
build: {
18-
path: 'static/build',
19-
img: 'static/build/img',
20-
view: 'view/build/',
21-
},
22-
dist: {
23-
path: 'static/dist',
24-
js: 'static/dist/js',
25-
css: 'static/dist/css',
26-
img: 'static/dist/img',
27-
view: 'view/dist/',
28-
},
29-
},
309
dev: {
3110
domain: 'piaofang.wepiao.com',
3211
f2e: '127.0.0.1:8000',
@@ -48,37 +27,48 @@ const defaultConfig = {
4827
'/data/sk/101010100.html': 'www.weather.com.cn:80',
4928
'2pmh9.free.natapp.cc': '/ping',
5029
},
30+
// webpack externals
31+
externals: {
32+
react: 'React',
33+
'react-dom': 'ReactDOM',
34+
},
5135
},
5236
}
5337

5438
/* eslint-disable */
5539
const customConfig = require(`${path.resolve(process.cwd(), 'config.js')}`)
56-
const extended = Object.assign({}, defaultConfig, customConfig)
40+
const extended = Object.assign({}, defaultConfig, customConfig || {})
5741
const config = {
5842
asset: {
59-
path: getPath(extended.asset.path),
60-
origin: extended.asset.path,
43+
path: 'static/',
44+
src: {
45+
path: 'src/',
46+
js: 'src/static/js',
47+
img: 'src/static/img',
48+
view: 'src/template',
49+
},
50+
build: {
51+
path: 'static/build',
52+
img: 'static/build/img',
53+
view: 'view/build/',
54+
},
55+
dist: {
56+
path: 'static/dist',
57+
js: 'static/dist/js',
58+
css: 'static/dist/css',
59+
img: 'static/dist/img',
60+
view: 'view/dist/',
61+
},
6162
},
62-
dev: extended.dev
63+
dev: extended.dev,
6364
}
6465

65-
Object.keys(extended.asset).map((key) => {
66-
if (key !== 'path' || key !== 'origin') {
67-
Object.keys(extended.asset[key]).map((subKey) => {
68-
if (!config.asset[key]) {
69-
config.asset[key] = {}
70-
}
71-
72-
config.asset[key][subKey] = getPath(extended.asset[key][subKey])
73-
74-
// webpack needs this original path
75-
if (key === 'build' && subKey === 'path') {
76-
config.asset[key].origin = extended.asset[key][subKey]
77-
}
66+
Object.keys(config.asset).map((key) => {
67+
Object.keys(config.asset[key]).map((subKey) => {
68+
config.asset[key][subKey] = getPath(config.asset[key][subKey])
7869

79-
return subKey
80-
})
81-
}
70+
return subKey
71+
})
8272

8373
return key
8474
})

bin/webpack.dev.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const config = require('./webpack.common')
66
const gonConfig = require('./config')
77

88
const domain = gonConfig.dev.domain
9-
const buildPath = `${gonConfig.asset.origin}${gonConfig.asset.build.origin}`
109

1110
const PATH = config.PATH
1211
const CWD = process.cwd()
@@ -94,7 +93,7 @@ module.exports = {
9493
replacements: [
9594
{
9695
pattern: /\{\{\{(\S*?)\}\}\}/g,
97-
replacement: (match, p1) => `http://${domain}/${buildPath}/${p1}`,
96+
replacement: (match, p1) => `http://${domain}/static/build/${p1}`,
9897
},
9998
],
10099
}),
@@ -115,8 +114,5 @@ module.exports = {
115114
},
116115
}),
117116
],
118-
externals: {
119-
react: 'React',
120-
'react-dom': 'ReactDOM',
121-
},
117+
externals: gonConfig.dev.externals,
122118
}

bin/webpack.pro.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl
55
const ExtractTextPlugin = require('extract-text-webpack-plugin')
66

77
const config = require('./webpack.common')
8+
const gonConfig = require('./config')
89

910
const PATH = config.PATH
1011
const CWD = process.cwd()
@@ -70,8 +71,5 @@ module.exports = {
7071
analyzerMode: 'static',
7172
}),
7273
],
73-
externals: {
74-
react: 'React',
75-
'react-dom': 'ReactDOM',
76-
},
74+
externals: gonConfig.dev.externals,
7775
}

0 commit comments

Comments
 (0)