Unverified Commit 64850a83 authored by Guy Bedford's avatar Guy Bedford Committed by GitHub

ncc Babel inlining (#18768)

This adds inlining for Babel and the Babel plugins used in next.

This is based to the PR at https://github.com/vercel/next.js/pull/18823.

The approach is to make one large bundle and then separate out the individual packages from that in order to avoid duplications.

In the first attempt the Babel bundle size was 10MB... using "resolutions" in the Yarn workspace to reduce the duplicated packages this was brought down to a 2.8MB bundle for Babel and all the used plugins which is exactly the expected file size here.

This will thus add a 2.8MB download size to the next package, but save downloading any babel dependencies separately, removing a large number of package dependencies from the overall install.
parent 596ee9c1
...@@ -37,9 +37,9 @@ ...@@ -37,9 +37,9 @@
}, },
"pre-commit": "lint-staged", "pre-commit": "lint-staged",
"devDependencies": { "devDependencies": {
"@babel/plugin-proposal-object-rest-spread": "7.11.0", "@babel/plugin-proposal-object-rest-spread": "7.12.1",
"@babel/preset-flow": "7.10.4", "@babel/preset-flow": "7.10.4",
"@babel/preset-react": "7.10.4", "@babel/preset-react": "7.12.5",
"@fullhuman/postcss-purgecss": "1.3.0", "@fullhuman/postcss-purgecss": "1.3.0",
"@mdx-js/loader": "0.18.0", "@mdx-js/loader": "0.18.0",
"@types/cheerio": "0.22.16", "@types/cheerio": "0.22.16",
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
"shell-quote": "1.7.2", "shell-quote": "1.7.2",
"spectron": "^7.0.0", "spectron": "^7.0.0",
"styled-components": "5.1.0", "styled-components": "5.1.0",
"styled-jsx-plugin-postcss": "2.0.1", "styled-jsx-plugin-postcss": "3.0.2",
"tailwindcss": "1.1.3", "tailwindcss": "1.1.3",
"taskr": "1.1.0", "taskr": "1.1.0",
"tree-kill": "1.2.2", "tree-kill": "1.2.2",
......
import { NodePath, PluginObj, types } from '@babel/core' import { NodePath, PluginObj, types } from 'next/dist/compiled/babel/core'
export default function AmpAttributePatcher(): PluginObj { export default function AmpAttributePatcher(): PluginObj {
return { return {
......
import { NodePath, PluginObj, types } from '@babel/core' import { NodePath, PluginObj, types } from 'next/dist/compiled/babel/core'
import commonjsPlugin from '@babel/plugin-transform-modules-commonjs' import commonjsPlugin from 'next/dist/compiled/babel/plugin-transform-modules-commonjs'
// Rewrite imports using next/<something> to next-server/<something> // Rewrite imports using next/<something> to next-server/<something>
export default function NextToNextServer(...args: any): PluginObj { export default function NextToNextServer(...args: any): PluginObj {
......
import { NodePath, PluginObj, types as BabelTypes } from '@babel/core' import {
import jsx from '@babel/plugin-syntax-jsx' NodePath,
PluginObj,
types as BabelTypes,
} from 'next/dist/compiled/babel/core'
import jsx from 'next/dist/compiled/babel/plugin-syntax-jsx'
export default function ({ export default function ({
types: t, types: t,
......
import { NodePath, PluginObj, types as BabelTypes } from '@babel/core' import {
NodePath,
PluginObj,
types as BabelTypes,
} from 'next/dist/compiled/babel/core'
export default function ({ export default function ({
types: t, types: t,
......
import { NodePath, PluginObj, types as BabelTypes } from '@babel/core' import {
NodePath,
PluginObj,
types as BabelTypes,
} from 'next/dist/compiled/babel/core'
import { PageConfig } from 'next/types' import { PageConfig } from 'next/types'
import { STRING_LITERAL_DROP_BUNDLE } from '../../../next-server/lib/constants' import { STRING_LITERAL_DROP_BUNDLE } from '../../../next-server/lib/constants'
...@@ -77,9 +81,12 @@ export default function nextPageConfig({ ...@@ -77,9 +81,12 @@ export default function nextPageConfig({
} }
const config: PageConfig = {} const config: PageConfig = {}
const declarations = [ const declarations: BabelTypes.VariableDeclarator[] = [
...(exportPath.node.declaration?.declarations || []), ...((exportPath.node
exportPath.scope.getBinding(CONFIG_KEY)?.path.node, .declaration as BabelTypes.VariableDeclaration)
?.declarations || []),
exportPath.scope.getBinding(CONFIG_KEY)?.path
.node as BabelTypes.VariableDeclarator,
].filter(Boolean) ].filter(Boolean)
for (const specifier of exportPath.node.specifiers) { for (const specifier of exportPath.node.specifiers) {
...@@ -147,7 +154,7 @@ export default function nextPageConfig({ ...@@ -147,7 +154,7 @@ export default function nextPageConfig({
) )
) )
} }
const { name } = prop.key const { name } = prop.key as BabelTypes.Identifier
if (BabelTypes.isIdentifier(prop.key, { name: 'amp' })) { if (BabelTypes.isIdentifier(prop.key, { name: 'amp' })) {
if (!BabelTypes.isObjectProperty(prop)) { if (!BabelTypes.isObjectProperty(prop)) {
throw new Error( throw new Error(
......
import { NodePath, PluginObj, types } from '@babel/core' import { NodePath, PluginObj, types } from 'next/dist/compiled/babel/core'
export default function NextPageDisallowReExportAllExports(): PluginObj<any> { export default function NextPageDisallowReExportAllExports(): PluginObj<any> {
return { return {
......
import { NodePath, PluginObj, types as BabelTypes } from '@babel/core' import {
NodePath,
PluginObj,
types as BabelTypes,
} from 'next/dist/compiled/babel/core'
import { SERVER_PROPS_SSG_CONFLICT } from '../../../lib/constants' import { SERVER_PROPS_SSG_CONFLICT } from '../../../lib/constants'
import { import {
SERVER_PROPS_ID, SERVER_PROPS_ID,
......
import { PluginObj, types as BabelTypes } from '@babel/core' import { PluginObj, types as BabelTypes } from 'next/dist/compiled/babel/core'
import chalk from 'next/dist/compiled/chalk' import chalk from 'next/dist/compiled/chalk'
export default function NoAnonymousDefaultExport({ export default function NoAnonymousDefaultExport({
......
import { NodePath, PluginObj, types as BabelTypes } from '@babel/core' import {
NodePath,
PluginObj,
types as BabelTypes,
} from 'next/dist/compiled/babel/core'
// matches any hook-like (the default) // matches any hook-like (the default)
const isHook = /^use[A-Z]/ const isHook = /^use[A-Z]/
......
...@@ -23,7 +23,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWAR ...@@ -23,7 +23,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWAR
// Modified to put `webpack` and `modules` under `loadableGenerated` to be backwards compatible with next/dynamic which has a `modules` key // Modified to put `webpack` and `modules` under `loadableGenerated` to be backwards compatible with next/dynamic which has a `modules` key
// Modified to support `dynamic(import('something'))` and `dynamic(import('something'), options) // Modified to support `dynamic(import('something'))` and `dynamic(import('something'), options)
import { NodePath, PluginObj, types as BabelTypes } from '@babel/core' import {
NodePath,
PluginObj,
types as BabelTypes,
} from 'next/dist/compiled/babel/core'
export default function ({ export default function ({
types: t, types: t,
......
import { PluginItem } from '@babel/core' import { PluginItem } from 'next/dist/compiled/babel/core'
const env = process.env.NODE_ENV const env = process.env.NODE_ENV
const isProduction = env === 'production' const isProduction = env === 'production'
const isDevelopment = env === 'development' const isDevelopment = env === 'development'
...@@ -111,11 +111,11 @@ module.exports = ( ...@@ -111,11 +111,11 @@ module.exports = (
sourceType: 'unambiguous', sourceType: 'unambiguous',
presets: [ presets: [
customModernPreset || [ customModernPreset || [
require('@babel/preset-env').default, require('next/dist/compiled/babel/preset-env'),
presetEnvConfig, presetEnvConfig,
], ],
[ [
require('@babel/preset-react'), require('next/dist/compiled/babel/preset-react'),
{ {
// This adds @babel/plugin-transform-react-jsx-source and // This adds @babel/plugin-transform-react-jsx-source and
// @babel/plugin-transform-react-jsx-self automatically in development // @babel/plugin-transform-react-jsx-self automatically in development
...@@ -125,7 +125,7 @@ module.exports = ( ...@@ -125,7 +125,7 @@ module.exports = (
}, },
], ],
[ [
require('@babel/preset-typescript'), require('next/dist/compiled/babel/preset-typescript'),
{ allowNamespaces: true, ...options['preset-typescript'] }, { allowNamespaces: true, ...options['preset-typescript'] },
], ],
], ],
...@@ -149,20 +149,20 @@ module.exports = ( ...@@ -149,20 +149,20 @@ module.exports = (
lib: true, lib: true,
}, },
], ],
require('@babel/plugin-syntax-dynamic-import'), require('next/dist/compiled/babel/plugin-syntax-dynamic-import'),
require('./plugins/react-loadable-plugin'), require('./plugins/react-loadable-plugin'),
[ [
require('@babel/plugin-proposal-class-properties'), require('next/dist/compiled/babel/plugin-proposal-class-properties'),
options['class-properties'] || {}, options['class-properties'] || {},
], ],
[ [
require('@babel/plugin-proposal-object-rest-spread'), require('next/dist/compiled/babel/plugin-proposal-object-rest-spread'),
{ {
useBuiltIns: true, useBuiltIns: true,
}, },
], ],
!isServer && [ !isServer && [
require('@babel/plugin-transform-runtime'), require('next/dist/compiled/babel/plugin-transform-runtime'),
{ {
corejs: false, corejs: false,
helpers: true, helpers: true,
...@@ -185,11 +185,11 @@ module.exports = ( ...@@ -185,11 +185,11 @@ module.exports = (
removeImport: true, removeImport: true,
}, },
], ],
isServer && require('@babel/plugin-syntax-bigint'), isServer && require('next/dist/compiled/babel/plugin-syntax-bigint'),
// Always compile numeric separator because the resulting number is // Always compile numeric separator because the resulting number is
// smaller. // smaller.
require('@babel/plugin-proposal-numeric-separator'), require('next/dist/compiled/babel/plugin-proposal-numeric-separator'),
require('@babel/plugin-proposal-export-namespace-from'), require('next/dist/compiled/babel/plugin-proposal-export-namespace-from'),
].filter(Boolean), ].filter(Boolean),
} }
} }
import { codeFrameColumns } from '@babel/code-frame' import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'
import ReactRefreshWebpackPlugin from '@next/react-refresh-utils/ReactRefreshWebpackPlugin' import ReactRefreshWebpackPlugin from '@next/react-refresh-utils/ReactRefreshWebpackPlugin'
import crypto from 'crypto' import crypto from 'crypto'
import { readFileSync, realpathSync } from 'fs' import { readFileSync, realpathSync } from 'fs'
......
...@@ -45,7 +45,7 @@ module.exports = babelLoader.custom((babel) => { ...@@ -45,7 +45,7 @@ module.exports = babelLoader.custom((babel) => {
{ type: 'plugin' } { type: 'plugin' }
) )
const commonJsItem = babel.createConfigItem( const commonJsItem = babel.createConfigItem(
require('@babel/plugin-transform-modules-commonjs'), require('next/dist/compiled/babel/plugin-transform-modules-commonjs'),
{ type: 'plugin' } { type: 'plugin' }
) )
......
...@@ -164,7 +164,7 @@ export class NextEsmPlugin implements Plugin { ...@@ -164,7 +164,7 @@ export class NextEsmPlugin implements Plugin {
if (IS_PRESET_ENV.test(name)) { if (IS_PRESET_ENV.test(name)) {
presets.push([ presets.push([
require.resolve('@babel/preset-env'), require('next/dist/compiled/babel/preset-env'),
{ {
bugfixes: true, bugfixes: true,
loose: true, loose: true,
......
import { codeFrameColumns } from '@babel/code-frame' import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'
import Chalk from 'next/dist/compiled/chalk' import Chalk from 'next/dist/compiled/chalk'
import { SimpleWebpackError } from './simpleWebpackError' import { SimpleWebpackError } from './simpleWebpackError'
......
/* eslint-disable import/no-extraneous-dependencies */
function codeFrame() {
return require('@babel/code-frame')
}
function core() {
return require('@babel/core')
}
function pluginProposalClassProperties() {
return require('@babel/plugin-proposal-class-properties')
}
function pluginProposalExportNamespaceFrom() {
return require('@babel/plugin-proposal-export-namespace-from')
}
function pluginProposalNumericSeparator() {
return require('@babel/plugin-proposal-numeric-separator')
}
function pluginProposalObjectRestSpread() {
return require('@babel/plugin-proposal-object-rest-spread')
}
function pluginSyntaxBigint() {
return require('@babel/plugin-syntax-bigint')
}
function pluginSyntaxDynamicImport() {
return require('@babel/plugin-syntax-dynamic-import')
}
function pluginSyntaxJsx() {
return require('@babel/plugin-syntax-jsx')
}
function pluginTransformModulesCommonjs() {
return require('@babel/plugin-transform-modules-commonjs')
}
function pluginTransformRuntime() {
return require('@babel/plugin-transform-runtime')
}
function presetEnv() {
return require('@babel/preset-env')
}
function presetReact() {
return require('@babel/preset-react')
}
function presetTypescript() {
return require('@babel/preset-typescript')
}
module.exports = {
codeFrame,
core,
pluginProposalClassProperties,
pluginProposalExportNamespaceFrom,
pluginProposalNumericSeparator,
pluginProposalObjectRestSpread,
pluginSyntaxBigint,
pluginSyntaxDynamicImport,
pluginSyntaxJsx,
pluginTransformModulesCommonjs,
pluginTransformRuntime,
presetEnv,
presetReact,
presetTypescript,
}
module.exports = require('./bundle').codeFrame()
module.exports = require('./bundle').core()
module.exports = require('./bundle').pluginProposalClassProperties()
module.exports = require('./bundle').pluginProposalExportNamespaceFrom()
module.exports = require('./bundle').pluginProposalNumericSeparator()
module.exports = require('./bundle').pluginProposalObjectRestSpread()
module.exports = require('./bundle').pluginSyntaxBigint()
module.exports = require('./bundle').pluginSyntaxDynamicImport()
module.exports = require('./bundle').pluginSyntaxJsx()
module.exports = require('./bundle').pluginTransformModulesCommonjs()
module.exports = require('./bundle').pluginTransformRuntime()
module.exports = require('./bundle').presetEnv()
module.exports = require('./bundle').presetReact()
module.exports = require('./bundle').presetTypescript()
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This diff is collapsed.
module.exports = require('./bundle').codeFrame()
module.exports = require('./bundle').core()
{"name":"@babel/core","main":"bundle.js","author":"Sebastian McKenzie <sebmck@gmail.com>","license":"MIT"}
module.exports = require('./bundle').pluginProposalClassProperties()
module.exports = require('./bundle').pluginProposalExportNamespaceFrom()
module.exports = require('./bundle').pluginProposalNumericSeparator()
module.exports = require('./bundle').pluginProposalObjectRestSpread()
module.exports = require('./bundle').pluginSyntaxBigint()
module.exports = require('./bundle').pluginSyntaxDynamicImport()
module.exports = require('./bundle').pluginSyntaxJsx()
module.exports = require('./bundle').pluginTransformModulesCommonjs()
module.exports = require('./bundle').pluginTransformRuntime()
module.exports = require('./bundle').presetEnv()
module.exports = require('./bundle').presetReact()
module.exports = require('./bundle').presetTypescript()
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
import { codeFrameColumns } from '@babel/code-frame' import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'
import chalk from 'next/dist/compiled/chalk' import chalk from 'next/dist/compiled/chalk'
import path from 'path' import path from 'path'
......
...@@ -61,22 +61,7 @@ ...@@ -61,22 +61,7 @@
}, },
"dependencies": { "dependencies": {
"@ampproject/toolbox-optimizer": "2.7.0-alpha.1", "@ampproject/toolbox-optimizer": "2.7.0-alpha.1",
"@babel/code-frame": "7.10.4", "@babel/runtime": "7.12.5",
"@babel/core": "7.7.7",
"@babel/plugin-proposal-class-properties": "7.10.4",
"@babel/plugin-proposal-export-namespace-from": "7.10.4",
"@babel/plugin-proposal-numeric-separator": "7.10.4",
"@babel/plugin-proposal-object-rest-spread": "7.11.0",
"@babel/plugin-syntax-bigint": "7.8.3",
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/plugin-syntax-jsx": "7.10.4",
"@babel/plugin-transform-modules-commonjs": "7.10.4",
"@babel/plugin-transform-runtime": "7.11.5",
"@babel/preset-env": "7.11.5",
"@babel/preset-react": "7.10.4",
"@babel/preset-typescript": "7.10.4",
"@babel/runtime": "7.11.2",
"@babel/types": "7.11.5",
"@hapi/accept": "5.0.1", "@hapi/accept": "5.0.1",
"@next/env": "10.0.2-canary.0", "@next/env": "10.0.2-canary.0",
"@next/polyfill-module": "10.0.2-canary.0", "@next/polyfill-module": "10.0.2-canary.0",
...@@ -124,6 +109,21 @@ ...@@ -124,6 +109,21 @@
"sharp": "0.26.2" "sharp": "0.26.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/code-frame": "7.10.4",
"@babel/core": "7.12.3",
"@babel/plugin-proposal-class-properties": "7.12.1",
"@babel/plugin-proposal-export-namespace-from": "7.12.1",
"@babel/plugin-proposal-numeric-separator": "7.12.5",
"@babel/plugin-proposal-object-rest-spread": "7.12.1",
"@babel/plugin-syntax-bigint": "7.8.3",
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/plugin-syntax-jsx": "7.12.1",
"@babel/plugin-transform-modules-commonjs": "7.12.1",
"@babel/plugin-transform-runtime": "7.12.1",
"@babel/preset-env": "7.12.1",
"@babel/preset-react": "7.12.5",
"@babel/preset-typescript": "7.12.1",
"@babel/types": "7.12.6",
"@next/polyfill-nomodule": "10.0.2-canary.0", "@next/polyfill-nomodule": "10.0.2-canary.0",
"@taskr/clear": "1.1.0", "@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0", "@taskr/esnext": "1.1.0",
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// https://github.com/lukeed/taskr/pull/305 // https://github.com/lukeed/taskr/pull/305
const path = require('path') const path = require('path')
// eslint-disable-next-line import/no-extraneous-dependencies
const transform = require('@babel/core').transform const transform = require('@babel/core').transform
const babelClientOpts = { const babelClientOpts = {
...@@ -35,6 +37,7 @@ const babelClientOpts = { ...@@ -35,6 +37,7 @@ const babelClientOpts = {
overrides: [ overrides: [
{ {
test: /\.tsx?$/, test: /\.tsx?$/,
// eslint-disable-next-line import/no-extraneous-dependencies
plugins: [require('@babel/plugin-proposal-numeric-separator').default], plugins: [require('@babel/plugin-proposal-numeric-separator').default],
}, },
], ],
...@@ -68,6 +71,7 @@ const babelServerOpts = { ...@@ -68,6 +71,7 @@ const babelServerOpts = {
overrides: [ overrides: [
{ {
test: /\.tsx?$/, test: /\.tsx?$/,
// eslint-disable-next-line import/no-extraneous-dependencies
plugins: [require('@babel/plugin-proposal-numeric-separator').default], plugins: [require('@babel/plugin-proposal-numeric-separator').default],
}, },
], ],
......
...@@ -39,7 +39,12 @@ module.exports = function (task) { ...@@ -39,7 +39,12 @@ module.exports = function (task) {
}) })
if (options && options.packageName) { if (options && options.packageName) {
writePackageManifest.call(this, options.packageName, file.base) writePackageManifest.call(
this,
options.packageName,
file.base,
options.bundleName
)
} }
file.data = Buffer.from(code, 'utf8') file.data = Buffer.from(code, 'utf8')
...@@ -50,11 +55,14 @@ module.exports = function (task) { ...@@ -50,11 +55,14 @@ module.exports = function (task) {
// This function writes a minimal `package.json` file for a compiled package. // This function writes a minimal `package.json` file for a compiled package.
// It defines `name`, `main`, `author`, and `license`. It also defines `types`. // It defines `name`, `main`, `author`, and `license`. It also defines `types`.
// n.b. types intended for development usage only. // n.b. types intended for development usage only.
function writePackageManifest(packageName, main) { function writePackageManifest(packageName, main, bundleName) {
const packagePath = require.resolve(packageName + '/package.json') const packagePath = require.resolve(packageName + '/package.json')
let { name, author, license } = require(packagePath) let { name, author, license } = require(packagePath)
const compiledPackagePath = join(__dirname, `compiled/${packageName}`) const compiledPackagePath = join(
__dirname,
`compiled/${bundleName || packageName}`
)
const potentialLicensePath = join(dirname(packagePath), './LICENSE') const potentialLicensePath = join(dirname(packagePath), './LICENSE')
if (existsSync(potentialLicensePath)) { if (existsSync(potentialLicensePath)) {
......
...@@ -22,9 +22,6 @@ export async function browser_polyfills(task) { ...@@ -22,9 +22,6 @@ export async function browser_polyfills(task) {
} }
const externals = { const externals = {
// Babel
'@babel/core': '@babel/core',
// Browserslist (post-css plugins) // Browserslist (post-css plugins)
browserslist: 'browserslist', browserslist: 'browserslist',
'caniuse-lite': 'caniuse-lite', 'caniuse-lite': 'caniuse-lite',
...@@ -83,6 +80,54 @@ export async function ncc_async_sema(task, opts) { ...@@ -83,6 +80,54 @@ export async function ncc_async_sema(task, opts) {
.target('compiled/async-sema') .target('compiled/async-sema')
} }
// eslint-disable-next-line camelcase
export async function ncc_babel_bundle(task, opts) {
const bundleExternals = { ...externals }
for (const pkg of Object.keys(babelBundlePackages))
delete bundleExternals[pkg]
await task
.source(opts.src || 'bundles/babel/bundle.js')
.ncc({
packageName: '@babel/core',
bundleName: 'babel',
externals: bundleExternals,
})
.target('compiled/babel')
}
const babelBundlePackages = {
'code-frame': 'next/dist/compiled/babel/code-frame',
'@babel/core': 'next/dist/compiled/babel/core',
'@babel/plugin-proposal-class-properties':
'next/dist/compiled/babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-namespace-from':
'next/dist/compiled/babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-numeric-separator':
'next/dist/compiled/babel/plugin-proposal-numeric-separator',
'@babel/plugin-proposal-object-rest-spread':
'next/dist/compiled/babel/plugin-proposal-object-rest-spread',
'@babel/plugin-syntax-bigint':
'next/dist/compiled/babel/plugin-syntax-bigint',
'@babel/plugin-syntax-dynamic-import':
'next/dist/compiled/babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-jsx': 'next/dist/compiled/babel/plugin-syntax-jsx',
'@babel/plugin-transform-modules-commonjs':
'next/dist/compiled/babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-runtime':
'next/dist/compiled/babel/plugin-transform-runtime',
'@babel/preset-env': 'next/dist/compiled/babel/preset-env',
'@babel/preset-react': 'next/dist/compiled/babel/preset-react',
'@babel/preset-typescript': 'next/dist/compiled/babel/preset-typescript',
}
Object.assign(externals, babelBundlePackages)
export async function ncc_babel_bundle_packages(task, opts) {
await task
.source(opts.src || 'bundles/babel/packages/*')
.target('compiled/babel/')
}
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
externals['babel-loader'] = 'next/dist/compiled/babel-loader' externals['babel-loader'] = 'next/dist/compiled/babel-loader'
export async function ncc_babel_loader(task, opts) { export async function ncc_babel_loader(task, opts) {
...@@ -536,6 +581,8 @@ export async function ncc(task) { ...@@ -536,6 +581,8 @@ export async function ncc(task) {
'ncc_arg', 'ncc_arg',
'ncc_async_retry', 'ncc_async_retry',
'ncc_async_sema', 'ncc_async_sema',
'ncc_babel_bundle',
'ncc_babel_bundle_packages',
'ncc_babel_loader', 'ncc_babel_loader',
'ncc_cacache', 'ncc_cacache',
'ncc_cache_loader', 'ncc_cache_loader',
......
...@@ -37,7 +37,7 @@ type EventCliSessionStarted = { ...@@ -37,7 +37,7 @@ type EventCliSessionStarted = {
function hasBabelConfig(dir: string): boolean { function hasBabelConfig(dir: string): boolean {
try { try {
const noopFile = path.join(dir, 'noop.js') const noopFile = path.join(dir, 'noop.js')
const res = require('@babel/core').loadPartialConfig({ const res = require('next/dist/compiled/babel/core').loadPartialConfig({
cwd: dir, cwd: dir,
filename: noopFile, filename: noopFile,
sourceFileName: noopFile, sourceFileName: noopFile,
......
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
declare module '@babel/plugin-transform-modules-commonjs' declare module 'next/dist/compiled/babel/plugin-transform-modules-commonjs'
declare module '@babel/plugin-syntax-jsx' declare module 'next/dist/compiled/babel/plugin-syntax-jsx'
declare module 'browserslist' declare module 'browserslist'
declare module 'cssnano-simple' { declare module 'cssnano-simple' {
import { OldPlugin } from 'postcss' import { OldPlugin } from 'postcss'
...@@ -49,6 +49,15 @@ declare module 'next/dist/compiled/arg/index.js' { ...@@ -49,6 +49,15 @@ declare module 'next/dist/compiled/arg/index.js' {
export = arg export = arg
} }
declare module 'next/dist/compiled/babel/code-frame' {
export * from '@babel/code-frame'
}
declare module 'next/dist/compiled/babel/preset-env' {
export default any
}
declare module 'next/dist/compiled/babel/core' {
export * from '@babel/core'
}
declare module 'next/dist/compiled/chalk' { declare module 'next/dist/compiled/chalk' {
import m from 'chalk' import m from 'chalk'
export = m export = m
......
...@@ -108,7 +108,7 @@ describe('Build Output', () => { ...@@ -108,7 +108,7 @@ describe('Build Output', () => {
expect(sharedByAll.endsWith('kB')).toBe(true) expect(sharedByAll.endsWith('kB')).toBe(true)
if (_appSize.endsWith('kB')) { if (_appSize.endsWith('kB')) {
expect(parseFloat(_appSize)).toBe(1) expect(parseFloat(_appSize)).toBeLessThanOrEqual(1.01)
expect(_appSize.endsWith('kB')).toBe(true) expect(_appSize.endsWith('kB')).toBe(true)
} else { } else {
expect(parseFloat(_appSize) - 1000).toBeLessThanOrEqual(0) expect(parseFloat(_appSize) - 1000).toBeLessThanOrEqual(0)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment