Skip to content

Commit 9e11195

Browse files
committed
docs(api): clean up formatting and fix linting errors
1 parent 419f2d0 commit 9e11195

File tree

5 files changed

+125
-87
lines changed

5 files changed

+125
-87
lines changed

src/content/api/compilation.md

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,76 @@ sort: 3
66

77
The Compilation instance extends from the compiler i.e. `compiler.compilation`. It is the literal compilation of all the objects in the require graph. This object has access to all the modules and their dependencies (most of which are circular references). In the compilation phase, modules are loaded, sealed, optimized, chunked, hashed and restored, etc. This would be the main lifecycle of any operations of the compilation.
88

9-
```javascript
9+
``` js
1010
compiler.plugin("compilation", function(compilation) {
11-
//the main compilation instance
12-
//all subsequent methods are derived from compilation.plugin
11+
// the main compilation instance
12+
// all subsequent methods are derived from compilation.plugin
1313
});
1414
```
1515

16+
1617
## `normal-module-loader`
1718

1819
The normal module loader, is the function that actually loads all the modules in the module graph (one-by-one).
1920

20-
```javascript
21+
``` js
2122
compilation.plugin('normal-module-loader', function(loaderContext, module) {
22-
//this is where all the modules are loaded
23-
//one by one, no dependencies are created yet
23+
// this is where all the modules are loaded
24+
// one by one, no dependencies are created yet
2425
});
2526
```
2627

28+
2729
## `seal`
2830

2931
The sealing of the compilation has started.
3032

31-
```javascript
33+
``` js
3234
compilation.plugin('seal', function() {
33-
//you are not accepting any more modules
34-
//no arguments
35+
// you are not accepting any more modules
36+
// no arguments
3537
});
3638
```
3739

40+
3841
## `optimize`
3942

4043
Optimize the compilation.
4144

42-
```javascript
45+
``` js
4346
compilation.plugin('optimize', function() {
44-
//webpack is begining the optimization phase
45-
// no arguments
47+
// webpack is begining the optimization phase
48+
// no arguments
4649
});
4750
```
4851

52+
4953
## `optimize-tree(chunks, modules)` async
5054

5155
Async optimization of the tree.
5256

53-
```javascript
57+
``` js
5458
compilation.plugin('optimize-tree', function(chunks, modules) {
5559

5660
});
5761
```
5862

5963
#### `optimize-modules(modules: Module[])`
64+
6065
Optimize the modules.
61-
```javascript
66+
67+
``` js
6268
compilation.plugin('optimize-modules', function(modules) {
63-
//handle to the modules array during tree optimization
69+
// handle to the modules array during tree optimization
6470
});
6571
```
6672

73+
6774
## `after-optimize-modules(modules: Module[])`
6875

6976
Optimizing the modules has finished.
7077

78+
7179
## `optimize-chunks(chunks: Chunk[])`
7280

7381
Optimize the chunks.
@@ -91,73 +99,89 @@ compilation.plugin('optimize-chunks', function(chunks) {
9199

92100
Optimizing the chunks has finished.
93101

102+
94103
## `revive-modules(modules: Module[], records)`
95104

96105
Restore module info from records.
97106

107+
98108
## `optimize-module-order(modules: Module[])`
99109

100110
Sort the modules in order of importance. The first is the most important module. It will get the smallest id.
101111

112+
102113
## `optimize-module-ids(modules: Module[])`
103114

104115
Optimize the module ids.
105116

117+
106118
## `after-optimize-module-ids(modules: Module[])`
107119

108120
Optimizing the module ids has finished.
109121

122+
110123
## `record-modules(modules: Module[], records)`
111124

112125
Store module info to the records.
113126

127+
114128
## `revive-chunks(chunks: Chunk[], records)`
115129

116130
Restore chunk info from records.
117131

132+
118133
## `optimize-chunk-order(chunks: Chunk[])`
119134

120135
Sort the chunks in order of importance. The first is the most important chunk. It will get the smallest id.
121136

137+
122138
## `optimize-chunk-ids(chunks: Chunk[])`
123139

124140
Optimize the chunk ids.
125141

142+
126143
## `after-optimize-chunk-ids(chunks: Chunk[])`
127144

128145
Optimizing the chunk ids has finished.
129146

147+
130148
## `record-chunks(chunks: Chunk[], records)`
131149

132150
Store chunk info to the records.
133151

152+
134153
## `before-hash`
135154

136155
Before the compilation is hashed.
137156

157+
138158
## `after-hash`
139159

140160
After the compilation is hashed.
141161

162+
142163
## `before-chunk-assets`
143164

144165
Before creating the chunk assets.
145166

167+
146168
## `additional-chunk-assets(chunks: Chunk[])`
147169

148170
Create additional assets for the chunks.
149171

172+
150173
## `record(compilation, records)`
151174

152175
Store info about the compilation to the records
153176

177+
154178
## `additional-assets` async
155179

156180
Create additional assets for the compilation
157181

158182
Here's an example that downloads an image.
159183

160-
```javascript
184+
``` js
161185
compiler.plugin('compilation', function(compilation) {
162186
compilation.plugin('additional-assets', function(callback) {
163187
download('https://img.shields.io/npm/v/webpack.svg', function(resp) {
@@ -172,6 +196,7 @@ compiler.plugin('compilation', function(compilation) {
172196
});
173197
```
174198

199+
175200
## `optimize-chunk-assets(chunks: Chunk[])` async
176201

177202
Optimize the assets for the chunks.
@@ -180,85 +205,92 @@ The assets are stored in `this.assets`, but not all of them are chunk assets. A
180205

181206
Here's an example that simply adds a banner to each chunk.
182207

183-
```javascript
208+
``` js
184209
compilation.plugin("optimize-chunk-assets", function(chunks, callback) {
185-
chunks.forEach(function(chunk) {
186-
chunk.files.forEach(function(file) {
187-
compilation.assets[file] = new ConcatSource("\/**Sweet Banner**\/", "\n", compilation.assets[file]);
188-
});
210+
chunks.forEach(function(chunk) {
211+
chunk.files.forEach(function(file) {
212+
compilation.assets[file] = new ConcatSource("\/**Sweet Banner**\/", "\n", compilation.assets[file]);
189213
});
190-
callback();
214+
});
215+
callback();
191216
});
192217
```
193218

194219
## `after-optimize-chunk-assets(chunks: Chunk[])`
195220

196221
The chunk assets have been optimized. Here's an example plugin from [@boopathi](https://github.com/boopathi) that outputs exactly what went into each chunk.
197222

198-
```javascript
223+
``` js
199224
var PrintChunksPlugin = function() {};
225+
200226
PrintChunksPlugin.prototype.apply = function(compiler) {
201-
compiler.plugin('compilation', function(compilation, params) {
202-
compilation.plugin('after-optimize-chunk-assets', function(chunks) {
203-
console.log(chunks.map(function(c) {
204-
return {
205-
id: c.id,
206-
name: c.name,
207-
includes: c.modules.map(function(m) {
208-
return m.request;
209-
})
210-
};
211-
}));
212-
});
227+
compiler.plugin('compilation', function(compilation, params) {
228+
compilation.plugin('after-optimize-chunk-assets', function(chunks) {
229+
console.log(chunks.map(function(c) {
230+
return {
231+
id: c.id,
232+
name: c.name,
233+
includes: c.modules.map(function(m) {
234+
return m.request;
235+
})
236+
};
237+
}));
213238
});
239+
});
214240
};
215241
```
216242

243+
217244
## `optimize-assets(assets: Object{name: Source})` async
218245

219246
Optimize all assets.
220247

221248
The assets are stored in `this.assets`.
222249

250+
223251
## `after-optimize-assets(assets: Object{name: Source})`
224252

225253
The assets has been optimized.
226254

255+
227256
## `build-module(module)`
228257

229258
Before a module build has started.
230259

231-
```javascript
260+
``` js
232261
compilation.plugin('build-module', function(module){
233-
console.log('build module');
234-
console.log(module);
262+
console.log('About to build: ', module);
235263
});
236264
```
237265

266+
238267
## `succeed-module(module)`
239268

240269
A module has been built successfully.
241-
```javascript
270+
271+
``` js
242272
compilation.plugin('succeed-module', function(module){
243-
console.log('succeed module');
244-
console.log(module);
273+
console.log('Successfully built: ', module);
245274
});
246275
```
247276

277+
248278
## `failed-module(module)`
249279

250280
The module build has failed.
251-
```javascript
281+
282+
``` js
252283
compilation.plugin('failed-module', function(module){
253-
console.log('failed module');
254-
console.log(module);
284+
console.log('Failed to build: ', module);
255285
});
256286
```
257287

288+
258289
## `module-asset(module, filename)`
259290

260291
An asset from a module was added to the compilation.
261292

293+
262294
## `chunk-asset(chunk, filename)`
263295

264296
An asset from a chunk was added to the compilation.

src/content/api/module-factories.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ group: Plugins
44
sort: 5
55
---
66

7+
?> Lead in...
8+
79
## `NormalModuleFactory`
810

9-
### `before-resolve(data)` async waterfall
11+
`before-resolve(data)` async waterfall
1012

1113
Before the factory starts resolving. The `data` object has these properties:
1214

@@ -15,7 +17,7 @@ Before the factory starts resolving. The `data` object has these properties:
1517

1618
Plugins are allowed to modify the object or to pass a new similar object to the callback.
1719

18-
### `after-resolve(data)` async waterfall
20+
`after-resolve(data)` async waterfall
1921

2022
After the factory has resolved the request. The `data` object has these properties:
2123

@@ -26,10 +28,17 @@ After the factory has resolved the request. The `data` object has these properti
2628
* `resource`: The resource. It will be loaded by the NormalModule.
2729
* `parser`: The parser that will be used by the NormalModule.
2830

31+
2932
## `ContextModuleFactory`
3033

31-
### `before-resolve(data)` async waterfall
34+
`before-resolve(data)` async waterfall
35+
36+
?> Add documentation.
37+
38+
`after-resolve(data)` async waterfall
39+
40+
?> Add documentation.
3241

33-
### `after-resolve(data)` async waterfall
42+
`alternatives(options: Array)` async waterfall
3443

35-
### `alternatives(options: Array)` async waterfall
44+
?> Add documentation.

src/content/api/plugins.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Many objects in webpack extend the `Tapable` class, which exposes a `plugin` met
1212

1313
A plugin is installed once as webpack starts up. webpack installs a plugin by calling its `apply` method, and passes a reference to the webpack `compiler` object. You may then call `compiler.plugin` to access asset compilations and their individual build steps. An example would look like this:
1414

15-
```javascript
16-
// MyPlugin.js
15+
__my-plugin.js__
1716

17+
``` js
1818
function MyPlugin(options) {
1919
// Configure your plugin with options...
2020
}
@@ -41,14 +41,17 @@ MyPlugin.prototype.apply = function(compiler) {
4141
module.exports = MyPlugin;
4242
```
4343

44-
Then in `webpack.config.js`
44+
__webpack.config.js__
4545

46-
```javascript
47-
plugins: [
48-
new MyPlugin({options: 'nada'})
49-
]
46+
``` js
47+
plugins: [
48+
new MyPlugin({
49+
options: 'nada'
50+
})
51+
]
5052
```
5153

54+
5255
## Plugin Interfaces
5356

5457
There are two types of plugin interfaces.

0 commit comments

Comments
 (0)