Skip to content

Commit

Permalink
fix: exclude external dependencies from build
Browse files Browse the repository at this point in the history
  • Loading branch information
moki committed Oct 28, 2022
1 parent 2539c4f commit df415bc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -85,5 +95,14 @@ module.exports = [
}),
new ThreadsPlugin(),
],
externals: [
function (ctx, req, cb) {
if (shouldExcludeDependency(req)) {
return cb(null, 'commonjs ' + req);
}

return cb();
},
],
},
];

0 comments on commit df415bc

Please sign in to comment.