Skip to content

Commit

Permalink
feat(webpack): add externals option for nest config
Browse files Browse the repository at this point in the history
  • Loading branch information
jpapini committed Jul 1, 2024
1 parent cada98c commit e52cd4e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-mice-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@jpapini/webpack-config': minor
---

Adding `externals` option for nest config.
5 changes: 3 additions & 2 deletions packages/webpack-config/src/configs/nest-app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Configuration } from 'webpack';
import webpack from 'webpack';
import nodeExternals from 'webpack-node-externals';

import type { IWebpackEnv } from '~/types';
import type { IExternalItem, IWebpackEnv } from '~/types';
import { shorternPath } from '~/utils/find-root.util';
import { mergeConfig } from '~/utils/merge-config.util';

Expand All @@ -22,6 +22,7 @@ export type ICreateNestAppWebpackConfigOptions = {
entryFile?: string;
outputDir?: string;
outputFilename?: string;
externals?: IExternalItem[];
};

export function createNestAppWebpackConfig(
Expand Down Expand Up @@ -50,7 +51,7 @@ export function createNestAppWebpackConfig(
__filename: false,
},
externalsPresets: { node: true },
externals: [nodeExternals()],
externals: [nodeExternals(), ...(options.externals ?? [])],
entry: [entryFile],
output: {
path: outputDir,
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './configs';
export * from './utils/merge-config.util';
6 changes: 6 additions & 0 deletions packages/webpack-config/src/types/external-item.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { ExternalsPlugin } from 'webpack';

// eslint-disable-next-line @typescript-eslint/naming-convention
type GetArrayInnerType<T> = T extends (infer U)[] ? U : never;

export type IExternalItem = GetArrayInnerType<ExternalsPlugin['externals']>;
1 change: 1 addition & 0 deletions packages/webpack-config/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './external-item.type';
export * from './webpack-env.type';

0 comments on commit e52cd4e

Please sign in to comment.