Skip to content

Commit

Permalink
feat(bundling): remove assets option from vite build (#13441)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Nov 28, 2022
1 parent 05d0bf1 commit 5af4ae0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 82 deletions.
34 changes: 0 additions & 34 deletions docs/generated/packages/vite.json
Expand Up @@ -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",
Expand Down
25 changes: 10 additions & 15 deletions packages/vite/src/executors/build/build.impl.ts
@@ -1,6 +1,6 @@
import 'dotenv/config';
import { ExecutorContext, logger } from '@nrwl/devkit';
import { build, InlineConfig } from 'vite';
import 'dotenv/config';
import { getBuildConfig } from '../../utils/options-utils';
import { ViteBuildExecutorOptions } from './schema';
import { copyAssets } from '@nrwl/js';
Expand All @@ -12,29 +12,24 @@ 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
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) {
// For buildable libs, copy package.json if it exists.
if (existsSync(join(projectRoot, 'package.json'))) {
await copyAssets(
{
outputPath: options.outputPath,
assets: assets,
assets: [
{
input: '.',
output: '.',
glob: 'package.json',
},
],
},
context
);
Expand Down
2 changes: 0 additions & 2 deletions packages/vite/src/executors/build/schema.d.ts
@@ -1,12 +1,10 @@
import type { AssetGlob } from '@nrwl/workspace/src/utilities/assets';
import type { FileReplacement } from '../../plugins/rollup-replace-files.plugin';
export interface ViteBuildExecutorOptions {
outputPath: string;
baseHref?: string;
proxyConfig?: string;
tsConfig?: string;
configFile?: string;
assets?: AssetGlob[];
fileReplacements?: FileReplacement[];
sourcemap?: boolean | 'inline' | 'hidden';
minify?: boolean | 'esbuild' | 'terser';
Expand Down
8 changes: 0 additions & 8 deletions packages/vite/src/executors/build/schema.json
Expand Up @@ -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",
Expand Down
27 changes: 4 additions & 23 deletions packages/vite/src/executors/dev-server/dev-server.impl.ts
@@ -1,16 +1,13 @@
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,
getBuildTargetOptions,
getServerOptions,
} from '../../utils/options-utils';

import { copyAssets, CopyAssetsResult } from '@nrwl/js';

import { ViteDevServerExecutorOptions } from './schema';
import { ViteBuildExecutorOptions } from '../build/schema';

Expand All @@ -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),
{
Expand All @@ -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,
Expand All @@ -55,16 +40,12 @@ export default async function* viteDevServerExecutor(
await new Promise<{ success: boolean }>(() => {});
}

async function runViteDevServer(
server: ViteDevServer,
assetsResult: CopyAssetsResult
): Promise<string> {
async function runViteDevServer(server: ViteDevServer): Promise<string> {
try {
await server.listen();
server.printUrls();

const processOnExit = () => {
assetsResult?.stop();
process.off('SIGINT', processOnExit);
process.off('SIGTERM', processOnExit);
process.off('exit', processOnExit);
Expand Down

1 comment on commit 5af4ae0

@vercel
Copy link

@vercel vercel bot commented on 5af4ae0 Nov 28, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.