(options: MinifyOptions)
| 4 | import { type MinifyOptions, minify } from 'terser'; |
| 5 | |
| 6 | export default function min(options: MinifyOptions): OutputPlugin { |
| 7 | return { |
| 8 | name: 'min', |
| 9 | async writeBundle(opts, bundle) { |
| 10 | const files = Object.keys(bundle); |
| 11 | |
| 12 | for (const file of files) { |
| 13 | const chunk = bundle[file]; |
| 14 | if ((file.endsWith('.mjs') || file.endsWith('.js')) && chunk.type === 'chunk' && chunk.isEntry) { |
| 15 | this.info(`Creating min file for bundle ${file}`); |
| 16 | |
| 17 | const o = { ...options }; |
| 18 | if (opts.format === 'es') { |
| 19 | o.module = true; |
| 20 | } else if (opts.format === 'cjs') { |
| 21 | o.toplevel = true; |
| 22 | } |
| 23 | |
| 24 | const min = await minify(chunk.code, o); |
| 25 | const outputFile = path.resolve( |
| 26 | opts.dir!, |
| 27 | file.replace('.mjs', '.min.mjs').replace('.js', '.min.js') |
| 28 | ); |
| 29 | await fs.promises.writeFile(outputFile, min.code!); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | }; |
| 34 | } |
no outgoing calls
no test coverage detected