1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/infrastructure/webpack/src/get-node-config.ts
Iku-turso 0c2cc25b5b feat: Make webpack configuration trigger linkable-push
Previously this was done by lens-webpack-build, which is awkward for
build-scripts that watch.

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Mikko Aspiala <mikko.aspiala@gmail.com>
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
2023-06-01 08:57:01 +03:00

81 lines
1.6 KiB
TypeScript

import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
import type { Configuration } from "webpack";
import { MakePeerDependenciesExternalPlugin } from "./plugins/make-peer-dependencies-external";
import { ProtectFromImportingNonDependencies } from "./plugins/protect-from-importing-non-dependencies";
import { LinkablePushPlugin } from "./plugins/linkable-push-plugin";
export type Paths = {
entrypointFilePath: string;
outputDirectory: string;
};
export const getNodeConfig = ({
entrypointFilePath,
outputDirectory,
}: Paths): Configuration => ({
name: entrypointFilePath,
entry: { index: entrypointFilePath },
target: "node",
mode: "production",
performance: {
maxEntrypointSize: 100000,
hints: "error",
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
},
plugins: [
new MakePeerDependenciesExternalPlugin(),
new ProtectFromImportingNonDependencies(),
new ForkTsCheckerPlugin({
typescript: {
mode: "write-dts",
configOverwrite: {
include: [entrypointFilePath],
compilerOptions: {
declaration: true,
declarationDir: outputDirectory,
},
},
},
}),
new LinkablePushPlugin(),
],
output: {
path: outputDirectory,
filename: (pathData) =>
pathData.chunk?.name === "index"
? "index.js"
: `${pathData.chunk?.name}/index.js`,
library: {
type: "commonjs2",
},
},
externalsPresets: { node: true },
node: {
__dirname: true,
__filename: true,
},
module: {
rules: [
{
test: /\.ts(x)?$/,
loader: "ts-loader",
},
],
},
});