feat(vite): add incremental builds support to Vite plugin build executor (#17433)
Co-authored-by: Katerina Skroumpelou <sk.katherine@gmail.com>
This commit is contained in:
parent
f55241bc7d
commit
a9f8cc61fa
@ -16,6 +16,11 @@
|
||||
"x-completion-type": "directory",
|
||||
"x-priority": "important"
|
||||
},
|
||||
"buildLibsFromSource": {
|
||||
"type": "boolean",
|
||||
"description": "Read buildable libraries from source instead of building them separately.",
|
||||
"default": true
|
||||
},
|
||||
"base": {
|
||||
"type": "string",
|
||||
"description": "Base public path when served in development or production.",
|
||||
|
||||
@ -18,6 +18,11 @@
|
||||
"description": "Target which builds the application. Only used to retrieve the configuration as the dev-server does not build the code.",
|
||||
"x-priority": "important"
|
||||
},
|
||||
"buildLibsFromSource": {
|
||||
"type": "boolean",
|
||||
"description": "Read buildable libraries from source instead of building them separately.",
|
||||
"default": true
|
||||
},
|
||||
"proxyConfig": {
|
||||
"type": "string",
|
||||
"description": "Path to the proxy configuration file.",
|
||||
|
||||
@ -4,6 +4,7 @@ import { build, InlineConfig, mergeConfig } from 'vite';
|
||||
import {
|
||||
getViteBuildOptions,
|
||||
getViteSharedConfig,
|
||||
registerPaths,
|
||||
} from '../../utils/options-utils';
|
||||
import { ViteBuildExecutorOptions } from './schema';
|
||||
import {
|
||||
@ -16,8 +17,6 @@ import { existsSync, writeFileSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import { createAsyncIterable } from '@nx/devkit/src/utils/async-iterable';
|
||||
|
||||
import { registerTsConfigPaths } from '@nx/js/src/internal';
|
||||
|
||||
export async function* viteBuildExecutor(
|
||||
options: ViteBuildExecutorOptions,
|
||||
context: ExecutorContext
|
||||
@ -25,7 +24,7 @@ export async function* viteBuildExecutor(
|
||||
const projectRoot =
|
||||
context.projectsConfigurations.projects[context.projectName].root;
|
||||
|
||||
registerTsConfigPaths(resolve(projectRoot, 'tsconfig.json'));
|
||||
registerPaths(projectRoot, options, context);
|
||||
|
||||
const normalizedOptions = normalizeOptions(options);
|
||||
|
||||
|
||||
@ -18,4 +18,5 @@ export interface ViteBuildExecutorOptions {
|
||||
generatePackageJson?: boolean;
|
||||
includeDevDependenciesInPackageJson?: boolean;
|
||||
cssCodeSplit?: boolean;
|
||||
buildLibsFromSource?: boolean;
|
||||
}
|
||||
|
||||
@ -18,6 +18,11 @@
|
||||
"x-completion-type": "directory",
|
||||
"x-priority": "important"
|
||||
},
|
||||
"buildLibsFromSource": {
|
||||
"type": "boolean",
|
||||
"description": "Read buildable libraries from source instead of building them separately.",
|
||||
"default": true
|
||||
},
|
||||
"base": {
|
||||
"type": "string",
|
||||
"description": "Base public path when served in development or production.",
|
||||
|
||||
@ -7,6 +7,7 @@ import {
|
||||
getNxTargetOptions,
|
||||
getViteServerOptions,
|
||||
getViteBuildOptions,
|
||||
registerPaths,
|
||||
} from '../../utils/options-utils';
|
||||
|
||||
import { ViteDevServerExecutorOptions } from './schema';
|
||||
@ -14,6 +15,11 @@ import { ViteBuildExecutorOptions } from '../build/schema';
|
||||
import { registerTsConfigPaths } from '@nx/js/src/internal';
|
||||
import { resolve } from 'path';
|
||||
|
||||
import {
|
||||
calculateProjectDependencies,
|
||||
createTmpTsConfig,
|
||||
} from '@nx/js/src/utils/buildable-libs-utils';
|
||||
|
||||
export async function* viteDevServerExecutor(
|
||||
options: ViteDevServerExecutorOptions,
|
||||
context: ExecutorContext
|
||||
@ -21,7 +27,7 @@ export async function* viteDevServerExecutor(
|
||||
const projectRoot =
|
||||
context.projectsConfigurations.projects[context.projectName].root;
|
||||
|
||||
registerTsConfigPaths(resolve(projectRoot, 'tsconfig.json'));
|
||||
registerPaths(projectRoot, options, context);
|
||||
|
||||
// Retrieve the option for the configured buildTarget.
|
||||
const buildTargetOptions: ViteBuildExecutorOptions = getNxTargetOptions(
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
export interface ViteDevServerExecutorOptions {
|
||||
buildTarget: string;
|
||||
buildLibsFromSource?: boolean;
|
||||
proxyConfig?: string;
|
||||
port?: number;
|
||||
host?: string | boolean;
|
||||
|
||||
@ -21,6 +21,11 @@
|
||||
"description": "Target which builds the application. Only used to retrieve the configuration as the dev-server does not build the code.",
|
||||
"x-priority": "important"
|
||||
},
|
||||
"buildLibsFromSource": {
|
||||
"type": "boolean",
|
||||
"description": "Read buildable libraries from source instead of building them separately.",
|
||||
"default": true
|
||||
},
|
||||
"proxyConfig": {
|
||||
"type": "string",
|
||||
"description": "Path to the proxy configuration file.",
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
readTargetOptions,
|
||||
} from '@nx/devkit';
|
||||
import { existsSync } from 'fs';
|
||||
import { relative } from 'path';
|
||||
import { relative, resolve } from 'path';
|
||||
import {
|
||||
BuildOptions,
|
||||
InlineConfig,
|
||||
@ -19,6 +19,11 @@ import { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';
|
||||
import { VitePreviewServerExecutorOptions } from '../executors/preview-server/schema';
|
||||
import replaceFiles from '../../plugins/rollup-replace-files.plugin';
|
||||
import { ViteBuildExecutorOptions } from '../executors/build/schema';
|
||||
import { registerTsConfigPaths } from '@nx/js/src/internal';
|
||||
import {
|
||||
calculateProjectDependencies,
|
||||
createTmpTsConfig,
|
||||
} from '@nx/js/src/utils/buildable-libs-utils';
|
||||
|
||||
/**
|
||||
* Returns the path to the vite config file or undefined when not found.
|
||||
@ -188,3 +193,32 @@ export function getNxTargetOptions(target: string, context: ExecutorContext) {
|
||||
const targetObj = parseTargetString(target, context.projectGraph);
|
||||
return readTargetOptions(targetObj, context);
|
||||
}
|
||||
|
||||
export function registerPaths(
|
||||
projectRoot: string,
|
||||
options: ViteBuildExecutorOptions | ViteDevServerExecutorOptions,
|
||||
context: ExecutorContext
|
||||
) {
|
||||
const tsConfig = resolve(projectRoot, 'tsconfig.json');
|
||||
options.buildLibsFromSource ??= true;
|
||||
|
||||
if (!options.buildLibsFromSource) {
|
||||
const { dependencies } = calculateProjectDependencies(
|
||||
context.projectGraph,
|
||||
context.root,
|
||||
context.projectName,
|
||||
context.targetName,
|
||||
context.configurationName
|
||||
);
|
||||
const tmpTsConfig = createTmpTsConfig(
|
||||
tsConfig,
|
||||
context.root,
|
||||
projectRoot,
|
||||
dependencies
|
||||
);
|
||||
|
||||
registerTsConfigPaths(tmpTsConfig);
|
||||
} else {
|
||||
registerTsConfigPaths(tsConfig);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user