From f29b0e02d739aebb2274a98691ae5556f9613217 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Thu, 30 Jun 2022 10:07:56 +0800 Subject: [PATCH] chore: enable swc externalHelpers when pre-compile --- packages/next/taskfile-swc.js | 8 ++++++-- packages/next/taskfile.js | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/next/taskfile-swc.js b/packages/next/taskfile-swc.js index 52e2ce34ccaa7..f7e8478798cb0 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 external helpers on server-side files build + // _is_native_funtion helper is not compatible with edge runtime (need investigate) + externalHelpers: false, parser: { syntax: 'typescript', dynamicImport: true, diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index fa8f54b68e711..baaba84ed31b6 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -95,6 +95,8 @@ const externals = { 'terser-webpack-plugin': 'next/dist/build/webpack/plugins/terser-webpack-plugin', + + // TODO: Add @swc/helpers to externals once @vercel/ncc switch to swc-loader } // eslint-disable-next-line camelcase externals['node-html-parser'] = 'next/dist/compiled/node-html-parser'