feat(pack-up): enable preserve modules (#18358)

This commit is contained in:
Josh 2023-10-10 08:09:55 +01:00 committed by GitHub
parent fb3a0b8248
commit bb9a6788a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -89,6 +89,14 @@ interface ConfigOptions {
*/ */
externals?: string[]; externals?: string[];
minify?: boolean; minify?: boolean;
/**
* @alpha
*
* @description Instead of creating as few chunks as possible, this mode
* will create separate chunks for all modules using the original module
* names as file names
*/
preserveModules?: boolean;
sourcemap?: boolean; sourcemap?: boolean;
runtime?: Runtime; runtime?: Runtime;
} }

View File

@ -2,6 +2,8 @@ import react from '@vitejs/plugin-react';
import path from 'path'; import path from 'path';
import { InlineConfig, createLogger } from 'vite'; import { InlineConfig, createLogger } from 'vite';
import { resolveConfigProperty } from '../../core/config';
import type { ViteBaseTask } from './types'; import type { ViteBaseTask } from './types';
import type { BuildContext } from '../../createBuildContext'; import type { BuildContext } from '../../createBuildContext';
@ -9,7 +11,7 @@ import type { BuildContext } from '../../createBuildContext';
* @internal * @internal
*/ */
const resolveViteConfig = (ctx: BuildContext, task: ViteBaseTask) => { const resolveViteConfig = (ctx: BuildContext, task: ViteBaseTask) => {
const { cwd, distPath, targets, external, extMap, pkg, config: packUpConfig } = ctx; const { cwd, distPath, targets, external, extMap, pkg } = ctx;
const { entries, format, output, runtime } = task; const { entries, format, output, runtime } = task;
const outputExt = extMap[pkg.type || 'commonjs'][format]; const outputExt = extMap[pkg.type || 'commonjs'][format];
const outDir = path.relative(cwd, distPath); const outDir = path.relative(cwd, distPath);
@ -28,8 +30,8 @@ const resolveViteConfig = (ctx: BuildContext, task: ViteBaseTask) => {
clearScreen: false, clearScreen: false,
customLogger, customLogger,
build: { build: {
minify: packUpConfig?.minify ?? false, minify: resolveConfigProperty(ctx.config.minify, false),
sourcemap: packUpConfig?.sourcemap ?? true, sourcemap: resolveConfigProperty(ctx.config.sourcemap, true),
/** /**
* The task runner will clear this for us * The task runner will clear this for us
*/ */
@ -50,6 +52,7 @@ const resolveViteConfig = (ctx: BuildContext, task: ViteBaseTask) => {
rollupOptions: { rollupOptions: {
external, external,
output: { output: {
preserveModules: resolveConfigProperty(ctx.config.preserveModules, false),
/** /**
* Mimic TypeScript's behavior, by setting the value to "auto" to control * Mimic TypeScript's behavior, by setting the value to "auto" to control
* how Rollup handles default, namespace and dynamic imports from external * how Rollup handles default, namespace and dynamic imports from external