@nx/vite 16.9.0-beta.2 → 16.9.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "16.9.0-beta.
|
|
3
|
+
"version": "16.9.0-beta.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for building and testing applications using Vite",
|
|
6
6
|
"repository": {
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"migrations": "./migrations.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nrwl/vite": "16.9.0-beta.2",
|
|
33
|
-
"@nx/devkit": "16.9.0-beta.2",
|
|
34
|
-
"@nx/js": "16.9.0-beta.2",
|
|
35
32
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
36
33
|
"@swc/helpers": "~0.5.0",
|
|
37
34
|
"enquirer": "~2.3.6",
|
|
38
|
-
"
|
|
35
|
+
"@nx/devkit": "16.9.0-beta.4",
|
|
36
|
+
"@nx/js": "16.9.0-beta.4",
|
|
37
|
+
"tsconfig-paths": "^4.1.2",
|
|
38
|
+
"@nrwl/vite": "*"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"vite": "^4.3.4",
|
|
@@ -56,6 +56,5 @@
|
|
|
56
56
|
"./src/executors/*/compat": "./src/executors/*/compat.js",
|
|
57
57
|
"./plugins/nx-tsconfig-paths.plugin": "./plugins/nx-tsconfig-paths.plugin.js"
|
|
58
58
|
},
|
|
59
|
-
"type": "commonjs"
|
|
60
|
-
"gitHead": "e11d538fa2c7266066d554d9405abab8e0a65040"
|
|
59
|
+
"type": "commonjs"
|
|
61
60
|
}
|
|
@@ -19,7 +19,7 @@ const _vite = require("vite");
|
|
|
19
19
|
const _optionsutils = require("../../utils/options-utils");
|
|
20
20
|
async function* vitePreviewServerExecutor(options, context) {
|
|
21
21
|
var _context_projectsConfigurations_projects_target_project;
|
|
22
|
-
const target = (0, _devkit.parseTargetString)(options.buildTarget, context
|
|
22
|
+
const target = (0, _devkit.parseTargetString)(options.buildTarget, context);
|
|
23
23
|
const targetConfiguration = (_context_projectsConfigurations_projects_target_project = context.projectsConfigurations.projects[target.project]) == null ? void 0 : _context_projectsConfigurations_projects_target_project.targets[target.target];
|
|
24
24
|
if (!targetConfiguration) {
|
|
25
25
|
throw new Error(`Invalid buildTarget: ${options.buildTarget}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/executors/preview-server/preview-server.impl.ts"],"sourcesContent":["import { ExecutorContext, parseTargetString, runExecutor } from '@nx/devkit';\nimport { InlineConfig, mergeConfig, preview, PreviewServer } from 'vite';\nimport {\n getNxTargetOptions,\n getViteSharedConfig,\n getViteBuildOptions,\n getVitePreviewOptions,\n} from '../../utils/options-utils';\nimport { ViteBuildExecutorOptions } from '../build/schema';\nimport { VitePreviewServerExecutorOptions } from './schema';\n\ninterface CustomBuildTargetOptions {\n outputPath: string;\n}\n\nexport async function* vitePreviewServerExecutor(\n options: VitePreviewServerExecutorOptions,\n context: ExecutorContext\n) {\n const target = parseTargetString(options.buildTarget, context
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/executors/preview-server/preview-server.impl.ts"],"sourcesContent":["import { ExecutorContext, parseTargetString, runExecutor } from '@nx/devkit';\nimport { InlineConfig, mergeConfig, preview, PreviewServer } from 'vite';\nimport {\n getNxTargetOptions,\n getViteSharedConfig,\n getViteBuildOptions,\n getVitePreviewOptions,\n} from '../../utils/options-utils';\nimport { ViteBuildExecutorOptions } from '../build/schema';\nimport { VitePreviewServerExecutorOptions } from './schema';\n\ninterface CustomBuildTargetOptions {\n outputPath: string;\n}\n\nexport async function* vitePreviewServerExecutor(\n options: VitePreviewServerExecutorOptions,\n context: ExecutorContext\n) {\n const target = parseTargetString(options.buildTarget, context);\n const targetConfiguration =\n context.projectsConfigurations.projects[target.project]?.targets[\n target.target\n ];\n if (!targetConfiguration) {\n throw new Error(`Invalid buildTarget: ${options.buildTarget}`);\n }\n\n const isCustomBuildTarget =\n targetConfiguration.executor !== '@nx/vite:build' &&\n targetConfiguration.executor !== '@nrwl/vite:build';\n\n // Retrieve the option for the configured buildTarget.\n const buildTargetOptions:\n | ViteBuildExecutorOptions\n | CustomBuildTargetOptions = getNxTargetOptions(\n options.buildTarget,\n context\n );\n\n const outputPath = options.staticFilePath ?? buildTargetOptions.outputPath;\n\n if (!outputPath) {\n throw new Error(\n `Could not infer the \"outputPath\". It should either be a property of the \"${options.buildTarget}\" buildTarget or provided explicitly as a \"staticFilePath\" option.`\n );\n }\n\n // Merge the options from the build and preview-serve targets.\n // The latter takes precedence.\n const mergedOptions = {\n ...{ watch: {} },\n ...(isCustomBuildTarget ? {} : buildTargetOptions),\n ...options,\n outputPath,\n };\n\n // Retrieve the server configuration.\n const serverConfig: InlineConfig = mergeConfig(\n getViteSharedConfig(mergedOptions, options.clearScreen, context),\n {\n build: getViteBuildOptions(mergedOptions, context),\n preview: getVitePreviewOptions(mergedOptions, context),\n }\n );\n\n if (serverConfig.mode === 'production') {\n console.warn('WARNING: preview is not meant to be run in production!');\n }\n\n let server: PreviewServer | undefined;\n\n const processOnExit = async () => {\n await closeServer(server);\n };\n\n process.once('SIGINT', processOnExit);\n process.once('SIGTERM', processOnExit);\n process.once('exit', processOnExit);\n\n // Launch the build target.\n // If customBuildTarget is set to true, do not provide any overrides to it\n const buildTargetOverrides = isCustomBuildTarget ? {} : mergedOptions;\n const build = await runExecutor(target, buildTargetOverrides, context);\n\n for await (const result of build) {\n if (result.success) {\n try {\n if (!server) {\n server = await preview(serverConfig);\n }\n server.printUrls();\n\n const resolvedUrls = [\n ...server.resolvedUrls.local,\n ...server.resolvedUrls.network,\n ];\n\n yield {\n success: true,\n baseUrl: resolvedUrls[0] ?? '',\n };\n } catch (e) {\n console.error(e);\n yield {\n success: false,\n baseUrl: '',\n };\n }\n } else {\n yield {\n success: false,\n baseUrl: '',\n };\n }\n }\n\n await new Promise<void>((resolve) => {\n process.once('SIGINT', () => resolve());\n process.once('SIGTERM', () => resolve());\n process.once('exit', () => resolve());\n });\n}\n\nfunction closeServer(server?: PreviewServer): Promise<void> {\n return new Promise((resolve) => {\n if (!server) {\n resolve();\n } else {\n const { httpServer } = server;\n // closeAllConnections was added in Node v18.2.0\n httpServer.closeAllConnections && httpServer.closeAllConnections();\n httpServer.close(() => resolve());\n }\n });\n}\n\nexport default vitePreviewServerExecutor;\n"],"names":["vitePreviewServerExecutor","options","context","target","parseTargetString","buildTarget","targetConfiguration","projectsConfigurations","projects","project","targets","Error","isCustomBuildTarget","executor","buildTargetOptions","getNxTargetOptions","outputPath","staticFilePath","mergedOptions","watch","serverConfig","mergeConfig","getViteSharedConfig","clearScreen","build","getViteBuildOptions","preview","getVitePreviewOptions","mode","console","warn","server","processOnExit","closeServer","process","once","buildTargetOverrides","runExecutor","result","success","printUrls","resolvedUrls","local","network","baseUrl","e","error","Promise","resolve","httpServer","closeAllConnections","close"],"mappings":";;;;;;;;IAeuBA,yBAAyB;eAAzBA;;IA0HvB,OAAyC;eAAzC;;;;wBAzIgE;sBACE;8BAM3D;AAQA,gBAAgBA,0BACrBC,OAAyC,EACzCC,OAAwB,EACxB;QAGEA;IAFF,MAAMC,SAASC,IAAAA,yBAAiB,EAACH,QAAQI,WAAW,EAAEH;IACtD,MAAMI,sBACJJ,CAAAA,0DAAAA,QAAQK,sBAAsB,CAACC,QAAQ,CAACL,OAAOM,OAAO,CAAC,YAAvDP,KAAAA,IAAAA,wDAAyDQ,OAAO,CAC9DP,OAAOA,MAAM,CACd;IACH,IAAI,CAACG,qBAAqB;QACxB,MAAM,IAAIK,MAAM,CAAC,qBAAqB,EAAEV,QAAQI,WAAW,CAAC,CAAC,EAAE;IACjE,CAAC;IAED,MAAMO,sBACJN,oBAAoBO,QAAQ,KAAK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AC;gBACDW,OAAOS,SAAS;gBAEhB,MAAMC,eAAe;uBAChBV,OAAOU,YAAY,CAACC,KAAK;uBACzBX,OAAOU,YAAY,CAACE,OAAO;iBAC/B;oBAIUF;gBAFX,MAAM;oBACJF,SAAS,IAAI;oBACbK,SAASH,CAAAA,iBAAAA,YAAY,CAAC,EAAE,YAAfA,iBAAmB,EAAE;gBAChC;YACF,EAAE,OAAOI,GAAG;gBACVhB,QAAQiB,KAAK,CAACD;gBACd,MAAM;oBACJN,SAAS,KAAK;oBACdK,SAAS;gBACX;YACF;QACF,OAAO;YACL,MAAM;gBACJL,SAAS,KAAK;gBACdK,SAAS;YACX;QACF,CAAC;IACH;IAEA,MAAM,IAAIG,QAAc,CAACC,UAAY;QACnCd,QAAQC,IAAI,CAAC,UAAU,IAAMa;QAC7Bd,QAAQC,IAAI,CAAC,WAAW,IAAMa;QAC9Bd,QAAQC,IAAI,CAAC,QAAQ,IAAMa;IAC7B;AACF;AAEA,SAASf,YAAYF,MAAsB,EAAiB;IAC1D,OAAO,IAAIgB,QAAQ,CAACC,UAAY;QAC9B,IAAI,CAACjB,QAAQ;YACXiB;QACF,OAAO;YACL,MAAM,EAAEC,WAAU,EAAE,GAAGlB;YACvB,gDAAgD;YAChDkB,WAAWC,mBAAmB,IAAID,WAAWC,mBAAmB;YAChED,WAAWE,KAAK,CAAC,IAAMH;QACzB,CAAC;IACH;AACF;MAEA,WAAehD"}
|
|
@@ -133,7 +133,7 @@ function getVitePreviewOptions(options, context) {
|
|
|
133
133
|
return serverOptions;
|
|
134
134
|
}
|
|
135
135
|
function getNxTargetOptions(target, context) {
|
|
136
|
-
const targetObj = (0, _devkit.parseTargetString)(target, context
|
|
136
|
+
const targetObj = (0, _devkit.parseTargetString)(target, context);
|
|
137
137
|
return (0, _devkit.readTargetOptions)(targetObj, context);
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/vite/src/utils/options-utils.ts"],"sourcesContent":["import {\n ExecutorContext,\n joinPathFragments,\n logger,\n parseTargetString,\n readTargetOptions,\n} from '@nx/devkit';\nimport { existsSync } from 'fs';\nimport { relative } from 'path';\nimport {\n BuildOptions,\n InlineConfig,\n PluginOption,\n PreviewOptions,\n searchForWorkspaceRoot,\n ServerOptions,\n} from 'vite';\nimport { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';\nimport { VitePreviewServerExecutorOptions } from '../executors/preview-server/schema';\nimport replaceFiles from '../../plugins/rollup-replace-files.plugin';\nimport { ViteBuildExecutorOptions } from '../executors/build/schema';\n\n/**\n * Returns the path to the vite config file or undefined when not found.\n */\nexport function normalizeViteConfigFilePath(\n projectRoot: string,\n configFile?: string\n): string | undefined {\n if (configFile) {\n const normalized = joinPathFragments(configFile);\n if (!existsSync(normalized)) {\n throw new Error(\n `Could not find vite config at provided path \"${normalized}\".`\n );\n }\n return normalized;\n }\n return existsSync(joinPathFragments(projectRoot, 'vite.config.ts'))\n ? joinPathFragments(projectRoot, 'vite.config.ts')\n : existsSync(joinPathFragments(projectRoot, 'vite.config.js'))\n ? joinPathFragments(projectRoot, 'vite.config.js')\n : undefined;\n}\n\nexport function getProjectTsConfigPath(\n projectRoot: string\n): string | undefined {\n return existsSync(joinPathFragments(projectRoot, 'tsconfig.app.json'))\n ? joinPathFragments(projectRoot, 'tsconfig.app.json')\n : existsSync(joinPathFragments(projectRoot, 'tsconfig.lib.json'))\n ? joinPathFragments(projectRoot, 'tsconfig.lib.json')\n : existsSync(joinPathFragments(projectRoot, 'tsconfig.json'))\n ? joinPathFragments(projectRoot, 'tsconfig.json')\n : undefined;\n}\n\n/**\n * Returns the path to the proxy configuration file or undefined when not found.\n */\nexport function getViteServerProxyConfigPath(\n nxProxyConfig: string | undefined,\n context: ExecutorContext\n): string | undefined {\n if (nxProxyConfig) {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n\n const proxyConfigPath = nxProxyConfig\n ? joinPathFragments(context.root, nxProxyConfig)\n : joinPathFragments(projectRoot, 'proxy.conf.json');\n\n if (existsSync(proxyConfigPath)) {\n return proxyConfigPath;\n }\n }\n}\n\n/**\n * Builds the shared options for vite.\n *\n * Most shared options are derived from the build target.\n */\nexport function getViteSharedConfig(\n options: ViteBuildExecutorOptions,\n clearScreen: boolean | undefined,\n context: ExecutorContext\n): InlineConfig {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n\n const root = relative(\n context.cwd,\n joinPathFragments(context.root, projectRoot)\n );\n\n return {\n mode: options.mode,\n root,\n base: options.base,\n configFile: normalizeViteConfigFilePath(projectRoot, options.configFile),\n plugins: [replaceFiles(options.fileReplacements) as PluginOption],\n optimizeDeps: { force: options.force },\n clearScreen: clearScreen,\n logLevel: options.logLevel,\n };\n}\n\n/**\n * Builds the options for the vite dev server.\n */\nexport function getViteServerOptions(\n options: ViteDevServerExecutorOptions,\n context: ExecutorContext\n): ServerOptions {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n const serverOptions: ServerOptions = {\n host: options.host,\n port: options.port,\n https: options.https,\n hmr: options.hmr,\n open: options.open,\n cors: options.cors,\n fs: {\n allow: [\n searchForWorkspaceRoot(joinPathFragments(projectRoot)),\n joinPathFragments(context.root, 'node_modules/vite'),\n ],\n },\n };\n\n const proxyConfigPath = getViteServerProxyConfigPath(\n options.proxyConfig,\n context\n );\n if (proxyConfigPath) {\n logger.info(`Loading proxy configuration from: ${proxyConfigPath}`);\n serverOptions.proxy = require(proxyConfigPath);\n }\n\n return serverOptions;\n}\n\n/**\n * Builds the build options for the vite.\n */\nexport function getViteBuildOptions(\n options: ViteBuildExecutorOptions,\n context: ExecutorContext\n): BuildOptions {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n\n return {\n outDir: relative(projectRoot, options.outputPath),\n emptyOutDir: options.emptyOutDir,\n reportCompressedSize: true,\n cssCodeSplit: options.cssCodeSplit,\n target: options.target,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n sourcemap: options.sourcemap,\n minify: options.minify,\n manifest: options.manifest,\n ssrManifest: options.ssrManifest,\n ssr: options.ssr,\n watch: options.watch as BuildOptions['watch'],\n };\n}\n\n/**\n * Builds the options for the vite preview server.\n */\nexport function getVitePreviewOptions(\n options: VitePreviewServerExecutorOptions,\n context: ExecutorContext\n): PreviewOptions {\n const serverOptions: ServerOptions = {\n host: options.host,\n port: options.port,\n https: options.https,\n open: options.open,\n };\n\n const proxyConfigPath = getViteServerProxyConfigPath(\n options.proxyConfig,\n context\n );\n if (proxyConfigPath) {\n logger.info(`Loading proxy configuration from: ${proxyConfigPath}`);\n serverOptions.proxy = require(proxyConfigPath);\n }\n\n return serverOptions;\n}\n\nexport function getNxTargetOptions(target: string, context: ExecutorContext) {\n const targetObj = parseTargetString(target, context.projectGraph);\n return readTargetOptions(targetObj, context);\n}\n"],"names":["normalizeViteConfigFilePath","getProjectTsConfigPath","getViteServerProxyConfigPath","getViteSharedConfig","getViteServerOptions","getViteBuildOptions","getVitePreviewOptions","getNxTargetOptions","projectRoot","configFile","normalized","joinPathFragments","existsSync","Error","undefined","nxProxyConfig","context","projectsConfigurations","projects","projectName","root","proxyConfigPath","options","clearScreen","relative","cwd","mode","base","plugins","replaceFiles","fileReplacements","optimizeDeps","force","logLevel","serverOptions","host","port","https","hmr","open","cors","fs","allow","searchForWorkspaceRoot","proxyConfig","logger","info","proxy","require","outDir","outputPath","emptyOutDir","reportCompressedSize","cssCodeSplit","target","commonjsOptions","transformMixedEsModules","sourcemap","minify","manifest","ssrManifest","ssr","watch","targetObj","parseTargetString","projectGraph","readTargetOptions"],"mappings":";;;;;;;;IAyBgBA,2BAA2B;eAA3BA;;IAoBAC,sBAAsB;eAAtBA;;IAeAC,4BAA4B;eAA5BA;;IAuBAC,mBAAmB;eAAnBA;;IA4BAC,oBAAoB;eAApBA;;IAoCAC,mBAAmB;eAAnBA;;IA4BAC,qBAAqB;eAArBA;;IAuBAC,kBAAkB;eAAlBA;;;wBAhMT;oBAC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,MAAMR,cACJQ,QAAQC,sBAAsB,CAACC,QAAQ,CAACF,QAAQG,WAAW,CAAC,CAACC,IAAI;IAEnE,OAAO;QACL6B,QAAQzB,IAAAA,cAAQ,EAAChB,aAAac,QAAQ4B,UAAU;QAChDC,aAAa7B,QAAQ6B,WAAW;QAChCC,sBAAsB,IAAI;QAC1BC,cAAc/B,QAAQ+B,YAAY;QAClCC,QAAQhC,QAAQgC,MAAM;QACtBC,iBAAiB;YACfC,yBAAyB,IAAI;QAC/B;QACAC,WAAWnC,QAAQmC,SAAS;QAC5BC,QAAQpC,QAAQoC,MAAM;QACtBC,UAAUrC,QAAQqC,QAAQ;QAC1BC,aAAatC,QAAQsC,WAAW;QAChCC,KAAKvC,QAAQuC,GAAG;QAChBC,OAAOxC,QAAQwC,KAAK;IACtB;AACF;AAKO,SAASxD,sBACdgB,OAAyC,EACzCN,OAAwB,EACR;IAChB,MAAMkB,gBAA+B;QACnCC,MAAMb,QAAQa,IAAI;QAClBC,MAAMd,QAAQc,IAAI;QAClBC,OAAOf,QAAQe,KAAK;QACpBE,MAAMjB,QAAQiB,IAAI;IACpB;IAEA,MAAMlB,kBAAkBnB,6BACtBoB,QAAQsB,WAAW,EACnB5B;IAEF,IAAIK,iBAAiB;QACnBwB,cAAM,CAACC,IAAI,CAAC,CAAC,kCAAkC,EAAEzB,gBAAgB,CAAC;QAClEa,cAAca,KAAK,GAAGC,QAAQ3B;IAChC,CAAC;IAED,OAAOa;AACT;AAEO,SAAS3B,mBAAmB+C,MAAc,EAAEtC,OAAwB,EAAE;IAC3E,MAAM+C,YAAYC,IAAAA,yBAAiB,EAACV,QAAQtC,QAAQiD,YAAY;IAChE,OAAOC,IAAAA,yBAAiB,EAACH,WAAW/C;AACtC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/vite/src/utils/options-utils.ts"],"sourcesContent":["import {\n ExecutorContext,\n joinPathFragments,\n logger,\n parseTargetString,\n readTargetOptions,\n} from '@nx/devkit';\nimport { existsSync } from 'fs';\nimport { relative } from 'path';\nimport {\n BuildOptions,\n InlineConfig,\n PluginOption,\n PreviewOptions,\n searchForWorkspaceRoot,\n ServerOptions,\n} from 'vite';\nimport { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';\nimport { VitePreviewServerExecutorOptions } from '../executors/preview-server/schema';\nimport replaceFiles from '../../plugins/rollup-replace-files.plugin';\nimport { ViteBuildExecutorOptions } from '../executors/build/schema';\n\n/**\n * Returns the path to the vite config file or undefined when not found.\n */\nexport function normalizeViteConfigFilePath(\n projectRoot: string,\n configFile?: string\n): string | undefined {\n if (configFile) {\n const normalized = joinPathFragments(configFile);\n if (!existsSync(normalized)) {\n throw new Error(\n `Could not find vite config at provided path \"${normalized}\".`\n );\n }\n return normalized;\n }\n return existsSync(joinPathFragments(projectRoot, 'vite.config.ts'))\n ? joinPathFragments(projectRoot, 'vite.config.ts')\n : existsSync(joinPathFragments(projectRoot, 'vite.config.js'))\n ? joinPathFragments(projectRoot, 'vite.config.js')\n : undefined;\n}\n\nexport function getProjectTsConfigPath(\n projectRoot: string\n): string | undefined {\n return existsSync(joinPathFragments(projectRoot, 'tsconfig.app.json'))\n ? joinPathFragments(projectRoot, 'tsconfig.app.json')\n : existsSync(joinPathFragments(projectRoot, 'tsconfig.lib.json'))\n ? joinPathFragments(projectRoot, 'tsconfig.lib.json')\n : existsSync(joinPathFragments(projectRoot, 'tsconfig.json'))\n ? joinPathFragments(projectRoot, 'tsconfig.json')\n : undefined;\n}\n\n/**\n * Returns the path to the proxy configuration file or undefined when not found.\n */\nexport function getViteServerProxyConfigPath(\n nxProxyConfig: string | undefined,\n context: ExecutorContext\n): string | undefined {\n if (nxProxyConfig) {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n\n const proxyConfigPath = nxProxyConfig\n ? joinPathFragments(context.root, nxProxyConfig)\n : joinPathFragments(projectRoot, 'proxy.conf.json');\n\n if (existsSync(proxyConfigPath)) {\n return proxyConfigPath;\n }\n }\n}\n\n/**\n * Builds the shared options for vite.\n *\n * Most shared options are derived from the build target.\n */\nexport function getViteSharedConfig(\n options: ViteBuildExecutorOptions,\n clearScreen: boolean | undefined,\n context: ExecutorContext\n): InlineConfig {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n\n const root = relative(\n context.cwd,\n joinPathFragments(context.root, projectRoot)\n );\n\n return {\n mode: options.mode,\n root,\n base: options.base,\n configFile: normalizeViteConfigFilePath(projectRoot, options.configFile),\n plugins: [replaceFiles(options.fileReplacements) as PluginOption],\n optimizeDeps: { force: options.force },\n clearScreen: clearScreen,\n logLevel: options.logLevel,\n };\n}\n\n/**\n * Builds the options for the vite dev server.\n */\nexport function getViteServerOptions(\n options: ViteDevServerExecutorOptions,\n context: ExecutorContext\n): ServerOptions {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n const serverOptions: ServerOptions = {\n host: options.host,\n port: options.port,\n https: options.https,\n hmr: options.hmr,\n open: options.open,\n cors: options.cors,\n fs: {\n allow: [\n searchForWorkspaceRoot(joinPathFragments(projectRoot)),\n joinPathFragments(context.root, 'node_modules/vite'),\n ],\n },\n };\n\n const proxyConfigPath = getViteServerProxyConfigPath(\n options.proxyConfig,\n context\n );\n if (proxyConfigPath) {\n logger.info(`Loading proxy configuration from: ${proxyConfigPath}`);\n serverOptions.proxy = require(proxyConfigPath);\n }\n\n return serverOptions;\n}\n\n/**\n * Builds the build options for the vite.\n */\nexport function getViteBuildOptions(\n options: ViteBuildExecutorOptions,\n context: ExecutorContext\n): BuildOptions {\n const projectRoot =\n context.projectsConfigurations.projects[context.projectName].root;\n\n return {\n outDir: relative(projectRoot, options.outputPath),\n emptyOutDir: options.emptyOutDir,\n reportCompressedSize: true,\n cssCodeSplit: options.cssCodeSplit,\n target: options.target,\n commonjsOptions: {\n transformMixedEsModules: true,\n },\n sourcemap: options.sourcemap,\n minify: options.minify,\n manifest: options.manifest,\n ssrManifest: options.ssrManifest,\n ssr: options.ssr,\n watch: options.watch as BuildOptions['watch'],\n };\n}\n\n/**\n * Builds the options for the vite preview server.\n */\nexport function getVitePreviewOptions(\n options: VitePreviewServerExecutorOptions,\n context: ExecutorContext\n): PreviewOptions {\n const serverOptions: ServerOptions = {\n host: options.host,\n port: options.port,\n https: options.https,\n open: options.open,\n };\n\n const proxyConfigPath = getViteServerProxyConfigPath(\n options.proxyConfig,\n context\n );\n if (proxyConfigPath) {\n logger.info(`Loading proxy configuration from: ${proxyConfigPath}`);\n serverOptions.proxy = require(proxyConfigPath);\n }\n\n return serverOptions;\n}\n\nexport function getNxTargetOptions(target: string, context: ExecutorContext) {\n const targetObj = parseTargetString(target, context);\n return readTargetOptions(targetObj, context);\n}\n"],"names":["normalizeViteConfigFilePath","getProjectTsConfigPath","getViteServerProxyConfigPath","getViteSharedConfig","getViteServerOptions","getViteBuildOptions","getVitePreviewOptions","getNxTargetOptions","projectRoot","configFile","normalized","joinPathFragments","existsSync","Error","undefined","nxProxyConfig","context","projectsConfigurations","projects","projectName","root","proxyConfigPath","options","clearScreen","relative","cwd","mode","base","plugins","replaceFiles","fileReplacements","optimizeDeps","force","logLevel","serverOptions","host","port","https","hmr","open","cors","fs","allow","searchForWorkspaceRoot","proxyConfig","logger","info","proxy","require","outDir","outputPath","emptyOutDir","reportCompressedSize","cssCodeSplit","target","commonjsOptions","transformMixedEsModules","sourcemap","minify","manifest","ssrManifest","ssr","watch","targetObj","parseTargetString","readTargetOptions"],"mappings":";;;;;;;;IAyBgBA,2BAA2B;eAA3BA;;IAoBAC,sBAAsB;eAAtBA;;IAeAC,4BAA4B;eAA5BA;;IAuBAC,mBAAmB;eAAnBA;;IA4BAC,oBAAoB;eAApBA;;IAoCAC,mBAAmB;eAAnBA;;IA4BAC,qBAAqB;eAArBA;;IAuBAC,kBAAkB;eAAlBA;;;wBAhMT;oBACoB;sBACF;sBAQlB;0CAGkB;AAMlB,SAASP,4BACdQ,WAAmB,EACnBC,UAAmB,EACC;IACpB,IAAIA,YAAY;QACd,MAAMC,aAAaC,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