Skip to content

Commit 9cf62e3

Browse files
committed
feat: 增加webpack配置项函数与文档更新
1 parent 4fa2cf5 commit 9cf62e3

File tree

10 files changed

+492
-258
lines changed

10 files changed

+492
-258
lines changed

packages/beidou-webpack/README-ZH.md

+134-4
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ module.exports = {
131131
hot: true,
132132
},
133133
};
134+
```
134135

135-
// 配置方案3:
136+
高级自定义配置:
137+
```js
136138
// 更多配置方法,可参看单测用例
137139
module.exports = (app, defaultConfig, dev, target) => {
138140
const factory = app.webpackFactory;
@@ -145,8 +147,8 @@ module.exports = (app, defaultConfig, dev, target) => {
145147
}
146148
})
147149
// 修改默认插件配置
148-
factory.modifyPlugin('CommonsChunkPlugin',
149-
factory.getPlugin('CommonsChunkPlugin'), // 如不修改,可传null
150+
factory.setPlugin('CommonsChunkPlugin',
151+
factory.usePlugin('CommonsChunkPlugin'), // 如不修改,可传null
150152
{
151153
name: 'vendor',
152154
filename: 'manifest.js',
@@ -185,9 +187,137 @@ module.exports = (app, defaultConfig, dev, target) => {
185187
return factory.getConfig(); // 返回配置
186188

187189
};
188-
189190
```
190191

192+
> app.webpackFactory 提供的函数如下:
193+
194+
### 重置配置项: reset(value)
195+
#### Parameters
196+
* [value] {Object}
197+
198+
#### return
199+
* this
200+
201+
### 设置配置项: set(key,value)
202+
#### Parameters
203+
* key {String}
204+
* value {*}
205+
206+
#### return
207+
* this
208+
209+
### 获取配置项: get(key)
210+
#### Parameters
211+
* key {String}
212+
213+
#### return
214+
* {*}
215+
216+
### 获取{param}配置实例: env(param)
217+
#### Parameters
218+
* param {String} 配置实例标识
219+
220+
#### return
221+
* {Object}
222+
223+
### 获取webpack配置: getConfig()
224+
#### Parameters
225+
* key {String}
226+
227+
#### return
228+
* value {*}
229+
230+
231+
### 增加插件配置: addPlugin(params1, params2,params3)
232+
#### Parameters
233+
* params1 {Object|Class|String} 插件实例|构造函数|已定义的插件名
234+
* [params1] {Object} 插件配置项
235+
* [params2] {String} 插件别名
236+
237+
#### return
238+
* this
239+
240+
241+
### getPlugin(params1) 获取插件配置
242+
#### Parameters
243+
* params1 {String|Function} 别名|自定义函数
244+
245+
#### return
246+
* {Object}
247+
248+
### 设置插件配置: setPlugin(params1, params2,params3)
249+
250+
#### Parameter
251+
* params1 {Object|Class} 插件实例|构造函数
252+
* [params1] {Object} 插件配置项
253+
* [params2] {String} 插件别名
254+
255+
#### return
256+
* this
257+
258+
### 定义插件: definePlugin(params1, params2,params3)
259+
#### Parameters
260+
* params1 {Object|Class} 插件实例|构造函数
261+
* [params1] {Object} 插件配置项
262+
* [params2] {String} 插件别名
263+
#### return
264+
* this
265+
266+
### 获取定义的插件: usePlugin(params1)
267+
#### Parameters
268+
* params1 {String} 插件别名
269+
#### return
270+
* {Object}
271+
272+
### 增加配置规则: addRule(params1,params2)
273+
#### Parameters
274+
* params1 {Object} 配置项
275+
* [params2] {String} 别名
276+
#### return
277+
* this
278+
279+
### 设置配置规则: addRule(params1,params2)
280+
#### Parameters
281+
* params1 {Object} 配置项
282+
* [params2] {String} 别名
283+
#### return
284+
* this
285+
286+
### 获取配置规则: getRule(params1)
287+
#### Parameters
288+
* params1 {String|Function} 配置项|自定义函数
289+
#### return
290+
* {Object}
291+
292+
### 定义配置规则: defineRule(params1,params2)
293+
#### Parameters
294+
* params1 {Object} 配置项
295+
* [params2] {String} 别名
296+
#### return
297+
* this
298+
299+
### 获取定义的配置规则: usePlugin(params1)
300+
#### Parameters
301+
* params1 {String} 别名
302+
303+
#### return
304+
* {Object}
305+
306+
### 定义Loader: defineLoader(params1,params2)
307+
#### Parameters
308+
* params1 {String} 别名
309+
* [params2] {String} 路径,默认值为 require.resolve(params1)
310+
#### return
311+
* this
312+
313+
### 获取定义Loader: useLoader(params1)
314+
#### Parameters
315+
* params1 {String} 别名
316+
#### return
317+
* {path}
318+
319+
320+
191321
- **app**: `BeidouApplication` 示例, 通常用来读取应用的全局配置项。
192322

193323
- **defaultConfig**: 插件生成的默认 webpack 配置,可用于覆盖使用。

packages/beidou-webpack/README.md

+139-10
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ module.exports = {
134134
},
135135
};
136136

137-
// Example:
138-
// Please to find more methods in unittest
137+
```
138+
139+
> Advanced custom configuration :
140+
```js
141+
// find more example in unittest, please
139142
module.exports = (app, defaultConfig, dev, target) => {
140143
const factory = app.webpackFactory;
141144
factory.set('output',{
@@ -146,9 +149,9 @@ module.exports = (app, defaultConfig, dev, target) => {
146149
publicPath: '/build/',
147150
}
148151
})
149-
// modify default webpack config
150-
factory.modifyPlugin('CommonsChunkPlugin',
151-
factory.getPlugin('CommonsChunkPlugin'), // if not modify , make sure the value is null
152+
// set default plugin config
153+
factory.setPlugin('CommonsChunkPlugin',
154+
factory.usePlugin('CommonsChunkPlugin'),
152155
{
153156
name: 'vendor',
154157
filename: 'manifest.js',
@@ -162,7 +165,7 @@ module.exports = (app, defaultConfig, dev, target) => {
162165
warnings: false,
163166
}
164167
},
165-
'UglifyJsPlugin' , // if not set , the default value is function name
168+
'UglifyJsPlugin' , // if not pass, use the default value
166169
)
167170

168171
factory.addRule({
@@ -184,14 +187,140 @@ module.exports = (app, defaultConfig, dev, target) => {
184187
},
185188
}))
186189

187-
return factory.getConfig(); // return the new config
188-
// you can return different env value
189-
// return factory.env('prod').getConfig();
190-
// return factoryInProd.getConfig();
190+
return factory.getConfig(); // return the final config for webpack
191191

192192
};
193193
```
194194

195+
> app.webpackFactory methods list:
196+
197+
### reset(value)
198+
#### Parameters
199+
* [value] {Object}
200+
201+
#### return
202+
* this
203+
204+
### set(key,value)
205+
#### Parameters
206+
* key {String}
207+
* value {*}
208+
209+
#### return
210+
* this
211+
212+
### get(key)
213+
#### Parameters
214+
* key {String}
215+
216+
#### return
217+
* {*}
218+
219+
### generate {param} factory for webpack: env(param)
220+
#### Parameters
221+
* param {String} factory flag
222+
223+
#### return
224+
* {Object}
225+
226+
### Get the final config for webpack : getConfig()
227+
#### Parameters
228+
* key {String}
229+
230+
#### return
231+
* value {*}
232+
233+
234+
### addPlugin(params1, params2,params3)
235+
#### Parameters
236+
* params1 {Object|Class|String} 插件实例|构造函数|已定义的插件名
237+
* [params1] {Object} 插件配置项
238+
* [params2] {String} 插件别名
239+
240+
#### return
241+
* this
242+
243+
244+
### getPlugin(params1)
245+
#### Parameters
246+
* params1 {String|Function}
247+
248+
#### return
249+
* {Object}
250+
251+
### 设置插件配置: setPlugin(params1, params2,params3)
252+
253+
#### Parameter
254+
* params1 {Object|Class}
255+
* [params1] {Object}
256+
* [params2] {String}
257+
258+
#### return
259+
* this
260+
261+
### definePlugin(params1, params2,params3)
262+
#### Parameters
263+
* params1 {Object|Class}
264+
* [params1] {Object}
265+
* [params2] {String}
266+
#### return
267+
* this
268+
269+
### usePlugin(params1)
270+
#### Parameters
271+
* params1 {String}
272+
#### return
273+
* {Object}
274+
275+
### addRule(params1,params2)
276+
#### Parameters
277+
* params1 {Object}
278+
* [params2] {String}
279+
#### return
280+
* this
281+
282+
### addRule(params1,params2)
283+
#### Parameters
284+
* params1 {Object}
285+
* [params2] {String}
286+
#### return
287+
* this
288+
289+
### getRule(params1)
290+
#### Parameters
291+
* params1 {String|Function}
292+
#### return
293+
* {Object}
294+
295+
### defineRule(params1,params2)
296+
#### Parameters
297+
* params1 {Object}
298+
* [params2] {String}
299+
#### return
300+
* this
301+
302+
### usePlugin(params1)
303+
#### Parameters
304+
* params1 {String}
305+
306+
#### return
307+
* {Object}
308+
309+
### defineLoader(params1,params2)
310+
#### Parameters
311+
* params1 {String}
312+
* [params2] {String}
313+
#### return
314+
* this
315+
316+
### useLoader(params1)
317+
#### Parameters
318+
* params1 {String}
319+
#### return
320+
* {path}
321+
322+
323+
195324
- **app**: the `BeidouApplication` instance, usually used to access server config.
196325

197326
- **defaultConfig**: default webpack config generated by beidou-webpack.

0 commit comments

Comments
 (0)