Skip to content

Commit 608bc70

Browse files
author
Patrik Sletmo
committed
feat: add hook for customizing injected runtime tags
Enable other plugins to tap into the tag injection mechanism in order to customize the functionality of lazy loaded chunks. Closes webpack-contrib#40.
1 parent 1ffc393 commit 608bc70

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

package-lock.json

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"loader-utils": "^1.1.0",
4343
"normalize-url": "1.9.1",
4444
"schema-utils": "^1.0.0",
45+
"tapable": "^1.1.3",
4546
"webpack-sources": "^1.1.0"
4647
},
4748
"devDependencies": {

src/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import webpack from 'webpack';
44
import sources from 'webpack-sources';
55

66
import validateOptions from 'schema-utils';
7+
import { SyncWaterfallHook } from 'tapable';
78

89
import CssDependency from './CssDependency';
910
import schema from './plugin-options.json';
@@ -24,6 +25,8 @@ const REGEXP_NAME = /\[name\]/i;
2425
const REGEXP_PLACEHOLDERS = /\[(name|id|chunkhash)\]/g;
2526
const DEFAULT_FILENAME = '[name].css';
2627

28+
const compilerHookMap = new WeakMap();
29+
2730
class CssDependencyTemplate {
2831
apply() {}
2932
}
@@ -127,6 +130,17 @@ class MiniCssExtractPlugin {
127130
}
128131
}
129132

133+
static getCompilerHooks(compiler) {
134+
let hooks = compilerHookMap.get(compiler);
135+
if (!hooks) {
136+
hooks = {
137+
customize: new SyncWaterfallHook(['source']),
138+
};
139+
compilerHookMap.set(compiler, hooks);
140+
}
141+
return hooks;
142+
}
143+
130144
apply(compiler) {
131145
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
132146
compilation.dependencyFactories.set(
@@ -376,6 +390,9 @@ class MiniCssExtractPlugin {
376390
'}',
377391
])
378392
: '',
393+
MiniCssExtractPlugin.getCompilerHooks(
394+
compiler
395+
).customize.call(''),
379396
'var head = document.getElementsByTagName("head")[0];',
380397
'head.appendChild(linkTag);',
381398
]),

0 commit comments

Comments
 (0)