import type * as Rolldown from 'rolldown'; export interface RolldownOptions { cjs?: boolean; single_chunk?: boolean; split_modules?: boolean; dynamic_imports?: string[]; externals?: (string | RegExp)[]; globals?: Record; plugins?: (Rolldown.Plugin | Promise)[]; styles?: boolean; assets?: boolean; defines?: Record; production?: boolean | null; analyze?: boolean; print?: boolean; vue?: boolean; no_i18n?: boolean; } /** 通过 rolldown 从入口文件打包所有依赖生成单个 index.{mjs,cjs} 文件 - target: 目标环境 nodejs | web - fpd_root: 项目根目录 - fpd_out: 输出文件目录 - entries: 入口文件 Record<输出文件路径, 输入文件路径> - options?: - cjs?: `false` - single_chunk?: `true` 对于 await import(), 或者多个 entry 公用的部分, 不要创建分块,总是打包到一个 .js 中 - split_modules?: `false` node_modules 模块单独一个 deps.js chunk - dynamic_imports?: `undefined` 设置为 string[] 时可以只打包这些 await import() 动态导入的依赖 - externals?: string[] 或 RegExp[] 哪些导入模块不打包 - globals?: Record<包名, 全局变量名>, 替换模块为 globalThis 上的变量,避免打包 - plugins?: rolldown 插件 - styles?: `false` 加上 styles_plugin 插件,支持 .sass, .css 等样式导入 - assets?: `false` 加上 svg 插件,支持 .svg, .icon.svg, .png, 等资源导入为 data url - defines?: Record 定义如 process.env.NODE_ENV 的值为常数 - production?: `true` 如果设置了 true / false,则会定义 process.env.NODE_ENV 为 'production' / 'development' - analyze?: `false` 生成 stats.html 用于生成文件大小分析 - print?: `true` 打印生成的文件 - vue?: `false` 定义 __VUE_OPTIONS_API__ 等环境变量,且不处理 svg - no_i18n?: `false` 不引入 react i18next 国际化,替换 xshell/i18n/instance.js 为简单对象 @example await rolldown('web', 'D:/0/web/', 'T:/test/', { 'react.js': 'react.ts' }) */ export declare function rolldown(target: 'web' | 'nodejs', fpd_root: string, fpd_out: string, entries: Record, { cjs, single_chunk, split_modules, dynamic_imports: _dynamic_imports, externals, globals, plugins, styles, assets, production, defines, analyze, print, vue, no_i18n, }?: RolldownOptions): Promise; /** target web 时的 npm 包依赖管理 有 productions 但无 devs 时,大部分情况是相同配置,因此在 dev 模式下会用 productions 也可以手动设置 [ ] 禁用 fallback */ export interface Dependency { /** 项目隐含的子依赖 */ dependencies?: string[]; /** 开发环境依赖的 .js 文件 string 类型时为 node_modules 下的相对路径,输出到 {fpd_out}vendors/ 同样的相对路径 AssetOption 类型时见 {@link AssetOption} */ devs?: (string | AssetOption)[]; /** 生产环境依赖的 .js 文件 string 类型时为 node_modules 下的相对路径,输出到 {fpd_out}vendors/ 同样的相对路径 AssetOption 类型时见 {@link AssetOption} */ productions?: (string | AssetOption)[]; /** 需要直接复制到输出目录的资源 */ assets?: { productions: string[]; devs?: string[]; }; /** .map 代码映射 */ maps?: { productions?: (string | AssetOption)[]; devs?: (string | AssetOption)[]; }; } export type DependencyId = 'react' | 'lodash' | 'jquery' | 'xterm' | 'swiper' | 'plotly' | 'antd' | 'vscode-oniguruma' | 'antd-plots' | 'gridstack' | 'quill' | 'monaco' | 'echarts'; interface AssetOption { /** 相对 fpd_root 的路径,或者绝对路径 */ src: string; /** 相对 fpd_out 的路径,或者绝对路径,默认等于 src 的值 */ out?: string; /** 直接设置 html 的路径,强制覆盖 */ value?: string; } export declare function get_asset_out(asset: string | AssetOption): string; export declare function get_vendor_asset_out(asset: string | AssetOption): string; interface Assets { productions?: (string | AssetOption)[]; devs?: (string | AssetOption)[]; } export type HtmlsConfig = Record; export interface HtmlConfig { title: string; /** `index.js` 也可以设置 entries 中的其他项, 应填写相对于 fpd_out 的路径 */ entry?: string; device_viewport?: boolean; /** 也会在 copy_files 中一并被复制,应填写相对于 fpd_root 和 fpd_out 的路径 */ icon?: string | AssetOption; /** 仅用于生成 html 中 script 标签,文件复制由 copy_assets 的 dependencies 参数决定 */ dependencies?: DependencyId[]; manifest?: string | AssetOption; /** 额外需要在 head 加载的样式 */ styles?: (string | AssetOption)[]; /** 额外需要加载的脚本 */ scripts?: { /** 在 index.js 之前加载 */ before?: (string | AssetOption)[]; /** 在 index.js 之后加载 */ after?: (string | AssetOption)[]; /** 在 index.js 之后通过 defer 而非 module 加载 */ after_legacy?: (string | AssetOption)[]; }; heads?: string[]; notice?: boolean; } interface BuildHtmlOptions { assets_root?: string; template?: boolean; css?: boolean; print?: boolean; } export declare function build_htmls(fpd_out: string, production: boolean, htmls: HtmlsConfig, { print, assets_root, template, css, }?: BuildHtmlOptions): Promise; export declare function copy_assets(fpd_root: string, fpd_out: string, production: boolean, _dependencies: DependencyId[], htmls?: HtmlsConfig, assets?: Assets, source_map?: boolean, print?: { info: boolean; files: boolean; }): Promise; /** 解析依赖的文件 - dependencies: 依赖 id - assets: false 时只包括在 script 标签加载的文件; true 时包括 assets, maps 等 */ export declare function resolve_dependency_assets(_dependencies: DependencyId[], assets: boolean, production: boolean, source_map?: boolean): (string | AssetOption)[]; export {};