From c3e880f025591df69f56a729135bc5bb85fbbb4b Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 8 Jun 2022 18:24:20 +0800 Subject: [PATCH] chore: enable externalHelpers for precompile client code --- packages/next/taskfile-swc.js | 8 ++++++-- packages/next/taskfile.js | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/next/taskfile-swc.js b/packages/next/taskfile-swc.js index 52e2ce34ccaa7..bbef1fab59855 100644 --- a/packages/next/taskfile-swc.js +++ b/packages/next/taskfile-swc.js @@ -25,6 +25,7 @@ module.exports = function (task) { const isClient = serverOrClient === 'client' + /** @type {import('@swc/core').Options} */ const swcClientOptions = { module: { type: 'commonjs', @@ -32,7 +33,7 @@ module.exports = function (task) { }, jsc: { loose: true, - + externalHelpers: true, target: 'es2016', parser: { syntax: 'typescript', @@ -55,6 +56,7 @@ module.exports = function (task) { }, } + /** @type {import('@swc/core').Options} */ const swcServerOptions = { module: { type: 'commonjs', @@ -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, diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index b90e92f8b8ec6..169873b4af970 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -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' @@ -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') } @@ -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') }