Skip to content

Commit 368add4

Browse files
authored
feat(webpack): Primarily use contentHash for debug ID hash (#702)
1 parent e00a472 commit 368add4

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/webpack-plugin/src/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ import { v4 as uuidv4 } from "uuid";
1313

1414
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1515
// @ts-ignore webpack is a peer dep
16-
import * as webback4or5 from "webpack";
16+
import * as webpack4or5 from "webpack";
1717

1818
interface BannerPluginCallbackArg {
1919
chunk?: {
2020
hash?: string;
21+
contentHash?: {
22+
javascript?: string;
23+
};
2124
};
2225
}
2326

@@ -33,8 +36,8 @@ function webpackReleaseInjectionPlugin(injectionCode: string): UnpluginOptions {
3336
// @ts-ignore webpack version compatibility shenanigans
3437
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
3538
compiler?.webpack?.BannerPlugin ||
36-
webback4or5?.BannerPlugin ||
37-
webback4or5?.default?.BannerPlugin;
39+
webpack4or5?.BannerPlugin ||
40+
webpack4or5?.default?.BannerPlugin;
3841
compiler.options.plugins = compiler.options.plugins || [];
3942
compiler.options.plugins.push(
4043
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
@@ -74,8 +77,8 @@ function webpackBundleSizeOptimizationsPlugin(
7477
// @ts-ignore webpack version compatibility shenanigans
7578
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
7679
compiler?.webpack?.DefinePlugin ||
77-
webback4or5?.DefinePlugin ||
78-
webback4or5?.default?.DefinePlugin;
80+
webpack4or5?.DefinePlugin ||
81+
webpack4or5?.default?.DefinePlugin;
7982
compiler.options.plugins = compiler.options.plugins || [];
8083
compiler.options.plugins.push(
8184
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
@@ -99,16 +102,17 @@ function webpackDebugIdInjectionPlugin(): UnpluginOptions {
99102
// @ts-ignore webpack version compatibility shenanigans
100103
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
101104
compiler?.webpack?.BannerPlugin ||
102-
webback4or5?.BannerPlugin ||
103-
webback4or5?.default?.BannerPlugin;
105+
webpack4or5?.BannerPlugin ||
106+
webpack4or5?.default?.BannerPlugin;
104107
compiler.options.plugins = compiler.options.plugins || [];
105108
compiler.options.plugins.push(
106109
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
107110
new BannerPlugin({
108111
raw: true,
109112
include: /\.(js|ts|jsx|tsx|mjs|cjs)(\?[^?]*)?(#[^#]*)?$/,
110113
banner: (arg?: BannerPluginCallbackArg) => {
111-
const debugId = arg?.chunk?.hash ? stringToUUID(arg.chunk.hash) : uuidv4();
114+
const hash = arg?.chunk?.contentHash?.javascript ?? arg?.chunk?.hash;
115+
const debugId = hash ? stringToUUID(hash) : uuidv4();
112116
return getDebugIdSnippet(debugId);
113117
},
114118
})
@@ -161,8 +165,8 @@ function webpackModuleMetadataInjectionPlugin(injectionCode: string): UnpluginOp
161165
// @ts-ignore webpack version compatibility shenanigans
162166
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
163167
compiler?.webpack?.BannerPlugin ||
164-
webback4or5?.BannerPlugin ||
165-
webback4or5?.default?.BannerPlugin;
168+
webpack4or5?.BannerPlugin ||
169+
webpack4or5?.default?.BannerPlugin;
166170
compiler.options.plugins = compiler.options.plugins || [];
167171
compiler.options.plugins.push(
168172
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call

0 commit comments

Comments
 (0)