mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
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>
27 lines
872 B
TypeScript
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 || {});
|
|
};
|