snapshot of https://github.com/dream-num/univer.git (dev, 2026-09-16; blobs > 131072B omitted)
Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
This commit is contained in:
58
common/shared/tsdown/configs/module.ts
Normal file
58
common/shared/tsdown/configs/module.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import type { UserConfig } from 'tsdown';
|
||||
import type { IEntryConfig } from '../types.ts';
|
||||
import { defineConfig } from 'tsdown';
|
||||
import { createCssNoopInputOptions } from '../plugins/css-noop.ts';
|
||||
import { createOutputAliasPlugin } from '../plugins/output-alias.ts';
|
||||
import { createOutputObfuscatorPlugin } from '../plugins/output-obfuscator.ts';
|
||||
|
||||
export type TModuleFormat = 'cjs' | 'esm';
|
||||
|
||||
export interface ICreateModuleConfigOptions {
|
||||
baseConfig: Partial<UserConfig>;
|
||||
enableObfuscation: boolean;
|
||||
entries: IEntryConfig[];
|
||||
externalPackages: string[];
|
||||
facadeExternalPackages: string[];
|
||||
format: TModuleFormat;
|
||||
obfuscatorIgnorePatterns?: RegExp[];
|
||||
outDir: string;
|
||||
packageDir: string;
|
||||
plugins: any[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the common ESM/CJS bundle config for a single package entry.
|
||||
*/
|
||||
export function createModuleConfig(options: ICreateModuleConfigOptions): UserConfig {
|
||||
const { baseConfig, enableObfuscation, entries, externalPackages, facadeExternalPackages, format, obfuscatorIgnorePatterns, outDir, packageDir, plugins } = options;
|
||||
const hasFacadeEntry = entries.some((entry) => entry.type === 'facade');
|
||||
const hasIndexEntry = entries.some((entry) => entry.type === 'index');
|
||||
const neverBundle = hasFacadeEntry ? facadeExternalPackages : externalPackages;
|
||||
const copyToRoot = format === 'esm';
|
||||
const keepRootIndexCss = hasIndexEntry && format === 'esm';
|
||||
|
||||
return defineConfig({
|
||||
...baseConfig,
|
||||
deps: {
|
||||
neverBundle,
|
||||
},
|
||||
dts: false,
|
||||
entry: Object.fromEntries(entries.map((entry) => [entry.key, entry.path])),
|
||||
format,
|
||||
inputOptions: keepRootIndexCss ? baseConfig.inputOptions : createCssNoopInputOptions(baseConfig.inputOptions),
|
||||
outputOptions: {
|
||||
codeSplitting: true,
|
||||
minify: enableObfuscation,
|
||||
},
|
||||
outDir,
|
||||
plugins: [
|
||||
...plugins,
|
||||
...(enableObfuscation ? [createOutputObfuscatorPlugin(obfuscatorIgnorePatterns)] : []),
|
||||
createOutputAliasPlugin({
|
||||
copyToRoot,
|
||||
keepRootIndexCss,
|
||||
packageDir,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user