-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.js
34 lines (26 loc) · 709 Bytes
/
webpack.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
const Compiler = require('./Compiler')
/**
*
* @param { Object } options 用户传入的配置
* @returns { Object } parseOptions 经过标准化的配置
*/
webpack._initOptions = function (options) {
const parseOptions = { ...options }
if (typeof options.entry === 'string') {
parseOptions.entry = {
main: options.entry
}
}
parseOptions.cwd = process.cwd()
return parseOptions
}
function webpack(webpackOptions) {
const options = webpack._initOptions(webpackOptions)
const compiler = new Compiler(options)
const { plugins = [] } = options
for (let i = 0; i < plugins.length; i++) {
plugins[i].apply(compiler)
}
return compiler
}
module.exports = webpack