Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create a package for backporting SWC minifier of next.js #47

Merged
merged 8 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "강동윤 <[email protected]>",
"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.

Loading