Skip to content

Commit

Permalink
chore: enable externalHelpers for precompile client code
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jun 8, 2022
1 parent ccb155e commit c3e880f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/next/taskfile-swc.js
Original file line number Diff line number Diff line change
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
// @swc/helpers/_is_native_function.js is not compatible with edge-runtime
externalHelpers: false,
parser: {
syntax: 'typescript',
dynamicImport: true,
Expand Down
10 changes: 8 additions & 2 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ const externals = {

'terser-webpack-plugin':
'next/dist/build/webpack/plugins/terser-webpack-plugin',

/**
* TODO: add @swc/helpers as once ncc replaces ts-loader
* with swc-loader and externalHelpers becomes an option:
* https://github.com/vercel/ncc/pull/926/
*/
}
// eslint-disable-next-line camelcase
externals['node-html-parser'] = 'next/dist/compiled/node-html-parser'
Expand Down Expand Up @@ -1956,7 +1962,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 +1972,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 c3e880f

Please sign in to comment.