import { type ManualChunksOption, type PreRenderedChunk } from 'rollup'; import { type PackageJson } from 'type-fest'; /** * One of the following: * cjs – CommonJS, suitable for Node and other bundlers * esm – Keep the bundle as an ES module file, suitable for other bundlers like webpack package.json {module:'esm/index.js'} * umd – Universal Module Definition, works as amd, cjs and iife all in one */ export type ForgeOutputFormat = 'cjs' | 'esm' | 'umd'; export interface ForgeOutputOption { /** * Specifies the format of the generated bundle. */ format: ForgeOutputFormat; /** * Specifies the dist folder name of the generated bundle. * normally it should be same with format 'esm'|'cjs'|'umd' */ distFolder: string; /** * If we need to clean folder of we plan build to; * @default true */ cleanDistFolder?: boolean; /** * Allows the creation of custom shared common chunks. * When using the object form, each property represents a chunk that contains the listed modules and all their dependencies if they are part of the module graph unless they are already in another manual chunk. The name of the chunk will be determined by the property key. * https://rollupjs.org/guide/en/#outputmanualchunks */ manualChunks?: ManualChunksOption; /** * The pattern to use for naming shared chunks created when code-splitting, or a function that is called per chunk to return such a pattern. * Patterns support the following placeholders, But: for library build maybe we need to set it to `[name].js` better to keep better readability * @default "[name]-[hash].js" */ chunkFileNames?: string | ((chunkInfo: PreRenderedChunk) => string); /** * The pattern to use for chunks created from entry points, or a function that is called per entry chunk to return such a pattern. * Patterns support the following placeholders: * [format]: The rendering format defined in the output options, e.g. es or cjs. * [hash]: A hash based only on the content of the final generated entry chunk, including transformations in renderChunk and any referenced file hashes. You can also set a specific hash length via e.g. [hash:10]. * [name]: The file name (without extension) of the entry point, unless the object form of input was used to define a different name. * @default "[name].js" */ entryFileNames?: string | ((chunkInfo: PreRenderedChunk) => string); /** * A string to prependto the bundle. */ banner?: string; /** * A string to append the bundle. */ footer?: string; /** * For script sourcemap only, it we need to sourceMap for style, we need to configure using * styling plugin of `@flatjs/forge-plugin-styling` * If true, a separate sourcemap file will be created. * If "inline", the sourcemap will be appended to the resulting output file as a data URI. */ sourcemap?: boolean | 'inline'; /** * By default, sourcemap files generated by Rollup uses relative URLs to reference the files they describe. * By providing an absolute base URL, e.g. https://example.com, sourcemaps will use absolute URLs instead. */ sourcemapBaseUrl?: string; /** * Preserve module structure, for ui components build (react), cause of each exported module has import `index.css` if have * we need set `preserveModules` to make sure compiled code has referenced another inner `module` with correct css `import` * Note: 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.Requires the output.dir option. */ preserveModules?: boolean; /** * A directory path to input modules that should be stripped away from output.dir path while output.preserveModules is true. */ preserveModulesRoot?: string; /** * A transformation to apply to each path in a sourcemap. * For instance the following will change all paths to be relative to the src directory. * @default `${`packageName`}/src/xxxx.ts` */ sourcemapPathTransform?: (pkgJson: PackageJson, projectCwd: string) => (relativeSourcePath: string, sourcemapPath: string) => string; /** * Necessary for iife/umd bundles that exports values in which case it is the global variable name representing your bundle. * Other scripts on the same page can use this variable name to access the exports of your bundle. * umd repo global moduleName. e.g. window['moduleName'] */ umdModuleName?: string; /** * Specifies id: variableName pairs necessary for external imports in umd/iife bundles. For example, in a case like this… * `import $ from 'jquery';` * if we want to tell Rollup that jquery is external and the jquery module ID equates to the global $ variable: * `globals: { jquery: '$' }` * ```ts * // rollup.config.js * export default { * ..., * external: ['jquery'], * output: { * format: 'iife', * name: 'MyBundle', * globals: { * jquery: '$' * } * } * }; *``` */ umdGlobals?: Record; /** * The Dependencies will be extracted into bundle files. * Note: that once our code use `modularImports` to pack the library code * The corresponding library code import might be `@dimjs/utils/esm/class-names` rather than `@dimjs/utils` * This will cause the `rollup` `external` not to be called, i.e. the `package.json` file of the corresponding directory cannot be found by `rollup` * This means require(`@dimjs/utils/esm/class-names`) is not a module, it is a file import. * This means that the configuration of BundledDependencies has no effect, which is correct. This means that some library bundle optimizations cannot be performed in `miniprogram` biz build. */ bundledDependencies?: Array; }