Skip to content

Commit b3f4a75

Browse files
committed
no message
1 parent bba261a commit b3f4a75

15 files changed

+8674
-0
lines changed

.babelrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"env",
5+
{
6+
"targets": {
7+
"node": "4"
8+
}
9+
}
10+
]
11+
]
12+
}

webpack/.babelrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"env",
5+
{
6+
"targets": {
7+
"node": "4"
8+
}
9+
}
10+
]
11+
]
12+
}

webpack/loaders/ml-loader.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const loaderUtils = require('loader-utils')
2+
const validateOptions = require('schema-utils')
3+
const fs = require('fs')
4+
const path = require('path')
5+
const schema = {
6+
type: 'object',
7+
properties: {
8+
test: {
9+
type: 'string'
10+
}
11+
}
12+
}
13+
module.exports = function (source) {
14+
const options = loaderUtils.getOptions(this)
15+
const callback = this.async()
16+
const msPath = path.resolve('loaders/ms.js')
17+
18+
this.addDependency(msPath)
19+
console.log('options', options)
20+
validateOptions(schema, options, 'Example Loader')
21+
22+
fs.readFile(msPath, 'utf-8', function (err, header) {
23+
if (err) return callback(err)
24+
callback(null, header + "\n" + source);
25+
})
26+
// return source
27+
}
28+
29+
module.exports = function (source) {
30+
const options = loaderUtils.getOptions(this)
31+
source = source.replace(/\[name\]/g, options.name)
32+
return `export default ${JSON.stringify(source)}`
33+
}

webpack/loaders/ms-plugin.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const pluginName = 'ml-plugin';
2+
3+
class mlPlugin {
4+
constructor(option) {
5+
this.option = option
6+
}
7+
8+
apply(compiler) {
9+
compiler.hooks.entryOption.tap(pluginName, (context, entry) => {
10+
console.log('entryOption 在处理来自webpack选项的entry配置后调用。\n')
11+
})
12+
compiler.hooks.afterPlugins.tap(pluginName, compiler => {
13+
console.log('afterPlugins 在设置初始内部插件集之后调用。\n')
14+
})
15+
compiler.hooks.afterResolvers.tap(pluginName, compiler => {
16+
console.log('afterResolvers 解析器设置完成后触发。\n')
17+
})
18+
compiler.hooks.environment.tap(pluginName, compiler => {
19+
console.log('environment 在初始化配置文件中的插件之后,在准备编译器环境时调用。\n')
20+
})
21+
compiler.hooks.afterEnvironment.tap(pluginName, compiler => {
22+
console.log('afterEnvironment environment编译器环境设置完成后,在挂钩之后立即调用。\n')
23+
})
24+
compiler.hooks.beforeRun.tap(pluginName, compiler => {
25+
console.log('beforeRun 在运行编译器之前添加一个挂钩。\n')
26+
})
27+
compiler.hooks.run.tap(pluginName, compiler => {
28+
console.log('run 开始阅读之前,请先钩住编译器records。\n')
29+
})
30+
compiler.hooks.watchRun.tap(pluginName, compiler => {
31+
console.log('watchRun 在触发新的编译之后但实际开始编译之前,在监视模式下执行插件。\n')
32+
})
33+
compiler.hooks.normalModuleFactory.tap(pluginName, normalModuleFactory => {
34+
console.log('normalModuleFactory NormalModuleFactory创建a后调用。\n')
35+
})
36+
compiler.hooks.contextModuleFactory.tap(pluginName, contextModuleFactory => {
37+
console.log('contextModuleFactory ContextModuleFactory创建a后运行插件。\n')
38+
})
39+
compiler.hooks.beforeCompile.tap(pluginName, compilationParams => {
40+
console.log('beforeCompile 创建编译参数后执行插件。\n')
41+
})
42+
compiler.hooks.compile.tap(pluginName, compilationParams => {
43+
console.log('compile beforeCompile在创建新编译之前,在之后立即调用。\n')
44+
})
45+
compiler.hooks.thisCompilation.tap(pluginName, (compilation, compilationParams) => {
46+
console.log('thisCompilation 在初始化编译时执行,恰好在发出compilation事件之前执行。\n')
47+
})
48+
compiler.hooks.compilation.tap(pluginName, (compilation, compilationParams) => {
49+
console.log('compilation 创建编译后运行插件。\n')
50+
})
51+
compiler.hooks.make.tap(pluginName, (compilation) => {
52+
console.log('make 在完成编译之前执行。\n')
53+
})
54+
compiler.hooks.afterCompile.tap(pluginName, (compilation) => {
55+
console.log('afterCompile 在完成并密封编译后调用。\n')
56+
})
57+
compiler.hooks.shouldEmit.tap(pluginName, (compilation) => {
58+
console.log('shouldEmit 在释放资产之前调用。应该返回一个布尔值,告诉是否发出。\n')
59+
return true
60+
})
61+
compiler.hooks.emit.tap(pluginName, (compilation) => {
62+
console.log('emit 在将资产释放到输出目录之前立即执行。\n')
63+
})
64+
compiler.hooks.afterEmit.tap(pluginName, (compilation) => {
65+
console.log('afterEmit 在将资产释放到输出目录后调用。\n')
66+
})
67+
compiler.hooks.assetEmitted.tap(pluginName, (file, info) => {
68+
console.log('assetEmitted 当资产被排放时执行。提供对有关发出的资产的信息的访问,例如其输出路径和字节内容。\n')
69+
})
70+
compiler.hooks.done.tap(pluginName, (stats) => {
71+
console.log('done 编译完成后执行。\n')
72+
})
73+
compiler.hooks.failed.tap(pluginName, (error) => {
74+
console.log('failed 如果编译失败则调用。\n')
75+
})
76+
compiler.hooks.invalid.tap(pluginName, (fileName, changeTime) => {
77+
console.log('invalid 当监视编译无效时执行。\n')
78+
})
79+
compiler.hooks.watchClose.tap(pluginName, () => {
80+
console.log('watchClose 监视编译停止时调用。\n')
81+
})
82+
}
83+
}
84+
85+
module.exports = mlPlugin

webpack/loaders/ms.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('这里是ms')

0 commit comments

Comments
 (0)