Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bundling): remove default values from executors #13444

Merged
merged 1 commit into from Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 7 additions & 28 deletions docs/generated/packages/vite.json
Expand Up @@ -161,29 +161,18 @@
"description": "Path to the proxy configuration file.",
"x-completion-type": "file"
},
"port": {
"type": "number",
"description": "Port to listen on.",
"default": 4200
},
"port": { "type": "number", "description": "Port to listen on." },
"host": {
"description": "Specify which IP addresses the server should listen on.",
"default": "localhost",
"oneOf": [{ "type": "boolean" }, { "type": "string" }]
},
"https": {
"type": "boolean",
"description": "Serve using HTTPS.",
"default": false
},
"https": { "type": "boolean", "description": "Serve using HTTPS." },
"hmr": {
"description": "Enable hot module replacement. For more options, use the 'hmr' option in the Vite configuration file.",
"type": "boolean",
"default": true
"type": "boolean"
},
"open": {
"description": "Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname.",
"default": false,
"oneOf": [{ "type": "boolean" }, { "type": "string" }]
},
"cors": {
Expand All @@ -198,12 +187,10 @@
"mode": {
"type": "string",
"description": "Mode to run the server in.",
"enum": ["production", "development"],
"default": "development"
"enum": ["production", "development"]
},
"clearScreen": {
"description": "Set to false to prevent Vite from clearing the terminal screen when logging certain messages.",
"default": true,
"type": "boolean"
}
},
Expand Down Expand Up @@ -235,19 +222,14 @@
},
"baseHref": {
"type": "string",
"description": "Base url for the application being built."
"description": "Base public path when served in development or production.",
"alias": "base"
},
"proxyConfig": {
"type": "string",
"description": "Path to the proxy configuration file.",
"x-completion-type": "file"
},
"tsConfig": {
"type": "string",
"description": "The name of the Typescript configuration file.",
"x-completion-type": "file",
"x-completion-glob": "tsconfig.*.json"
},
"configFile": {
"type": "string",
"description": "The name of the Vite.js configuration file.",
Expand Down Expand Up @@ -278,12 +260,10 @@
},
"sourcemap": {
"description": "Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.",
"default": true,
"oneOf": [{ "type": "boolean" }, { "type": "string" }]
},
"minify": {
"description": "Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.",
"default": "esbuild",
"oneOf": [{ "type": "boolean" }, { "type": "string" }]
},
"manifest": {
Expand All @@ -302,8 +282,7 @@
"mode": {
"type": "string",
"description": "Mode to run the build in.",
"enum": ["production", "development"],
"default": "production"
"enum": ["production", "development"]
}
},
"definitions": {
Expand Down
6 changes: 4 additions & 2 deletions packages/vite/src/executors/build/build.impl.ts
@@ -1,7 +1,7 @@
import 'dotenv/config';
import { ExecutorContext, logger } from '@nrwl/devkit';
import { build, InlineConfig } from 'vite';
import { getBuildConfig } from '../../utils/options-utils';
import { getBuildAndSharedConfig } from '../../utils/options-utils';
import { ViteBuildExecutorOptions } from './schema';
import { copyAssets } from '@nrwl/js';
import { existsSync } from 'fs';
Expand All @@ -14,7 +14,9 @@ export default async function viteBuildExecutor(
const projectRoot = context.workspace.projects[context.projectName].root;

logger.info(`NX Vite build starting ...`);
const buildResult = await runInstance(await getBuildConfig(options, context));
const buildResult = await runInstance(
await getBuildAndSharedConfig(options, context)
);
logger.info(`NX Vite build finished ...`);
logger.info(`NX Vite files available in ${options.outputPath}`);

Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/executors/build/schema.d.ts
Expand Up @@ -3,7 +3,6 @@ export interface ViteBuildExecutorOptions {
outputPath: string;
baseHref?: string;
proxyConfig?: string;
tsConfig?: string;
configFile?: string;
fileReplacements?: FileReplacement[];
sourcemap?: boolean | 'inline' | 'hidden';
Expand Down
14 changes: 3 additions & 11 deletions packages/vite/src/executors/build/schema.json
Expand Up @@ -19,19 +19,14 @@
},
"baseHref": {
"type": "string",
"description": "Base url for the application being built."
"description": "Base public path when served in development or production.",
"alias": "base"
},
"proxyConfig": {
"type": "string",
"description": "Path to the proxy configuration file.",
"x-completion-type": "file"
},
"tsConfig": {
"type": "string",
"description": "The name of the Typescript configuration file.",
"x-completion-type": "file",
"x-completion-glob": "tsconfig.*.json"
},
"configFile": {
"type": "string",
"description": "The name of the Vite.js configuration file.",
Expand Down Expand Up @@ -62,7 +57,6 @@
},
"sourcemap": {
"description": "Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.",
"default": true,
"oneOf": [
{
"type": "boolean"
Expand All @@ -74,7 +68,6 @@
},
"minify": {
"description": "Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.",
"default": "esbuild",
"oneOf": [
{
"type": "boolean"
Expand Down Expand Up @@ -114,8 +107,7 @@
"mode": {
"type": "string",
"description": "Mode to run the build in.",
"enum": ["production", "development"],
"default": "production"
"enum": ["production", "development"]
}
},
"definitions": {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/executors/dev-server/dev-server.impl.ts
Expand Up @@ -3,7 +3,7 @@ import { ExecutorContext } from '@nrwl/devkit';
import { createServer, InlineConfig, mergeConfig, ViteDevServer } from 'vite';

import {
getBuildConfig,
getBuildAndSharedConfig,
getBuildTargetOptions,
getServerOptions,
} from '../../utils/options-utils';
Expand All @@ -21,7 +21,7 @@ export default async function* viteDevServerExecutor(
} as ViteDevServerExecutorOptions & ViteBuildExecutorOptions;

const serverConfig: InlineConfig = mergeConfig(
await getBuildConfig(mergedOptions, context),
await getBuildAndSharedConfig(mergedOptions, context),
{
server: getServerOptions(mergedOptions, context),
} as InlineConfig
Expand Down
15 changes: 4 additions & 11 deletions packages/vite/src/executors/dev-server/schema.json
Expand Up @@ -27,12 +27,10 @@
},
"port": {
"type": "number",
"description": "Port to listen on.",
"default": 4200
"description": "Port to listen on."
},
"host": {
"description": "Specify which IP addresses the server should listen on.",
"default": "localhost",
"oneOf": [
{
"type": "boolean"
Expand All @@ -44,17 +42,14 @@
},
"https": {
"type": "boolean",
"description": "Serve using HTTPS.",
"default": false
"description": "Serve using HTTPS."
},
"hmr": {
"description": "Enable hot module replacement. For more options, use the 'hmr' option in the Vite configuration file.",
"type": "boolean",
"default": true
"type": "boolean"
},
"open": {
"description": "Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname.",
"default": false,
"oneOf": [
{
"type": "boolean"
Expand All @@ -76,12 +71,10 @@
"mode": {
"type": "string",
"description": "Mode to run the server in.",
"enum": ["production", "development"],
"default": "development"
"enum": ["production", "development"]
},
"clearScreen": {
"description": "Set to false to prevent Vite from clearing the terminal screen when logging certain messages.",
"default": true,
"type": "boolean"
}
},
Expand Down
10 changes: 10 additions & 0 deletions packages/vite/src/generators/vitest/vitest.spec.ts
Expand Up @@ -109,6 +109,11 @@ describe('vitest generator', () => {


export default defineConfig({

server:{
port: 4200,
host: 'localhost',
},
plugins: [

react(),
Expand Down Expand Up @@ -145,6 +150,11 @@ describe('vitest generator', () => {


export default defineConfig({

server:{
port: 4200,
host: 'localhost',
},
plugins: [

react(),
Expand Down
10 changes: 9 additions & 1 deletion packages/vite/src/utils/generator-utils.ts
Expand Up @@ -406,7 +406,13 @@ export function writeViteConfig(tree: Tree, options: Schema) {
}]
}
},`
: '';
: ``;

const serverOption = `
server:{
port: 4200,
host: 'localhost',
},`;

switch (options.uiFramework) {
case 'react':
Expand All @@ -422,6 +428,7 @@ ${options.includeVitest ? '/// <reference types="vitest" />' : ''}
}

export default defineConfig({
${serverOption}
plugins: [
${options.includeLib ? dtsPlugin : ''}
react(),
Expand All @@ -447,6 +454,7 @@ ${options.includeVitest ? '/// <reference types="vitest" />' : ''}
}

export default defineConfig({
${serverOption}
plugins: [
${options.includeLib ? dtsPlugin : ''}
tsconfigPaths({
Expand Down
44 changes: 5 additions & 39 deletions packages/vite/src/utils/options-utils.ts
Expand Up @@ -9,33 +9,28 @@ import { existsSync } from 'fs';
import { join, relative } from 'path';
import {
BuildOptions,
defineConfig,
InlineConfig,
mergeConfig,
searchForWorkspaceRoot,
ServerOptions,
UserConfig,
UserConfigFn,
} from 'vite';
import { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';
import replaceFiles from '../../plugins/rollup-replace-files.plugin';
import { ViteBuildExecutorOptions } from '../executors/build/schema';

export async function getBuildConfig(
export async function getBuildAndSharedConfig(
options:
| (ViteDevServerExecutorOptions & ViteBuildExecutorOptions)
| ViteBuildExecutorOptions,
context: ExecutorContext
): Promise<InlineConfig> {
const projectRoot = context.workspace.projects[context.projectName].root;

const userConfig: UserConfig = await getUserConfig(
options as ViteDevServerExecutorOptions & ViteBuildExecutorOptions,
context,
projectRoot
);

return mergeConfig(userConfig, {
return mergeConfig({}, {
mode: options.mode,
root: projectRoot,
base: options.baseHref,
configFile: normalizeConfigFilePath(
options.configFile,
context.root,
Expand Down Expand Up @@ -63,33 +58,6 @@ export function normalizeConfigFilePath(
: undefined;
}

export function normalizeTsConfigPath(
tsConfig: string,
workspaceRoot: string
): string {
return tsConfig
? joinPathFragments(`${workspaceRoot}/${tsConfig}`)
: undefined;
}

export async function getUserConfig(
options: ViteDevServerExecutorOptions & ViteBuildExecutorOptions,
context: ExecutorContext,
projectRoot: string
): Promise<UserConfig> {
const baseUserConfig: UserConfigFn = (await defineConfig(() => {
return {
base: options.baseHref ?? '/',
root: projectRoot,
tsConfig: normalizeTsConfigPath(options.tsConfig, context.root),
};
})) as UserConfigFn;
return baseUserConfig({
command: 'build',
mode: options['configurationName'],
});
}

export function getServerOptions(
options: ViteDevServerExecutorOptions,
context: ExecutorContext
Expand Down Expand Up @@ -122,7 +90,6 @@ export function getServerOptions(
open: options.open,
cors: options.cors,
logLevel: options.logLevel,
mode: options.mode,
clearScreen: options.clearScreen,
};

Expand Down Expand Up @@ -159,7 +126,6 @@ export function getViteBuildOptions(
manifest: options.manifest,
ssrManifest: options.ssrManifest,
logLevel: options.logLevel,
mode: options.mode,
};

return buildOptions;
Expand Down