Files
noodl/packages/noodl-editor/webpackconfigs/helpers/get-externals-modules.js
Michael Cartner b9c60b07dc Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com>
Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com>
Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com>
Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com>
Co-Authored-By: Johan  <4934465+joolsus@users.noreply.github.com>
Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com>
Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
2024-01-26 11:52:55 +01:00

37 lines
1.1 KiB
JavaScript

const fs = require('fs');
const packageJson = require('../../package');
module.exports = function ({ production }) {
//some modules are not packaged in the production build to reduce app size
//make sure webpack bundles those and don't exclude them
//skip this in dev mode since it slows down the bundling
function getExcludedNodeModules() {
return packageJson.build.files
.map((pattern) => pattern.match(/\!node_modules\/(.+)/))
.filter((match) => match !== null)
.map((match) => match[1]);
}
// don't bundle external modules from node_modules
let externals = [];
if (fs.existsSync('node_modules')) {
externals = [...externals, ...fs.readdirSync('node_modules')];
}
// When building normally in a monorepo
if (fs.existsSync('../../node_modules')) {
externals = [...externals, ...fs.readdirSync('../../node_modules')];
}
if (production) {
// ..except these
getExcludedNodeModules().forEach((m) => {
const i = externals.indexOf(m);
if (i !== -1) externals.splice(i, 1);
});
}
return externals;
};