From df415bc61809e1ffd4933c1676139e4442c32865 Mon Sep 17 00:00:00 2001 From: moki-codes Date: Thu, 27 Oct 2022 18:34:49 +0400 Subject: [PATCH] fix: exclude external dependencies from build --- webpack.config.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/webpack.config.js b/webpack.config.js index f6c36ef6..f4295190 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,6 +2,16 @@ const webpack = require('webpack'); const {resolve} = require('path'); const ThreadsPlugin = require('threads-plugin'); +const conditions = [ + (req) => !/^\./.test(req), + (req) => !req.includes('threads-plugin'), +]; + +const filterBy = (predicates) => + (req) => predicates.every((predicate) => predicate(req)); + +const shouldExcludeDependency = filterBy(conditions); + module.exports = [ { mode: 'production', @@ -85,5 +95,14 @@ module.exports = [ }), new ThreadsPlugin(), ], + externals: [ + function (ctx, req, cb) { + if (shouldExcludeDependency(req)) { + return cb(null, 'commonjs ' + req); + } + + return cb(); + }, + ], }, ];