Skip to content

Commit 9596a4f

Browse files
authored
Merge pull request webpack#6038 from webpack/refactoring/plugin-system-all
Refactoring plugin system all
2 parents 8b08512 + e054999 commit 9596a4f

51 files changed

Lines changed: 952 additions & 771 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/code-splitted-css-bundle/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ body {
7272
## Uncompressed
7373

7474
```
75-
Hash: eb83e18f883b3782ac4e
75+
Hash: 07cd62e8204ce12e5e90
7676
Version: webpack next
7777
Asset Size Chunks Chunk Names
7878
ce21cbdd9b894e6af794813eb3fdaf60.png 119 bytes [emitted]
@@ -112,7 +112,7 @@ Child extract-text-webpack-plugin ../../node_modules/extract-text-webpack-plugin
112112
## Minimized (uglify-js, no zip)
113113

114114
```
115-
Hash: 3d67c808fc684d446a10
115+
Hash: 875c8c7227c51a7a972d
116116
Version: webpack next
117117
Asset Size Chunks Chunk Names
118118
ce21cbdd9b894e6af794813eb3fdaf60.png 119 bytes [emitted]

examples/externals/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = {
5858
var a = typeof exports === 'object' ? factory(require("add"), require("./math")["subtract"]) : factory(root["add"], root["subtract"]);
5959
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
6060
}
61-
})(this, function(__WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__2__) {
61+
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__2__) {
6262
```
6363
<details><summary><code>return /******/ (function(modules) { /* webpackBootstrap */ })</code></summary>
6464
@@ -190,7 +190,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__2__;
190190
Hash: ffa746601696f82316c5
191191
Version: webpack next
192192
Asset Size Chunks Chunk Names
193-
output.js 4.43 KiB 0 [emitted] main
193+
output.js 4.47 KiB 0 [emitted] main
194194
Entrypoint main = output.js
195195
chunk {0} output.js (main) 197 bytes [entry] [rendered]
196196
> main [0] ./example.js
@@ -208,7 +208,7 @@ chunk {0} output.js (main) 197 bytes [entry] [rendered]
208208
Hash: ffa746601696f82316c5
209209
Version: webpack next
210210
Asset Size Chunks Chunk Names
211-
output.js 1.02 KiB 0 [emitted] main
211+
output.js 1.05 KiB 0 [emitted] main
212212
Entrypoint main = output.js
213213
chunk {0} output.js (main) 197 bytes [entry] [rendered]
214214
> main [0] ./example.js

examples/harmony-library/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
exports["MyLibrary"] = factory();
2727
else
2828
root["MyLibrary"] = factory();
29-
})(this, function() {
29+
})(typeof self !== 'undefined' ? self : this, function() {
3030
```
3131
<details><summary><code>return /******/ (function(modules) { /* webpackBootstrap */ })</code></summary>
3232
@@ -140,7 +140,7 @@ function increment() {
140140
Hash: 3644f1adc4c521a71110
141141
Version: webpack next
142142
Asset Size Chunks Chunk Names
143-
MyLibrary.umd.js 3.63 KiB 0 [emitted] main
143+
MyLibrary.umd.js 3.66 KiB 0 [emitted] main
144144
Entrypoint main = MyLibrary.umd.js
145145
chunk {0} MyLibrary.umd.js (main) 97 bytes [entry] [rendered]
146146
> main [0] ./example.js
@@ -155,7 +155,7 @@ chunk {0} MyLibrary.umd.js (main) 97 bytes [entry] [rendered]
155155
Hash: 3644f1adc4c521a71110
156156
Version: webpack next
157157
Asset Size Chunks Chunk Names
158-
MyLibrary.umd.js 922 bytes 0 [emitted] main
158+
MyLibrary.umd.js 952 bytes 0 [emitted] main
159159
Entrypoint main = MyLibrary.umd.js
160160
chunk {0} MyLibrary.umd.js (main) 97 bytes [entry] [rendered]
161161
> main [0] ./example.js

examples/multi-part-library/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343
exports["alpha"] = factory();
4444
else
4545
root["MyLibrary"] = root["MyLibrary"] || {}, root["MyLibrary"]["alpha"] = factory();
46-
})(this, function() {
46+
})(typeof self !== 'undefined' ? self : this, function() {
4747
```
4848
<details><summary><code>return /******/ (function(modules) { /* webpackBootstrap */ })</code></summary>
4949
@@ -152,7 +152,7 @@ module.exports = "alpha";
152152
exports["beta"] = factory();
153153
else
154154
root["MyLibrary"] = root["MyLibrary"] || {}, root["MyLibrary"]["beta"] = factory();
155-
})(this, function() {
155+
})(typeof self !== 'undefined' ? self : this, function() {
156156
return /******/ (function(modules) { // webpackBootstrap
157157
/******/ // The module cache
158158
/******/ var installedModules = {};
@@ -249,8 +249,8 @@ module.exports = "beta";
249249
Hash: 17fa97a0dfa6b745377a
250250
Version: webpack next
251251
Asset Size Chunks Chunk Names
252-
MyLibrary.beta.js 3.24 KiB 0 [emitted] beta
253-
MyLibrary.alpha.js 3.24 KiB 1 [emitted] alpha
252+
MyLibrary.beta.js 3.28 KiB 0 [emitted] beta
253+
MyLibrary.alpha.js 3.27 KiB 1 [emitted] alpha
254254
Entrypoint alpha = MyLibrary.alpha.js
255255
Entrypoint beta = MyLibrary.beta.js
256256
chunk {0} MyLibrary.beta.js (beta) 24 bytes [entry] [rendered]
@@ -269,8 +269,8 @@ chunk {1} MyLibrary.alpha.js (alpha) 25 bytes [entry] [rendered]
269269
Hash: 17fa97a0dfa6b745377a
270270
Version: webpack next
271271
Asset Size Chunks Chunk Names
272-
MyLibrary.beta.js 825 bytes 0 [emitted] beta
273-
MyLibrary.alpha.js 827 bytes 1 [emitted] alpha
272+
MyLibrary.beta.js 855 bytes 0 [emitted] beta
273+
MyLibrary.alpha.js 857 bytes 1 [emitted] alpha
274274
Entrypoint alpha = MyLibrary.alpha.js
275275
Entrypoint beta = MyLibrary.beta.js
276276
chunk {0} MyLibrary.beta.js (beta) 24 bytes [entry] [rendered]

lib/AmdMainTemplatePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AmdMainTemplatePlugin {
2626
).join(", ");
2727

2828
if(this.name) {
29-
const name = mainTemplate.applyPluginsWaterfall("asset-path", this.name, {
29+
const name = mainTemplate.getAssetPath(this.name, {
3030
hash,
3131
chunk
3232
});

lib/ChunkTemplate.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@
66

77
const ConcatSource = require("webpack-sources").ConcatSource;
88
const Template = require("./Template");
9+
const SyncWaterfallHook = require("tapable").SyncWaterfallHook;
10+
const SyncHook = require("tapable").SyncHook;
911

1012
module.exports = class ChunkTemplate extends Template {
1113
constructor(outputOptions) {
1214
super(outputOptions);
15+
this.hooks = {
16+
modules: new SyncWaterfallHook(["source", "chunk", "moduleTemplate", "dependencyTemplates"]),
17+
render: new SyncWaterfallHook(["source", "chunk", "moduleTemplate", "dependencyTemplates"]),
18+
renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
19+
hash: new SyncHook(["hash"]),
20+
hashForChunk: new SyncHook(["hash", "chunk"]),
21+
};
1322
}
1423

1524
getRenderManifest(options) {
@@ -59,10 +68,10 @@ module.exports = class ChunkTemplate extends Template {
5968

6069
renderJavascript(chunk, moduleTemplate, dependencyTemplates) {
6170
const moduleSources = this.renderChunkModules(chunk, m => true, moduleTemplate, dependencyTemplates);
62-
const core = this.applyPluginsWaterfall("modules", moduleSources, chunk, moduleTemplate, dependencyTemplates);
63-
let source = this.applyPluginsWaterfall("render", core, chunk, moduleTemplate, dependencyTemplates);
71+
const core = this.hooks.modules.call(moduleSources, chunk, moduleTemplate, dependencyTemplates);
72+
let source = this.hooks.render.call(core, chunk, moduleTemplate, dependencyTemplates);
6473
if(chunk.hasEntryModule()) {
65-
source = this.applyPluginsWaterfall("render-with-entry", source, chunk);
74+
source = this.hooks.renderWithEntry.call(source, chunk);
6675
}
6776
chunk.rendered = true;
6877
return new ConcatSource(source, ";");
@@ -75,11 +84,11 @@ module.exports = class ChunkTemplate extends Template {
7584
updateHash(hash) {
7685
hash.update("ChunkTemplate");
7786
hash.update("2");
78-
this.applyPlugins("hash", hash);
87+
this.hooks.hash.call(hash);
7988
}
8089

8190
updateHashForChunk(hash, chunk) {
8291
this.updateHash(hash);
83-
this.applyPlugins("hash-for-chunk", hash, chunk);
92+
this.hooks.hashForChunk.call(hash, chunk);
8493
}
8594
};

0 commit comments

Comments
 (0)