# 一.分析及处理
# 1.bin/mypack.js
#! /usr/bin/env node
//1)需要找到当前执行名的路径 拿到webpack.config.js
let path = require("path")
//config配置文件
let config = require(path.resolve(__dirname))
let Compiler = require("../lib/Complier")
let complier = new complier(config)
//标识运行编译
complier.run()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 2.lib/Complier.js
class Complier {
constructor(config) {
//entry output
this.config = config
//需要保存入口文件的路径
this.entryId
//需要保存所有的模块依赖
this.modules = {}
this.entry = config.entry
this.root = process.cwd()
}
buildModule(modulePath, isEntry) {}
emitFile() {}
run() {
//执行
this.buildModule(path.resolve(this.root, this.entry), true)
this.emitFile()
}
}
module.exports = Complier
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20