(
config: UserConfig,
projectDir: string,
name: string,
entry: string,
options: EsmOptions = {}
)
| 285 | } |
| 286 | |
| 287 | export function esm( |
| 288 | config: UserConfig, |
| 289 | projectDir: string, |
| 290 | name: string, |
| 291 | entry: string, |
| 292 | options: EsmOptions = {} |
| 293 | ) { |
| 294 | const { withMin = true } = options; |
| 295 | |
| 296 | const lib = config.build!.lib! as LibraryOptions; |
| 297 | const libEntry = lib.entry! as Record<string, string>; |
| 298 | libEntry[name] = path.resolve(projectDir, entry); |
| 299 | |
| 300 | const output = config.build!.rollupOptions!.output as OutputOptions[]; |
| 301 | if (!output.some(o => o.format === 'es')) { |
| 302 | output.push({ |
| 303 | globals: { |
| 304 | jQuery: 'jQuery' |
| 305 | }, |
| 306 | dir: 'dist/', |
| 307 | format: 'es', |
| 308 | entryFileNames: '[name].mjs', |
| 309 | chunkFileNames: '[name].mjs' |
| 310 | }); |
| 311 | } |
| 312 | |
| 313 | if (withMin) { |
| 314 | for (const o of output) { |
| 315 | o.plugins ??= []; |
| 316 | (o.plugins as OutputPlugin[]).push(min(terserOptions)); |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | export function defineEsmCjsLibConfig(setup?: (config: UserConfig) => void) { |
| 322 | return defineEsmLibConfig(config => { |
no test coverage detected