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

update webpack to 5.36.2, use dependOn #24656

Merged
merged 4 commits into from
May 3, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ export function createPagesMapping(
}

export type WebpackEntrypoints = {
[bundle: string]: string | string[]
[bundle: string]:
| string
| string[]
| {
import: string | string[]
dependOn: string | string[]
}
}

type Entrypoints = {
Expand Down
45 changes: 42 additions & 3 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,13 @@ export default async function getBaseWebpackConfig(
},
},
prodGranular: {
chunks: 'all',
// Keep main and _app chunks unsplitted in webpack 5
// as we don't need a separate vendor chunk from that
// and all other chunk depend on them so there is no
// duplication that need to be pulled out.
chunks: isWebpack5
? (chunk) => !/^(main|pages\/_app)$/.test(chunk.name)
: 'all',
cacheGroups: {
framework: {
chunks: 'all',
Expand Down Expand Up @@ -851,6 +857,7 @@ export default async function getBaseWebpackConfig(
setImmediate: false,
},
// Kept as function to be backwards compatible
// @ts-ignore TODO webpack 5 typings needed
entry: async () => {
return {
...(clientEntries ? clientEntries : {}),
Expand Down Expand Up @@ -1602,15 +1609,22 @@ export default async function getBaseWebpackConfig(
}

// Backwards compat for `main.js` entry key
// and setup of dependencies between entries
// we can't do that in the initial entry for
// backward-compat reasons
const originalEntry: any = webpackConfig.entry
if (typeof originalEntry !== 'undefined') {
webpackConfig.entry = async () => {
const updatedEntry = async () => {
const entry: WebpackEntrypoints =
typeof originalEntry === 'function'
? await originalEntry()
: originalEntry
// Server compilation doesn't have main.js
if (clientEntries && entry['main.js'] && entry['main.js'].length > 0) {
if (
clientEntries &&
Array.isArray(entry['main.js']) &&
entry['main.js'].length > 0
) {
const originalFile = clientEntries[
CLIENT_STATIC_FILES_RUNTIME_MAIN
] as string
Expand All @@ -1621,8 +1635,33 @@ export default async function getBaseWebpackConfig(
}
delete entry['main.js']

if (isWebpack5 && !isServer) {
for (const name of Object.keys(entry)) {
if (name === 'main' || name === 'amp' || name === 'react-refresh')
continue
const dependOn =
name.startsWith('pages/') && name !== 'pages/_app'
? 'pages/_app'
: 'main'
const old = entry[name]
if (typeof old === 'object' && !Array.isArray(old)) {
entry[name] = {
dependOn,
...old,
}
} else {
entry[name] = {
import: old,
dependOn,
}
}
}
}

return entry
}
// @ts-ignore webpack 5 typings needed
webpackConfig.entry = updatedEntry
}

if (!dev) {
Expand Down
34 changes: 17 additions & 17 deletions packages/next/bundles/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==

"@types/node@*":
version "14.14.41"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.41.tgz#d0b939d94c1d7bd53d04824af45f1139b8c45615"
integrity sha512-dueRKfaJL4RTtSa7bWeTK1M+VH+Gns73oCgzvYfHZywRCoPSd8EkXBL0mZ9unPTveBn+D9phZBaxuzpwjWkW0g==
version "15.0.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.0.1.tgz#ef34dea0881028d11398be5bf4e856743e3dc35a"
integrity sha512-TMkXt0Ck1y0KKsGr9gJtWGjttxlZnnvDtphxUOSd0bfaR6Q1jle+sPvrzNR1urqYTWMinoKvjKfXUGsumaO1PA==

"@webassemblyjs/ast@1.11.0":
version "1.11.0"
Expand Down Expand Up @@ -164,10 +164,10 @@
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==

acorn@^8.0.4:
version "8.1.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.1.1.tgz#fb0026885b9ac9f48bac1e185e4af472971149ff"
integrity sha512-xYiIVjNuqtKXMxlRMDc6mZUhXehod4a3gbZ1qRlM7icK4EbxUFNLhWoPblCvFtB2Y9CIqHP3CF/rdxLItaQv8g==
acorn@^8.2.1:
version "8.2.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.2.2.tgz#c4574e4fea298d6e6ed4b85ab844b06dd59f26d6"
integrity sha512-VrMS8kxT0e7J1EX0p6rI/E0FbfOVcvBpbIqHThFv+f8YrZIlMfVotYcXKVPmTvPW8sW5miJzfUFrrvthUZg8VQ==

ajv-keywords@^3.5.2:
version "3.5.2"
Expand Down Expand Up @@ -221,9 +221,9 @@ commander@^2.20.0:
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==

electron-to-chromium@^1.3.634:
version "1.3.718"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.718.tgz#a192981ced608978410ebc011e24ecab1bb4beb3"
integrity sha512-CikzdUSShGXwjq1pcW740wK8j+KbazgHZiwzlHICejDaczM6OVsPcrZmBHPwzj9i2rj5twg20MBwp+cYZwldYA==
version "1.3.723"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.723.tgz#52769a75635342a4db29af5f1e40bd3dad02c877"
integrity sha512-L+WXyXI7c7+G1V8ANzRsPI5giiimLAUDC6Zs1ojHHPhYXb3k/iTABFmWjivEtsWrRQymjnO66/rO2ZTABGdmWg==

enhanced-resolve@^5.8.0:
version "5.8.0"
Expand Down Expand Up @@ -438,9 +438,9 @@ terser-webpack-plugin@^5.1.1:
terser "^5.5.1"

terser@^5.5.1:
version "5.6.1"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.6.1.tgz#a48eeac5300c0a09b36854bf90d9c26fb201973c"
integrity sha512-yv9YLFQQ+3ZqgWCUk+pvNJwgUTdlIxUk1WTN+RnaFJe2L7ipG2csPT0ra2XRm7Cs8cxN7QXmK1rFzEwYEQkzXw==
version "5.7.0"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.7.0.tgz#a761eeec206bc87b605ab13029876ead938ae693"
integrity sha512-HP5/9hp2UaZt5fYkuhNBR8YyRcT8juw8+uFbAme53iN9hblvKnLUTKkmwJG6ocWpIKf8UK4DoeWG4ty0J6S6/g==
dependencies:
commander "^2.20.0"
source-map "~0.7.2"
Expand Down Expand Up @@ -471,16 +471,16 @@ watchpack@^2.0.0:
source-map "^0.6.1"

"webpack5@npm:webpack@5":
version "5.35.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.35.0.tgz#4db23c2b96c4e53a90c5732d7cdb301a84a33576"
integrity sha512-au3gu55yYF/h6NXFr0KZPZAYxS6Nlc595BzYPke8n0CSff5WXcoixtjh5LC/8mXunkRKxhymhXmBY0+kEbR6jg==
version "5.36.2"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.36.2.tgz#6ef1fb2453ad52faa61e78d486d353d07cca8a0f"
integrity sha512-XJumVnnGoH2dV+Pk1VwgY4YT6AiMKpVoudUFCNOXMIVrEKPUgEwdIfWPjIuGLESAiS8EdIHX5+TiJz/5JccmRg==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.47"
"@webassemblyjs/ast" "1.11.0"
"@webassemblyjs/wasm-edit" "1.11.0"
"@webassemblyjs/wasm-parser" "1.11.0"
acorn "^8.0.4"
acorn "^8.2.1"
browserslist "^4.14.5"
chrome-trace-event "^1.0.2"
enhanced-resolve "^5.8.0"
Expand Down
1,384 changes: 986 additions & 398 deletions packages/next/compiled/webpack/bundle5.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/integration/build-output/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ describe('Build Output', () => {
expect(indexSize.endsWith('B')).toBe(true)

// should be no bigger than 64.8 kb
expect(parseFloat(indexFirstLoad)).toBeCloseTo(65.3, 1)
expect(parseFloat(indexFirstLoad)).toBeCloseTo(63.5, 1)
expect(indexFirstLoad.endsWith('kB')).toBe(true)

expect(parseFloat(err404Size)).toBeCloseTo(3.69, 1)
expect(parseFloat(err404Size)).toBeCloseTo(3.04, 1)
expect(err404Size.endsWith('kB')).toBe(true)

expect(parseFloat(err404FirstLoad)).toBeCloseTo(68.8, 0)
expect(parseFloat(err404FirstLoad)).toBeCloseTo(66.3, 0)
expect(err404FirstLoad.endsWith('kB')).toBe(true)

expect(parseFloat(sharedByAll)).toBeCloseTo(65, 1)
expect(parseFloat(sharedByAll)).toBeCloseTo(63.3, 1)
expect(sharedByAll.endsWith('kB')).toBe(true)

if (_appSize.endsWith('kB')) {
Expand All @@ -119,10 +119,10 @@ describe('Build Output', () => {
expect(_appSize.endsWith(' B')).toBe(true)
}

expect(parseFloat(webpackSize) - 950).toBeLessThanOrEqual(0)
expect(parseFloat(webpackSize) - 952).toBeLessThanOrEqual(0)
expect(webpackSize.endsWith(' B')).toBe(true)

expect(parseFloat(mainSize) - 7.3).toBeLessThanOrEqual(0)
expect(parseFloat(mainSize) - 19.3).toBeLessThanOrEqual(0)
expect(mainSize.endsWith('kB')).toBe(true)

expect(parseFloat(frameworkSize) - 42.1).toBeLessThanOrEqual(0)
Expand Down