Skip to content

Commit

Permalink
build: use swc minify for prod builds
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 18, 2024
1 parent 1c3327a commit dadb363
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "5.0.4",
"@rollup/plugin-terser": "^0.4.4",
"@swc/core": "^1.6.1",
"@types/hash-sum": "^1.0.2",
"@types/minimist": "^1.2.5",
"@types/node": "^20.14.2",
Expand Down
169 changes: 130 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 19 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import pico from 'picocolors'
import commonJS from '@rollup/plugin-commonjs'
import polyfillNode from 'rollup-plugin-polyfill-node'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import esbuild from 'rollup-plugin-esbuild'
import alias from '@rollup/plugin-alias'
import { entries } from './scripts/aliases.js'
import { inlineEnums } from './scripts/inline-enums.js'
import { minify as minifySwc } from '@swc/core'

/**
* @template T
Expand Down Expand Up @@ -364,14 +364,25 @@ function createMinifiedConfig(/** @type {PackageFormat} */ format) {
format: outputConfigs[format].format,
},
[
terser({
module: /^esm/.test(format),
compress: {
ecma: 2016,
pure_getters: true,
{
name: 'swc-minify',

async renderChunk(
contents,
_,
{ format, sourcemap, sourcemapExcludeSources },
) {
const { code, map } = await minifySwc(contents, {
module: format === 'es',
compress: true,
mangle: true,
sourceMap: !!sourcemap,
inlineSourcesContent: !sourcemapExcludeSources,
})

return { code, map: map || null }
},
safari10: true,
}),
},
],
)
}

0 comments on commit dadb363

Please sign in to comment.