Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-compile more dependencies #32742

Merged
merged 25 commits into from Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.