Skip to content

Commit 180556c

Browse files
author
Pavithra K
committed
Adds some info on compiler
1 parent 122e036 commit 180556c

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

content/pluginsapi/compiler.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,67 @@ title: Compiler
33
sort: 2
44
---
55

6-
## Compiler
6+
The `Compiler` module of webpack is the main engine that creates a compilation instance with all the options passed through webpack CLI or `webpack` api or webpack comfiguration file.
7+
8+
It is exported by `webpack` api under `webpack.Compiler`.
9+
10+
The compiler is used by webpack by instantiating it and then calling the `run` method.
11+
12+
[__compiler-examples__](https://github.com/pksjce/webpack-internal-examples/blob/master/compiler-example.js)
13+
14+
```javascript
15+
// Can be imported from webpack package
16+
import {Compiler} from 'webpack';
17+
18+
// Create a new compiler instance
19+
const compiler = new Compiler();
20+
21+
// Populate all required options
22+
compiler.options = {...};
23+
24+
// Creating a plugin.
25+
class LogPlugin {
26+
apply (compiler) {
27+
compiler.plugin('should-emit', compilation => {
28+
console.log('should i emit');
29+
return true;
30+
})
31+
}
32+
}
33+
34+
// Apply the compiler to the plugin
35+
new LogPlugin().apply(compiler);
36+
37+
/* Add other supporting plugins */
38+
39+
// Callback to be executed after run is complete
40+
const callback = () => {
41+
console.log('Compiler has finished execution.')
42+
};
43+
44+
// call run on the compiler along with the callback
45+
compiler.run(callback);
46+
```
47+
48+
?>TODO: Add more explanation of how above code works explaining compiler parts and hooks.
49+
Also tell Tapable is mixed in with Compiler.Differentiate between Compiler's and Tapable's methods
750

851
## Watching
952

53+
?>TODO: Add that compiler duplicates all above functionality and adds watch functionality to it. Highlight differences.
54+
1055
## MultiCompiler
1156

57+
?> Can create child compilers?
58+
1259
## Event Hooks
1360

61+
?>TODO: For each hook follow template of
62+
1. event name
63+
2. reason for event.
64+
3. async or sync or parallel or waterfall
65+
4. some usage examples.
66+
1467
`environment()`
1568

1669
`after-environment()`

0 commit comments

Comments
 (0)