From 59c2c21e19ea478851d3652eb339f67ef0c14ee6 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Mon, 28 Nov 2022 09:35:16 -0500 Subject: [PATCH] feat(bundling): remove assets option from vite build - Does not work well with Vite build and dev-server - User can put their files into public/ or add a plugin to copy for them --- docs/generated/packages/vite.json | 34 ------------------- .../vite/src/executors/build/build.impl.ts | 31 +++++++---------- packages/vite/src/executors/build/schema.d.ts | 2 -- packages/vite/src/executors/build/schema.json | 8 ----- .../executors/dev-server/dev-server.impl.ts | 27 +++------------ 5 files changed, 17 insertions(+), 85 deletions(-) diff --git a/docs/generated/packages/vite.json b/docs/generated/packages/vite.json index 9fe8a35986f7ea..16dbd3d2865649 100644 --- a/docs/generated/packages/vite.json +++ b/docs/generated/packages/vite.json @@ -254,40 +254,6 @@ "x-completion-type": "file", "x-completion-glob": "vite.config.@(js|ts)" }, - "assets": { - "type": "array", - "description": "List of static application assets.", - "default": [], - "items": { - "oneOf": [ - { - "type": "object", - "properties": { - "glob": { - "type": "string", - "description": "The pattern to match." - }, - "input": { - "type": "string", - "description": "The input directory path in which to apply 'glob'. Defaults to the project root." - }, - "ignore": { - "description": "An array of globs to ignore.", - "type": "array", - "items": { "type": "string" } - }, - "output": { - "type": "string", - "description": "Absolute path within the output." - } - }, - "additionalProperties": false, - "required": ["glob", "input", "output"] - }, - { "type": "string" } - ] - } - }, "fileReplacements": { "description": "Replace files with other files in the build.", "type": "array", diff --git a/packages/vite/src/executors/build/build.impl.ts b/packages/vite/src/executors/build/build.impl.ts index 4c7d49642b94a2..81199988c7b2eb 100644 --- a/packages/vite/src/executors/build/build.impl.ts +++ b/packages/vite/src/executors/build/build.impl.ts @@ -12,34 +12,29 @@ export default async function viteBuildExecutor( context: ExecutorContext ) { const projectRoot = context.workspace.projects[context.projectName].root; - let assets = options.assets; - // Copy package.json as an asset if it exists + // For buildable libs, copy package.json if it exists. if (existsSync(join(projectRoot, 'package.json'))) { - assets ??= []; - assets.push({ - input: '.', - output: '.', - glob: 'package.json', - }); - } - - logger.info(`NX Vite build starting ...`); - const buildResult = await runInstance(await getBuildConfig(options, context)); - logger.info(`NX Vite build finished ...`); - logger.info(`NX Vite files available in ${options.outputPath}`); - - // TODO(jack): handle watch once we add that option - if (assets) { await copyAssets( { outputPath: options.outputPath, - assets: assets, + assets: [ + { + input: '.', + output: '.', + glob: 'package.json', + }, + ], }, context ); } + logger.info(`NX Vite build starting ...`); + const buildResult = await runInstance(await getBuildConfig(options, context)); + logger.info(`NX Vite build finished ...`); + logger.info(`NX Vite files available in ${options.outputPath}`); + return { success: true }; } diff --git a/packages/vite/src/executors/build/schema.d.ts b/packages/vite/src/executors/build/schema.d.ts index 6d76bfa4d12758..78cdf04819a51a 100644 --- a/packages/vite/src/executors/build/schema.d.ts +++ b/packages/vite/src/executors/build/schema.d.ts @@ -1,4 +1,3 @@ -import type { AssetGlob } from '@nrwl/workspace/src/utilities/assets'; import type { FileReplacement } from '../../plugins/rollup-replace-files.plugin'; export interface ViteBuildExecutorOptions { outputPath: string; @@ -6,7 +5,6 @@ export interface ViteBuildExecutorOptions { proxyConfig?: string; tsConfig?: string; configFile?: string; - assets?: AssetGlob[]; fileReplacements?: FileReplacement[]; sourcemap?: boolean | 'inline' | 'hidden'; minify?: boolean | 'esbuild' | 'terser'; diff --git a/packages/vite/src/executors/build/schema.json b/packages/vite/src/executors/build/schema.json index e788006f18989e..26b7557e1aa6c9 100644 --- a/packages/vite/src/executors/build/schema.json +++ b/packages/vite/src/executors/build/schema.json @@ -38,14 +38,6 @@ "x-completion-type": "file", "x-completion-glob": "vite.config.@(js|ts)" }, - "assets": { - "type": "array", - "description": "List of static application assets.", - "default": [], - "items": { - "$ref": "#/definitions/assetPattern" - } - }, "fileReplacements": { "description": "Replace files with other files in the build.", "type": "array", diff --git a/packages/vite/src/executors/dev-server/dev-server.impl.ts b/packages/vite/src/executors/dev-server/dev-server.impl.ts index 301e42dd0bd551..a3de015f728855 100644 --- a/packages/vite/src/executors/dev-server/dev-server.impl.ts +++ b/packages/vite/src/executors/dev-server/dev-server.impl.ts @@ -1,7 +1,6 @@ -import { ExecutorContext } from '@nrwl/devkit'; - import 'dotenv/config'; -import { InlineConfig, createServer, mergeConfig, ViteDevServer } from 'vite'; +import { ExecutorContext } from '@nrwl/devkit'; +import { createServer, InlineConfig, mergeConfig, ViteDevServer } from 'vite'; import { getBuildConfig, @@ -9,8 +8,6 @@ import { getServerOptions, } from '../../utils/options-utils'; -import { copyAssets, CopyAssetsResult } from '@nrwl/js'; - import { ViteDevServerExecutorOptions } from './schema'; import { ViteBuildExecutorOptions } from '../build/schema'; @@ -23,18 +20,6 @@ export default async function* viteDevServerExecutor( ...options, } as ViteDevServerExecutorOptions & ViteBuildExecutorOptions; - let assetsResult: CopyAssetsResult; - if (mergedOptions.assets) { - assetsResult = await copyAssets( - { - outputPath: mergedOptions.outputPath, - assets: mergedOptions.assets ?? [], - watch: true, - }, - context - ); - } - const serverConfig: InlineConfig = mergeConfig( await getBuildConfig(mergedOptions, context), { @@ -44,7 +29,7 @@ export default async function* viteDevServerExecutor( const server = await createServer(serverConfig); - const baseUrl = await runViteDevServer(server, assetsResult); + const baseUrl = await runViteDevServer(server); yield { success: true, @@ -55,16 +40,12 @@ export default async function* viteDevServerExecutor( await new Promise<{ success: boolean }>(() => {}); } -async function runViteDevServer( - server: ViteDevServer, - assetsResult: CopyAssetsResult -): Promise { +async function runViteDevServer(server: ViteDevServer): Promise { try { await server.listen(); server.printUrls(); const processOnExit = () => { - assetsResult?.stop(); process.off('SIGINT', processOnExit); process.off('SIGTERM', processOnExit); process.off('exit', processOnExit);