Skip to content

Commit 4d2bbfa

Browse files
committed
chore: initial work on webpack 5 integration
1 parent 50434b5 commit 4d2bbfa

File tree

2 files changed

+61
-70
lines changed

2 files changed

+61
-70
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"bugs": "https://github.com/webpack-contrib/mini-css-extract-plugin/issues",
1010
"main": "dist/cjs.js",
1111
"engines": {
12-
"node": ">= 6.9.0"
12+
"node": ">=10.13.0"
1313
},
1414
"scripts": {
1515
"start": "npm run build -- -w",
@@ -36,7 +36,7 @@
3636
"dist"
3737
],
3838
"peerDependencies": {
39-
"webpack": "^4.4.0"
39+
"webpack": "^5.0.0"
4040
},
4141
"dependencies": {
4242
"loader-utils": "^1.1.0",
@@ -72,7 +72,7 @@
7272
"npm-run-all": "^4.1.5",
7373
"prettier": "^1.18.2",
7474
"standard-version": "^6.0.1",
75-
"webpack": "^4.35.3",
75+
"webpack": "^5.0.0-beta.2",
7676
"webpack-cli": "^3.3.6",
7777
"webpack-dev-server": "^3.7.2"
7878
},

src/index.js

Lines changed: 58 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -139,85 +139,76 @@ class MiniCssExtractPlugin {
139139
new CssDependencyTemplate()
140140
);
141141

142-
compilation.mainTemplate.hooks.renderManifest.tap(
143-
pluginName,
144-
(result, { chunk }) => {
145-
const renderedModules = Array.from(chunk.modulesIterable).filter(
146-
(module) => module.type === MODULE_TYPE
147-
);
142+
compilation.hooks.renderManifest.tap(pluginName, (result, { chunk }) => {
143+
const renderedModules = Array.from(chunk.modulesIterable).filter(
144+
(module) => module.type === MODULE_TYPE
145+
);
148146

149-
if (renderedModules.length > 0) {
150-
result.push({
151-
render: () =>
152-
this.renderContentAsset(
153-
compilation,
154-
chunk,
155-
renderedModules,
156-
compilation.runtimeTemplate.requestShortener
157-
),
158-
filenameTemplate: ({ chunk: chunkData }) =>
159-
this.options.moduleFilename(chunkData),
160-
pathOptions: {
147+
if (renderedModules.length > 0) {
148+
result.push({
149+
render: () =>
150+
this.renderContentAsset(
151+
compilation,
161152
chunk,
162-
contentHashType: MODULE_TYPE,
163-
},
164-
identifier: `${pluginName}.${chunk.id}`,
165-
hash: chunk.contentHash[MODULE_TYPE],
166-
});
167-
}
153+
renderedModules,
154+
compilation.runtimeTemplate.requestShortener
155+
),
156+
filenameTemplate: ({ chunk: chunkData }) =>
157+
this.options.moduleFilename(chunkData),
158+
pathOptions: {
159+
chunk,
160+
contentHashType: MODULE_TYPE,
161+
},
162+
identifier: `${pluginName}.${chunk.id}`,
163+
hash: chunk.contentHash[MODULE_TYPE],
164+
});
168165
}
169-
);
166+
});
170167

171-
compilation.chunkTemplate.hooks.renderManifest.tap(
172-
pluginName,
173-
(result, { chunk }) => {
174-
const renderedModules = Array.from(chunk.modulesIterable).filter(
175-
(module) => module.type === MODULE_TYPE
176-
);
168+
compilation.hooks.renderManifest.tap(pluginName, (result, { chunk }) => {
169+
const renderedModules = Array.from(chunk.modulesIterable).filter(
170+
(module) => module.type === MODULE_TYPE
171+
);
177172

178-
if (renderedModules.length > 0) {
179-
result.push({
180-
render: () =>
181-
this.renderContentAsset(
182-
compilation,
183-
chunk,
184-
renderedModules,
185-
compilation.runtimeTemplate.requestShortener
186-
),
187-
filenameTemplate: this.options.chunkFilename,
188-
pathOptions: {
173+
if (renderedModules.length > 0) {
174+
result.push({
175+
render: () =>
176+
this.renderContentAsset(
177+
compilation,
189178
chunk,
190-
contentHashType: MODULE_TYPE,
191-
},
192-
identifier: `${pluginName}.${chunk.id}`,
193-
hash: chunk.contentHash[MODULE_TYPE],
194-
});
195-
}
179+
renderedModules,
180+
compilation.runtimeTemplate.requestShortener
181+
),
182+
filenameTemplate: this.options.chunkFilename,
183+
pathOptions: {
184+
chunk,
185+
contentHashType: MODULE_TYPE,
186+
},
187+
identifier: `${pluginName}.${chunk.id}`,
188+
hash: chunk.contentHash[MODULE_TYPE],
189+
});
196190
}
197-
);
191+
});
198192

199-
compilation.mainTemplate.hooks.hashForChunk.tap(
200-
pluginName,
201-
(hash, chunk) => {
202-
const { chunkFilename } = this.options;
193+
compilation.hooks.chunkHash.tap(pluginName, (hash, chunk) => {
194+
const { chunkFilename } = this.options;
203195

204-
if (REGEXP_CHUNKHASH.test(chunkFilename)) {
205-
hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
206-
}
196+
if (REGEXP_CHUNKHASH.test(chunkFilename)) {
197+
hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
198+
}
207199

208-
if (REGEXP_CONTENTHASH.test(chunkFilename)) {
209-
hash.update(
210-
JSON.stringify(
211-
chunk.getChunkMaps(true).contentHash[MODULE_TYPE] || {}
212-
)
213-
);
214-
}
200+
if (REGEXP_CONTENTHASH.test(chunkFilename)) {
201+
hash.update(
202+
JSON.stringify(
203+
chunk.getChunkMaps(true).contentHash[MODULE_TYPE] || {}
204+
)
205+
);
206+
}
215207

216-
if (REGEXP_NAME.test(chunkFilename)) {
217-
hash.update(JSON.stringify(chunk.getChunkMaps(true).name));
218-
}
208+
if (REGEXP_NAME.test(chunkFilename)) {
209+
hash.update(JSON.stringify(chunk.getChunkMaps(true).name));
219210
}
220-
);
211+
});
221212

222213
compilation.hooks.contentHash.tap(pluginName, (chunk) => {
223214
const { outputOptions } = compilation;

0 commit comments

Comments
 (0)