Skip to content

Commit

Permalink
Enable externalHelpers when pre compiling Next.js' code (#37164)
Browse files Browse the repository at this point in the history
* chore: enable `externalHelpers` for pre-compile

* chore(devDeps): update @swc/core@1.2.203
  • Loading branch information
SukkaW committed Jun 19, 2022
1 parent e05c31d commit 4671010
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 51 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -67,7 +67,7 @@
"@next/swc": "workspace:*",
"@svgr/webpack": "5.5.0",
"@swc/cli": "0.1.55",
"@swc/core": "1.2.148",
"@swc/core": "1.2.203",
"@swc/helpers": "0.3.17",
"@testing-library/react": "13.0.0",
"@types/cheerio": "0.22.16",
Expand Down
8 changes: 6 additions & 2 deletions packages/next/taskfile-swc.js
Expand Up @@ -25,14 +25,15 @@ module.exports = function (task) {

const isClient = serverOrClient === 'client'

/** @type {import('@swc/core').Options} */
const swcClientOptions = {
module: {
type: 'commonjs',
ignoreDynamic: true,
},
jsc: {
loose: true,

externalHelpers: true,
target: 'es2016',
parser: {
syntax: 'typescript',
Expand All @@ -55,6 +56,7 @@ module.exports = function (task) {
},
}

/** @type {import('@swc/core').Options} */
const swcServerOptions = {
module: {
type: 'commonjs',
Expand All @@ -67,7 +69,9 @@ module.exports = function (task) {
},
jsc: {
loose: true,

// Do not enable externalHelpers for server-side code
// "_is_native_function.mjs" helper is not compatible with edge runtime
externalHelpers: false,
parser: {
syntax: 'typescript',
dynamicImport: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/next/taskfile.js
Expand Up @@ -1956,7 +1956,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 @@ -1966,7 +1966,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
92 changes: 46 additions & 46 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 4671010

Please sign in to comment.