Skip to content

Commit

Permalink
Publish packages (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
DuCanhGH authored Jun 30, 2023
1 parent 4d13948 commit c05c014
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
7 changes: 0 additions & 7 deletions .changeset/friendly-rice-attack.md

This file was deleted.

8 changes: 8 additions & 0 deletions packages/next-pwa/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @ducanh2912/next-pwa

## 9.1.3

### Patch Changes

- [`4d13948`](https://github.com/DuCanhGH/next-pwa/commit/4d13948375d144a89bed858d36aee561bc987ca4) Thanks [@DuCanhGH](https://github.com/DuCanhGH)! - fix(next-pwa): fixed swc-minify crashing build when all swc sources can't be resolved

- The new behaviour should now be using `terser-webpack-plugin`'s `terserMinify` when they can't be found.

## 9.1.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/next-pwa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ducanh2912/next-pwa",
"version": "9.1.2",
"version": "9.1.3",
"type": "module",
"description": "PWA for Next.js, powered by Workbox.",
"repository": "https://github.com/DuCanhGH/next-pwa",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/resolve-swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Compiler } from "@swc/core";
export const resolveSwc = () => {
let swc: Compiler | undefined;

for (const swcSource of ["next/dist/build/swc", "@swc/core"]) {
for (const swcSource of ["@swc/core", "next/dist/build/swc"]) {
try {
swc = require(swcSource);
break;
Expand Down
15 changes: 12 additions & 3 deletions packages/utils/src/swc-minify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,23 @@ export const swcMinify = async (
};
};

const fallbackToTerser = () => {
return (
require("terser-webpack-plugin") as typeof TerserWebpack
).terserMinify(input, sourceMap, minimizerOptions, false);
};

let swc: Compiler;
try {
swc = resolveSwc();
} catch {
// swc might not be available, fallback to terser
return (
require("terser-webpack-plugin") as typeof TerserWebpack
).terserMinify(input, sourceMap, minimizerOptions, false);
return fallbackToTerser();
}

if (!swc.minify) {
// turns out that older versions of Next had `next/dist/build/swc` with no `swc.minify`...
return fallbackToTerser();
}

// Copy `swc` options
Expand Down

0 comments on commit c05c014

Please sign in to comment.