From 8c634495419b4becc32b83e24c21e36ff720a2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C4=81rlis=20Ga=C5=86=C4=A3is?= Date: Fri, 16 Oct 2020 15:07:37 +0300 Subject: [PATCH] fix: determine webpack peer dependency version (#296) --- src/index.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/index.js b/src/index.js index a5da5e6..7bec930 100644 --- a/src/index.js +++ b/src/index.js @@ -20,27 +20,19 @@ import { let FetchCompileWasmPlugin; let FetchCompileAsyncWasmPlugin; -try { - // Webpack 5, sync WASM +// determine the version of webpack peer dependency +// eslint-disable-next-line global-require, import/no-unresolved +const useWebpack5 = require('webpack/package.json').version.startsWith('5.'); + +if (useWebpack5) { // eslint-disable-next-line global-require, import/no-unresolved FetchCompileWasmPlugin = require('webpack/lib/web/FetchCompileWasmPlugin'); -} catch (ignoreError) { - // Nothing -} - -try { - // Webpack 5, async WASM // eslint-disable-next-line global-require, import/no-unresolved FetchCompileAsyncWasmPlugin = require('webpack/lib/web/FetchCompileAsyncWasmPlugin'); -} catch (ignoreError) { - // Nothing -} - -// Webpack 4 -FetchCompileWasmPlugin = - FetchCompileWasmPlugin || +} else { // eslint-disable-next-line global-require, import/no-unresolved - require('webpack/lib/web/FetchCompileWasmTemplatePlugin'); + FetchCompileWasmPlugin = require('webpack/lib/web/FetchCompileWasmTemplatePlugin'); +} export default function loader() {}