From fe85a17b4e4962590c86b46fe5ce160b99497132 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Sat, 7 Jan 2023 20:45:27 +0100 Subject: [PATCH] Use webpack externals to exclude dependencies (#3036) --- _scripts/webpack.renderer.config.js | 8 ++++---- _scripts/webpack.web.config.js | 18 +++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/_scripts/webpack.renderer.config.js b/_scripts/webpack.renderer.config.js index 8b8ad3c6e4e26..21258d9e4a806 100644 --- a/_scripts/webpack.renderer.config.js +++ b/_scripts/webpack.renderer.config.js @@ -32,6 +32,10 @@ const config = { path: path.join(__dirname, '../dist'), filename: '[name].js', }, + externals: { + // ignore linkedom's unnecessary broken canvas import, as youtubei.js only uses linkedom to generate DASH manifests + canvas: '{}' + }, module: { rules: [ { @@ -122,10 +126,6 @@ const config = { new MiniCssExtractPlugin({ filename: isDevMode ? '[name].css' : '[name].[contenthash].css', chunkFilename: isDevMode ? '[id].css' : '[id].[contenthash].css', - }), - // ignore linkedom's unnecessary broken canvas import, as youtubei.js only uses linkedom to generate DASH manifests - new webpack.IgnorePlugin({ - resourceRegExp: /^canvas$/ }) ], resolve: { diff --git a/_scripts/webpack.web.config.js b/_scripts/webpack.web.config.js index 42ab8dac26a3b..a61bdbc2d1f0e 100644 --- a/_scripts/webpack.web.config.js +++ b/_scripts/webpack.web.config.js @@ -22,9 +22,17 @@ const config = { path: path.join(__dirname, '../dist/web'), filename: '[name].js', }, - externals: { - electron: '{}' - }, + externals: [ + { + electron: '{}' + }, + ({ request }, callback) => { + if (request.startsWith('youtubei.js')) { + return callback(null, '{}') + } + callback() + } + ], module: { rules: [ { @@ -122,10 +130,6 @@ const config = { new MiniCssExtractPlugin({ filename: isDevMode ? '[name].css' : '[name].[contenthash].css', chunkFilename: isDevMode ? '[id].css' : '[id].[contenthash].css', - }), - // ignore all youtubei.js imports, even the ones with paths in them - new webpack.IgnorePlugin({ - resourceRegExp: /^youtubei\.js/ }) ], resolve: {