Skip to content

Commit 7b0118a

Browse files
authored
Disable core-js on Next.js core files as it's not transforming… (vercel#10193)
* Disable core-js on Next.js core files as it's not transforming anything important * Move babel options to taskr plugin * Disable transform-runtime for pages dir * Disable correctly * Disable corejs for core files * Temporarily check if this fixes the error
1 parent b6edf81 commit 7b0118a

File tree

3 files changed

+90
-81
lines changed

3 files changed

+90
-81
lines changed

packages/next/client/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'
2020
// So, we need to polyfill it.
2121
// See: https://webpack.js.org/guides/code-splitting/#dynamic-imports
2222
if (!window.Promise) {
23-
window.Promise = Promise
23+
window.Promise = require('@babel/runtime-corejs2/core-js/promise')
2424
}
2525

2626
const data = JSON.parse(document.getElementById('__NEXT_DATA__').textContent)

packages/next/taskfile-babel.js

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,84 @@
44
const extname = require('path').extname
55
const transform = require('@babel/core').transform
66

7+
const babelClientOpts = {
8+
presets: [
9+
'@babel/preset-typescript',
10+
[
11+
'@babel/preset-env',
12+
{
13+
modules: 'commonjs',
14+
targets: {
15+
esmodules: true,
16+
},
17+
loose: true,
18+
exclude: ['transform-typeof-symbol'],
19+
},
20+
],
21+
'@babel/preset-react',
22+
],
23+
plugins: [
24+
// workaround for @taskr/esnext bug replacing `-import` with `-require(`
25+
// eslint-disable-next-line no-useless-concat
26+
'@babel/plugin-syntax-dynamic-impor' + 't',
27+
['@babel/plugin-proposal-class-properties', { loose: true }],
28+
],
29+
}
30+
31+
const babelServerOpts = {
32+
presets: [
33+
'@babel/preset-typescript',
34+
'@babel/preset-react',
35+
[
36+
'@babel/preset-env',
37+
{
38+
modules: 'commonjs',
39+
targets: {
40+
node: '8.3',
41+
},
42+
loose: true,
43+
exclude: ['transform-typeof-symbol'],
44+
},
45+
],
46+
],
47+
plugins: [
48+
'@babel/plugin-proposal-optional-chaining',
49+
'@babel/plugin-proposal-nullish-coalescing-operator',
50+
'babel-plugin-dynamic-import-node',
51+
['@babel/plugin-proposal-class-properties', { loose: true }],
52+
],
53+
}
54+
755
module.exports = function(task) {
856
// eslint-disable-next-line require-yield
9-
task.plugin('babel', {}, function*(file, babelOpts, { stripExtension } = {}) {
57+
task.plugin('babel', {}, function*(
58+
file,
59+
serverOrClient,
60+
{ stripExtension } = {}
61+
) {
62+
// Don't compile .d.ts
63+
if (file.base.endsWith('.d.ts')) return
64+
65+
const babelOpts =
66+
serverOrClient === 'client' ? babelClientOpts : babelServerOpts
67+
1068
const options = {
1169
...babelOpts,
70+
plugins: [
71+
...babelOpts.plugins,
72+
// pages dir doesn't need core-js
73+
serverOrClient === 'client'
74+
? [
75+
'@babel/plugin-transform-runtime',
76+
{
77+
corejs: false,
78+
helpers: true,
79+
regenerator: false,
80+
useESModules: false,
81+
},
82+
]
83+
: false,
84+
].filter(Boolean),
1285
compact: true,
1386
babelrc: false,
1487
configFile: false,
@@ -17,8 +90,10 @@ module.exports = function(task) {
1790
const output = transform(file.data, options)
1891
const ext = extname(file.base)
1992

20-
// Include declaration files as they are
21-
if (file.base.endsWith('.d.ts')) return
93+
output.code = output.code.replace(
94+
/@babel\/runtime\//g,
95+
'@babel/runtime-corejs2/'
96+
)
2297

2398
// Replace `.ts|.tsx` with `.js` in files with an extension
2499
if (ext) {

packages/next/taskfile.js

Lines changed: 11 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,6 @@
11
const notifier = require('node-notifier')
22
const relative = require('path').relative
33

4-
const babelClientOpts = {
5-
presets: [
6-
'@babel/preset-typescript',
7-
[
8-
'@babel/preset-env',
9-
{
10-
modules: 'commonjs',
11-
targets: {
12-
esmodules: true,
13-
},
14-
loose: true,
15-
exclude: ['transform-typeof-symbol'],
16-
},
17-
],
18-
'@babel/preset-react',
19-
],
20-
plugins: [
21-
// workaround for @taskr/esnext bug replacing `-import` with `-require(`
22-
// eslint-disable-next-line no-useless-concat
23-
'@babel/plugin-syntax-dynamic-impor' + 't',
24-
['@babel/plugin-proposal-class-properties', { loose: true }],
25-
[
26-
'@babel/plugin-transform-runtime',
27-
{
28-
corejs: 2,
29-
helpers: true,
30-
regenerator: false,
31-
useESModules: false,
32-
},
33-
],
34-
],
35-
}
36-
37-
const babelServerOpts = {
38-
presets: [
39-
'@babel/preset-typescript',
40-
[
41-
'@babel/preset-env',
42-
{
43-
modules: 'commonjs',
44-
targets: {
45-
node: '8.3',
46-
},
47-
loose: true,
48-
exclude: ['transform-typeof-symbol'],
49-
},
50-
],
51-
],
52-
plugins: [
53-
'@babel/plugin-proposal-optional-chaining',
54-
'@babel/plugin-proposal-nullish-coalescing-operator',
55-
'babel-plugin-dynamic-import-node',
56-
['@babel/plugin-proposal-class-properties', { loose: true }],
57-
],
58-
}
59-
604
// eslint-disable-next-line camelcase
615
export async function ncc_arg(task, opts) {
626
await task
@@ -126,52 +70,47 @@ export async function compile(task) {
12670
export async function bin(task, opts) {
12771
await task
12872
.source(opts.src || 'bin/*')
129-
.babel(babelServerOpts, { stripExtension: true })
73+
.babel('server', { stripExtension: true })
13074
.target('dist/bin', { mode: '0755' })
13175
notify('Compiled binaries')
13276
}
13377

13478
export async function cli(task, opts) {
13579
await task
13680
.source(opts.src || 'cli/**/*.+(js|ts|tsx)')
137-
.babel(babelServerOpts)
81+
.babel('server')
13882
.target('dist/cli')
13983
notify('Compiled cli files')
14084
}
14185

14286
export async function lib(task, opts) {
14387
await task
14488
.source(opts.src || 'lib/**/*.+(js|ts|tsx)')
145-
.babel(babelServerOpts)
89+
.babel('server')
14690
.target('dist/lib')
14791
notify('Compiled lib files')
14892
}
14993

15094
export async function server(task, opts) {
151-
const babelOpts = {
152-
...babelServerOpts,
153-
// the /server files may use React
154-
presets: [...babelServerOpts.presets, '@babel/preset-react'],
155-
}
15695
await task
15796
.source(opts.src || 'server/**/*.+(js|ts|tsx)')
158-
.babel(babelOpts)
97+
.babel('server')
15998
.target('dist/server')
16099
notify('Compiled server files')
161100
}
162101

163102
export async function nextbuild(task, opts) {
164103
await task
165104
.source(opts.src || 'build/**/*.+(js|ts|tsx)')
166-
.babel(babelServerOpts)
105+
.babel('server')
167106
.target('dist/build')
168107
notify('Compiled build files')
169108
}
170109

171110
export async function client(task, opts) {
172111
await task
173112
.source(opts.src || 'client/**/*.+(js|ts|tsx)')
174-
.babel(babelClientOpts)
113+
.babel('client')
175114
.target('dist/client')
176115
notify('Compiled client files')
177116
}
@@ -180,34 +119,29 @@ export async function client(task, opts) {
180119
export async function nextbuildstatic(task, opts) {
181120
await task
182121
.source(opts.src || 'export/**/*.+(js|ts|tsx)')
183-
.babel(babelServerOpts)
122+
.babel('server')
184123
.target('dist/export')
185124
notify('Compiled export files')
186125
}
187126

188127
export async function pages_app(task) {
189128
await task
190129
.source('pages/_app.tsx')
191-
.babel(babelClientOpts)
130+
.babel('client')
192131
.target('dist/pages')
193132
}
194133

195134
export async function pages_error(task) {
196135
await task
197136
.source('pages/_error.tsx')
198-
.babel(babelClientOpts)
137+
.babel('client')
199138
.target('dist/pages')
200139
}
201140

202141
export async function pages_document(task) {
203-
const babelOpts = {
204-
...babelServerOpts,
205-
presets: [...babelServerOpts.presets, '@babel/preset-react'],
206-
}
207-
208142
await task
209143
.source('pages/_document.tsx')
210-
.babel(babelOpts)
144+
.babel('server')
211145
.target('dist/pages')
212146
}
213147

@@ -218,7 +152,7 @@ export async function pages(task, opts) {
218152
export async function telemetry(task, opts) {
219153
await task
220154
.source(opts.src || 'telemetry/**/*.+(js|ts|tsx)')
221-
.babel(babelServerOpts)
155+
.babel('server')
222156
.target('dist/telemetry')
223157
notify('Compiled telemetry files')
224158
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy