import * as swc from '@swc/core'; import type { RollupOptions, SourceMapInput, ModuleJSON, RollupOutput } from 'rollup'; import type { Context as _Context, PluginAPI as _PluginAPI, Plugin as _Plugin, TaskConfig as _BuildTask } from 'build-scripts'; import type { Config } from '@swc/core'; import type stylesPlugin from 'rollup-plugin-styles'; import type { FSWatcher } from 'chokidar'; import cssnano from 'cssnano'; import { TransformOptions } from '@babel/core'; export type StylesRollupPluginOptions = Parameters[0]; export type PlainObject = Record; type JSMinify = boolean | { options?: swc.JsMinifyOptions; }; type CSSMinify = boolean | { options?: Parameters[0]; }; export interface TransformUserConfig { /** * Which type of contents would be generated * "cjs" - Commonjs with ES5 syntax (targeting Node version under 12); * "esm" - ES Module with ES5 syntax (legacy outputs); * "es2017" - ES Module with ES2017 (targeting modern browsers and Node version upon 12) * @default ['esm', 'es2017'] */ formats?: Array<'cjs' | 'esm' | 'es2017'>; /** * Exclude all files matching any of those conditions. * - `string` to match any paths by `minimatch` glob patterns * - An `array` to match at least one of the conditions * @see https://github.com/isaacs/minimatch */ excludes?: string | string[]; } export interface BundleUserConfig { /** * Export name * @default package.name */ name?: string; /** * Output directory * @default 'dist' */ outputDir?: string; /** * @deprecated Please use `bundle.modes` config. * Generate uncompressed bundle for development debug. */ development?: boolean; /** * Node env modes. For example: 'production', 'development' * @default ['production'] */ modes?: NodeEnvMode[]; /** * Which type of contents would be generated * "umd" * "esm" * "cjs" * "es2017" * @default ['esm','es2017'] */ formats?: Array<'umd' | 'esm' | 'cjs' | 'es2017'>; /** * Specify external dependencies. * "boolean" - whether to bundle all dependencies or not; * "object" - specific external dependencies. * @default false All of dependencies will be bundled by default. */ externals?: boolean | Record; /** * Minify JS and CSS bundle. */ minify?: boolean | { js?: boolean | ((mode: string, command: string) => JSMinify); css?: boolean | ((mode: string, command: string) => CSSMinify); }; /** * Weather or not add the polyfill to the code. * @default ['usage'] * * In the next version(v2), the value of polyfill will be `false`. */ polyfill?: false | 'entry' | 'usage'; /** * Weather or not compile the dependencies in node_modules. */ compileDependencies?: boolean | Array; /** * Resolve node module by prefer using `browser` field in package.json. */ browser?: boolean; } export interface UserConfig { /** * Entry for a task * @default `./src/index` */ entry?: RollupOptions['input']; /** * Alias to file system paths * @default {} */ alias?: Record; /** * Define global constant replacements */ define?: PlainObject; /** * - true to generate a sourcemap for the code and include it in the result object. * - "inline" to generate a sourcemap and append it as a data URL to the end of the code, * but not include it in the result object. */ sourceMaps?: boolean | 'inline'; /** * Whether or not to generate declaration files for Ecmascript * @default false */ generateTypesForJs?: boolean; /** * Generate .d.ts files from TypeScript files in your project. * @default true */ declaration?: boolean; /** * Configure JSX transform type. * @default 'automatic' */ jsxRuntime?: 'automatic' | 'classic'; /** * Plugins of build scripts * @default [] */ plugins?: Array; /** * "transform mode" means transform files one by one */ transform?: TransformUserConfig; /** * "bundle mode" means bundle everything up by using Rollup */ bundle?: BundleUserConfig; } interface _TaskConfig { /** * Entry for a task * @default `./src/index` */ entry?: RollupOptions['input']; /** * Output directory */ outputDir?: string; /** * Define global constant replacements */ define?: PlainObject; /** * - true to generate a sourcemap for the code and include it in the result object. * - "inline" to generate a sourcemap and append it as a data URL to the end of the code, * but not include it in the result object. */ sourcemap?: boolean | 'inline'; /** * Alias to file system paths */ alias?: Record; /** * JSX transform type. */ jsxRuntime?: 'automatic' | 'classic'; /** * Modify default rollup options * @see https://rollupjs.org/guide/en/#rolluprollup */ modifyRollupOptions?: Array<(rollupOptions: RollupOptions) => RollupOptions>; /** * Configure extra swc compile options. * @see https://swc.rs/docs/configuration/compilation */ swcCompileOptions?: Config; /** * Modify inner swc compile options. * @see https://swc.rs/docs/configuration/compilation */ modifySwcCompileOptions?: (swcCompileOptions: Config) => Config; /** * Extra babel plugins */ babelPlugins?: babel.PluginItem[]; /** * Modify default babel options * @see https://babeljs.io/docs/options */ modifyBabelOptions?: (babelCompileOptions: TransformOptions) => TransformOptions; } export interface BundleTaskConfig extends _TaskConfig, Omit { type: 'bundle'; /** * Files extensions * @see https://www.npmjs.com/package/@rollup/plugin-node-resolve */ extensions?: string[]; /** * Config styles options. See https://www.npmjs.com/package/rollup-plugin-styles */ modifyStylesOptions?: Array<(options: StylesRollupPluginOptions) => StylesRollupPluginOptions>; jsMinify?: (mode: string, command: string) => JSMinify; cssMinify?: (mode: string, command: string) => CSSMinify; vendorName?: string; } export interface TransformTaskConfig extends _TaskConfig, TransformUserConfig { type: 'transform'; /** * Node env modes. For example: 'production', 'development' * @default `['development']` on start, `['production']` on build. */ modes?: NodeEnvMode[]; /** * Same as https://swc.rs/docs/configuration/compilation#jsctransformoptimizerglobals */ define?: Record; } export type TaskConfig = BundleTaskConfig | TransformTaskConfig; export type BuildTask = _BuildTask; export type Context = _Context; export type PluginAPI = _PluginAPI; /** * @deprecated Please use PluginAPI instead. */ export type PkgPluginAPI = PluginAPI; export type Plugin = _Plugin; /** * @deprecated Please use Plugin instead. */ export type PkgPlugin = Plugin; export declare enum TaskName { 'TRANSFORM_CJS' = "transform-cjs", 'TRANSFORM_ESM' = "transform-esm", 'TRANSFORM_ES2017' = "transform-es2017", 'BUNDLE_ES5' = "bundle-es5", 'BUNDLE_ES2017' = "bundle-es2017" } type TaskKey = keyof typeof TaskName; export type TaskValue = typeof TaskName[TaskKey]; export interface OutputFile { filePath?: string; absolutePath?: string; ext?: string; dest?: string; filename?: string; code?: string | Uint8Array; map?: string | SourceMapInput; } export interface OutputResult { taskName: string; outputFiles: OutputFile[]; modules?: ModuleJSON[]; outputs?: Array; } export type NodeEnvMode = 'development' | 'production' | string; export type WatchEvent = 'create' | 'update' | 'delete'; export interface WatchChangedFile { path: string; event: WatchEvent; } export type HandleChange = (changedFiles: WatchChangedFile[]) => Promise; export interface TaskResult { handleChange?: HandleChange; outputResults: OutputResult[]; } export interface TaskRunnerContext { mode: NodeEnvMode; buildTask: BuildTask; } export type RunTasks = (taskOptionsList: Array<[RollupOptions, TaskRunnerContext]>, context: Context, watcher?: FSWatcher) => Promise; export {};