Skip to content

Commit

Permalink
fix(#38106): use swc client config to pre-compile shared lib (#38137)
Browse files Browse the repository at this point in the history
## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes #38106.

Currently, the `shared/lib` directory (**which will also be shipped to legacy browsers**) is precompiled under `swcServerOptions`, which targets Node.js 12 and is way too modern:

- The public class field syntax is only supported since Chrome 72, Firefox 69, Edge 79, and Safari 14.1.
- Webpack currently doesn't support the public class field syntax as well (which causes the issue #38106)
- `async/await` syntax is also supported in Node.js 12 but not in the legacy browsers.

The PR fixes the issue by pre-compiling the `shared/lib` directory using `swcClientOptions` (which targets the ES5).

Note:

- The only way to validate the fix is to run an integration test case on a legacy browser.
- The output size is increased by a little. But the size impact can be minimized by enabling `@swc/helpers` (which I will bring up in the next PR)
  • Loading branch information
SukkaW committed Jun 29, 2022
1 parent 6d8a234 commit 55769e2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ export async function shared(task, opts) {
.source(
opts.src || 'shared/**/!(amp|config|constants|dynamic|head).+(js|ts|tsx)'
)
.swc('server', { dev: opts.dev })
.swc('client', { dev: opts.dev })
.target('dist/shared')
notify('Compiled shared files')
}
Expand All @@ -1999,7 +1999,7 @@ export async function shared_re_exported(task, opts) {
.source(
opts.src || 'shared/**/{amp,config,constants,dynamic,head}.+(js|ts|tsx)'
)
.swc('server', { dev: opts.dev, interopClientDefaultExport: true })
.swc('client', { dev: opts.dev, interopClientDefaultExport: true })
.target('dist/shared')
notify('Compiled shared re-exported files')
}
Expand Down

0 comments on commit 55769e2

Please sign in to comment.