Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions actions/build.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,37 @@ export class BuildAction extends AbstractAction {
watchAssetsMode,
);

const includeLibraryAssets = getValueOrDefault<boolean>(
configuration,
'compilerOptions.includeLibraryAssets',
appName,
'includeLibraryAssets',
commandOptions,
);
if (includeLibraryAssets && configuration.projects) {
for (const [projectName, project] of Object.entries(
configuration.projects,
)) {
if (projectName === appName) {
continue;
}
if (
project &&
project.type === 'library' &&
project.compilerOptions &&
Array.isArray(project.compilerOptions.assets) &&
project.compilerOptions.assets.length > 0
) {
this.assetsManager.copyAssets(
configuration,
projectName,
outDir,
watchAssetsMode,
);
}
}
}

const typeCheck = getValueOrDefault<boolean>(
configuration,
'compilerOptions.typeCheck',
Expand Down Expand Up @@ -220,9 +251,8 @@ export class BuildAction extends AbstractAction {
watchMode: boolean,
onSuccess: (() => void) | undefined,
) {
const { WebpackCompiler } = await import(
'../lib/compiler/webpack-compiler'
);
const { WebpackCompiler } =
await import('../lib/compiler/webpack-compiler');
const webpackCompiler = new WebpackCompiler(this.pluginsLoader);

const webpackPath =
Expand Down
9 changes: 9 additions & 0 deletions commands/build.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class BuildCommand extends AbstractCommand {
'Use "preserveWatchOutput" option when using tsc watch mode.',
)
.option('--all', 'Build all projects in a monorepo.')
.option(
'--include-library-assets',
'Also copy assets from library projects when building an app in a monorepo.',
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any chance we could remove this flag and just rely only on the nest-cli configuration?

.description('Build Nest application.')
.action(async (apps: string[], command: Command) => {
const options: Input[] = [];
Expand Down Expand Up @@ -76,6 +80,11 @@ export class BuildCommand extends AbstractCommand {

options.push({ name: 'all', value: !!command.all });

options.push({
name: 'includeLibraryAssets',
value: command.includeLibraryAssets,
});

const inputs: Input[] = apps.map((app) => ({
name: 'app',
value: app,
Expand Down
3 changes: 2 additions & 1 deletion lib/compiler/helpers/get-value-or-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function getValueOrDefault<T = any>(
| 'sourceRoot'
| 'exec'
| 'builder'
| 'typeCheck',
| 'typeCheck'
| 'includeLibraryAssets',
options: Input[] = [],
defaultValue?: T,
): T {
Expand Down
6 changes: 6 additions & 0 deletions lib/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export interface CompilerOptions {
deleteOutDir?: boolean;
manualRestart?: boolean;
builder?: Builder;
/**
* When building an application in a monorepo, also copy assets configured
* for sibling library projects into the application's output directory.
* Disabled by default to preserve backward compatibility.
*/
includeLibraryAssets?: boolean;
}

export interface PluginOptions {
Expand Down
Loading