Skip to content

Instantly share code, notes, and snippets.

@ScriptedAlchemy
Last active November 28, 2019 04:22
Show Gist options
  • Select an option

  • Save ScriptedAlchemy/befc896e358d912487cadeb91e0d1300 to your computer and use it in GitHub Desktop.

Select an option

Save ScriptedAlchemy/befc896e358d912487cadeb91e0d1300 to your computer and use it in GitHub Desktop.
Modifying tree-shaking module by module
if (moduleSource?.indexOf('externalize') > -1 || false) {
module.buildMeta = mergeDeep(module.buildMeta, { isExternalized: true });
// add exports back to usedExports, prevents tree shaking on module
Object.assign(module, { usedExports: module?.buildMeta?.providedExports || true });
try {
// look at refactoring this to use buildMeta not mutate id
module.id = moduleSource.match(/\/\*\s*externalize\s*:\s*(\S+)\s*\*\//)[1];
externalModules[module.id] = {};
} catch (error) {
throw new Error('external-import', error.message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment