1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/infrastructure/webpack/src/plugins/make-peer-dependencies-external.ts
Iku-turso 9a4b02becb chore: Consolidate infrastructure of webpack to ts to make it scriptable
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2023-05-03 09:31:24 +03:00

27 lines
872 B
TypeScript

// @ts-ignore
import ExternalModuleFactoryPlugin from "webpack/lib/ExternalModuleFactoryPlugin";
import path from "path";
import { toModuleMatcherRegExp } from "./to-module-matcher-reg-exp/to-module-matcher-reg-exp";
import { readJsonSync } from "fs-extra";
export class MakePeerDependenciesExternalPlugin {
apply(compiler: any) {
compiler.hooks.compile.tap("compile", (params: any) => {
const peerDependencies = getPeerDependencies();
new ExternalModuleFactoryPlugin(
compiler.options.output.library.type,
peerDependencies.map(toModuleMatcherRegExp)
).apply(params.normalModuleFactory);
});
}
}
const getPeerDependencies = () => {
const pathToPackageJson = path.resolve(process.cwd(), "package.json");
const packageJson = readJsonSync(pathToPackageJson);
return Object.keys(packageJson.peerDependencies || {});
};