Skip to content

Commit

Permalink
feat: Create a package for backporting SWC minifier of next.js (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Jun 29, 2024
1 parent b8a04ef commit d096fdc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/next-swc-minifier-backport/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# @swc/next-minifier-backport

You can install `@swc/next-minifier-backport`, and set the environment variable `NEXT_SWC_MINIFY_BACKPORT` while running `next build`.

```bash
npm install @swc/next-minifier-backport
```

```bash

NEXT_SWC_MINIFY_BACKPORT=true next build
```
19 changes: 19 additions & 0 deletions packages/next-swc-minifier-backport/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const swc = require("@swc/core");

function patchOptions(options) {
return {
...options,
compress: {
...(options?.compress ?? {}),
inline: 2,
},
};
}

exports.minify = (src, options) => {
return swc.minify(src, patchOptions(options));
};

exports.minifySync = (src, options) => {
return swc.minifySync(src, patchOptions(options));
};
25 changes: 25 additions & 0 deletions packages/next-swc-minifier-backport/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@swc/next-minifier-backport",
"version": "0.1.0",
"description": "Backport SWC Minifier without the need to upgrade Next.js",
"main": "index.js",
"scripts": {},
"keywords": [
"next.js",
"swc",
"minifier"
],
"author": "강동윤 <kdy1997.dev@gmail.com>",
"bugs": {
"url": "https://github.com/swc-project/pkgs/issues"
},
"homepage": "https://swc.rs",
"license": "Apache-2.0",
"dependencies": {},
"devDependencies": {
"@swc/core": "^1.6.4"
},
"peerDependencies": {
"@swc/core": "^1.6.4"
}
}
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit d096fdc

Please sign in to comment.