Skip to content

Commit

Permalink
Pre-compile more dependencies (#32742)
Browse files Browse the repository at this point in the history
This ncc's some remaining dependencies bringing us under 20 install time dependencies (including nested dependencies), this also reduces install size by another `2.75 MB`. A follow-up PR will investigate a custom install script for our swc packages to allow us to remove the `optionalDependencies` which is slowing down install time as well. 

x-ref: #32679
x-ref: #32627
x-ref: #31887
x-ref: vercel/styled-jsx#770
  • Loading branch information
ijjk committed Jan 17, 2022
1 parent 3894320 commit 25d064f
Show file tree
Hide file tree
Showing 57 changed files with 2,936 additions and 101 deletions.
5 changes: 4 additions & 1 deletion packages/next/build/babel/loader/get-config.ts
Expand Up @@ -77,7 +77,10 @@ function getPlugins(
: null
const reactRefreshItem = hasReactRefresh
? createConfigItem(
[require('react-refresh/babel'), { skipEnvCheck: true }],
[
require('next/dist/compiled/react-refresh/babel'),
{ skipEnvCheck: true },
],
{ type: 'plugin' }
)
: null
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/utils.ts
Expand Up @@ -4,7 +4,7 @@ import getGzipSize from 'next/dist/compiled/gzip-size'
import textTable from 'next/dist/compiled/text-table'
import path from 'path'
import { promises as fs } from 'fs'
import { isValidElementType } from 'react-is'
import { isValidElementType } from 'next/dist/compiled/react-is'
import stripAnsi from 'next/dist/compiled/strip-ansi'
import {
Redirect,
Expand Down
17 changes: 10 additions & 7 deletions packages/next/build/webpack-config.ts
@@ -1,4 +1,4 @@
import ReactRefreshWebpackPlugin from '@next/react-refresh-utils/ReactRefreshWebpackPlugin'
import ReactRefreshWebpackPlugin from 'next/dist/compiled/@next/react-refresh-utils/ReactRefreshWebpackPlugin'
import chalk from 'next/dist/compiled/chalk'
import crypto from 'crypto'
import { stringify } from 'querystring'
Expand Down Expand Up @@ -132,7 +132,8 @@ export function attachReactRefresh(
targetLoader: webpack.RuleSetUseItem
) {
let injections = 0
const reactRefreshLoaderName = '@next/react-refresh-utils/loader'
const reactRefreshLoaderName =
'next/dist/compiled/@next/react-refresh-utils/loader'
const reactRefreshLoader = require.resolve(reactRefreshLoaderName)
webpackConfig.module?.rules.forEach((rule) => {
const curr = rule.use
Expand Down Expand Up @@ -496,7 +497,7 @@ export default async function getBaseWebpackConfig(
...(dev
? {
[CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH]: require.resolve(
`@next/react-refresh-utils/runtime`
`next/dist/compiled/@next/react-refresh-utils/runtime`
),
[CLIENT_STATIC_FILES_RUNTIME_AMP]:
`./` +
Expand Down Expand Up @@ -638,8 +639,7 @@ export default async function getBaseWebpackConfig(
process: require.resolve('./polyfills/process'),
// Handled in separate alias
querystring: require.resolve('next/dist/compiled/querystring-es3'),
// TODO: investigate ncc'ing stream-browserify
stream: require.resolve('stream-browserify'),
stream: require.resolve('next/dist/compiled/stream-browserify'),
string_decoder: require.resolve(
'next/dist/compiled/string_decoder'
),
Expand Down Expand Up @@ -912,7 +912,8 @@ export default async function getBaseWebpackConfig(
const externalType = isEsm ? 'module' : 'commonjs'

if (
res.match(/next[/\\]dist[/\\]shared[/\\](?!lib[/\\]router[/\\]router)/)
res.match(/next[/\\]dist[/\\]shared[/\\](?!lib[/\\]router[/\\]router)/) ||
res.match(/next[/\\]dist[/\\]compiled[/\\].*\.[mc]?js$/)
) {
return `${externalType} ${request}`
}
Expand Down Expand Up @@ -1245,7 +1246,9 @@ export default async function getBaseWebpackConfig(
...codeCondition,
use: hasReactRefresh
? [
require.resolve('@next/react-refresh-utils/loader'),
require.resolve(
'next/dist/compiled/@next/react-refresh-utils/loader'
),
defaultLoaders.babel,
]
: defaultLoaders.babel,
Expand Down
Expand Up @@ -6,7 +6,7 @@ import {
sources,
} from 'next/dist/compiled/webpack/webpack'
import pLimit from 'next/dist/compiled/p-limit'
import { Worker } from 'jest-worker'
import { Worker } from 'next/dist/compiled/jest-worker'
import { spans } from '../../profiling-plugin'

function getEcmaVersion(environment) {
Expand Down
1 change: 1 addition & 0 deletions packages/next/build/webpack/require-hook.ts
Expand Up @@ -125,6 +125,7 @@ const hookPropertyMap = new Map(
'@babel/runtime/package.json',
'next/dist/compiled/@babel/runtime/package.json',
],
['node-fetch', 'next/dist/compiled/node-fetch'],
].map(([request, replacement]) => [request, require.resolve(replacement)])
)

Expand Down
2 changes: 1 addition & 1 deletion packages/next/client/index.tsx
Expand Up @@ -330,7 +330,7 @@ export async function initNext(opts: { webpackHMR?: any } = {}) {
CachedComponent = pageEntrypoint.component

if (process.env.NODE_ENV !== 'production') {
const { isValidElementType } = require('react-is')
const { isValidElementType } = require('next/dist/compiled/react-is')
if (!isValidElementType(CachedComponent)) {
throw new Error(
`The default export is not a React Component in page: "${page}"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 25d064f

Please sign in to comment.