Skip to content
This repository was archived by the owner on Sep 9, 2021. It is now read-only.

Commit 8c63449

Browse files
authored
fix: determine webpack peer dependency version (#296)
1 parent ae94796 commit 8c63449

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/index.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,19 @@ import {
2020
let FetchCompileWasmPlugin;
2121
let FetchCompileAsyncWasmPlugin;
2222

23-
try {
24-
// Webpack 5, sync WASM
23+
// determine the version of webpack peer dependency
24+
// eslint-disable-next-line global-require, import/no-unresolved
25+
const useWebpack5 = require('webpack/package.json').version.startsWith('5.');
26+
27+
if (useWebpack5) {
2528
// eslint-disable-next-line global-require, import/no-unresolved
2629
FetchCompileWasmPlugin = require('webpack/lib/web/FetchCompileWasmPlugin');
27-
} catch (ignoreError) {
28-
// Nothing
29-
}
30-
31-
try {
32-
// Webpack 5, async WASM
3330
// eslint-disable-next-line global-require, import/no-unresolved
3431
FetchCompileAsyncWasmPlugin = require('webpack/lib/web/FetchCompileAsyncWasmPlugin');
35-
} catch (ignoreError) {
36-
// Nothing
37-
}
38-
39-
// Webpack 4
40-
FetchCompileWasmPlugin =
41-
FetchCompileWasmPlugin ||
32+
} else {
4233
// eslint-disable-next-line global-require, import/no-unresolved
43-
require('webpack/lib/web/FetchCompileWasmTemplatePlugin');
34+
FetchCompileWasmPlugin = require('webpack/lib/web/FetchCompileWasmTemplatePlugin');
35+
}
4436

4537
export default function loader() {}
4638

0 commit comments

Comments
 (0)