Skip to content

Commit fcd8418

Browse files
authored
Merge pull request #297 from dma117/rspack-compatibility
Add Rspack compatibility
2 parents be2a8d4 + 6a7eea7 commit fcd8418

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"clean": "rimraf dist",
1818
"prebuild": "yarn clean",
1919
"build": "cross-env NODE_ENV=production babel src -d dist --copy-files",
20-
"test:only": "cross-env NODE_ENV=test jest",
20+
"test:only": "cross-env NODE_ENV=test NODE_OPTIONS=\"--openssl-legacy-provider\" jest",
2121
"test:watch": "yarn test:only --watch",
2222
"test:coverage": "yarn test:only --collectCoverageFrom=\"src/**/*.js\" --coverage",
2323
"pretest": "yarn lint",

src/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,18 @@ class EncodingPlugin {
210210
);
211211

212212
if (this.options.patchWebpackBootstrap) {
213-
['jsonpScript', 'linkPreload'].forEach((id) => {
214-
const hook = compilation.mainTemplate.hooks[id];
213+
const isRspack = compiler.rspack;
214+
215+
const hookNames = isRspack
216+
? ['createScript', 'linkPreload']
217+
: ['jsonpScript', 'linkPreload'];
218+
219+
const hooks = isRspack
220+
? compiler.webpack.RuntimePlugin.getCompilationHooks(compilation)
221+
: compilation.mainTemplate.hooks;
222+
223+
hookNames.forEach((id) => {
224+
const hook = hooks[id];
215225
if (hook) {
216226
hook.tap(pluginName, (s) =>
217227
s.replace(/(["'])utf-8["']/gi, `$1${this.options.encoding}$1`),

0 commit comments

Comments
 (0)