Skip to content

Commit dadb363

Browse files
committed
build: use swc minify for prod builds
1 parent 1c3327a commit dadb363

File tree

3 files changed

+150
-48
lines changed

3 files changed

+150
-48
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"@rollup/plugin-json": "^6.1.0",
6868
"@rollup/plugin-node-resolve": "^15.2.3",
6969
"@rollup/plugin-replace": "5.0.4",
70-
"@rollup/plugin-terser": "^0.4.4",
70+
"@swc/core": "^1.6.1",
7171
"@types/hash-sum": "^1.0.2",
7272
"@types/minimist": "^1.2.5",
7373
"@types/node": "^20.14.2",

pnpm-lock.yaml

+130-39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import pico from 'picocolors'
99
import commonJS from '@rollup/plugin-commonjs'
1010
import polyfillNode from 'rollup-plugin-polyfill-node'
1111
import { nodeResolve } from '@rollup/plugin-node-resolve'
12-
import terser from '@rollup/plugin-terser'
1312
import esbuild from 'rollup-plugin-esbuild'
1413
import alias from '@rollup/plugin-alias'
1514
import { entries } from './scripts/aliases.js'
1615
import { inlineEnums } from './scripts/inline-enums.js'
16+
import { minify as minifySwc } from '@swc/core'
1717

1818
/**
1919
* @template T
@@ -364,14 +364,25 @@ function createMinifiedConfig(/** @type {PackageFormat} */ format) {
364364
format: outputConfigs[format].format,
365365
},
366366
[
367-
terser({
368-
module: /^esm/.test(format),
369-
compress: {
370-
ecma: 2016,
371-
pure_getters: true,
367+
{
368+
name: 'swc-minify',
369+
370+
async renderChunk(
371+
contents,
372+
_,
373+
{ format, sourcemap, sourcemapExcludeSources },
374+
) {
375+
const { code, map } = await minifySwc(contents, {
376+
module: format === 'es',
377+
compress: true,
378+
mangle: true,
379+
sourceMap: !!sourcemap,
380+
inlineSourcesContent: !sourcemapExcludeSources,
381+
})
382+
383+
return { code, map: map || null }
372384
},
373-
safari10: true,
374-
}),
385+
},
375386
],
376387
)
377388
}

0 commit comments

Comments
 (0)