Unverified Commit 1810cf5a authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Add an experimental mode for flyingShuttle (#6985)

parent f301c4f0
...@@ -30,7 +30,8 @@ const defaultConfig = { ...@@ -30,7 +30,8 @@ const defaultConfig = {
), ),
ampBindInitData: false, ampBindInitData: false,
exportTrailingSlash: true, exportTrailingSlash: true,
profiling: false profiling: false,
flyingShuttle: false
} }
} }
......
...@@ -57,14 +57,15 @@ function getPossibleFiles(pageExtensions: string[], pages: string[]) { ...@@ -57,14 +57,15 @@ function getPossibleFiles(pageExtensions: string[], pages: string[]) {
export async function getSpecifiedPages( export async function getSpecifiedPages(
dir: string, dir: string,
pages: string[], pages: string[],
pageExtensions: string[] pageExtensions: string[],
assumeAll: boolean
) { ) {
const pagesDir = path.join(dir, 'pages') const pagesDir = path.join(dir, 'pages')
const reservedPages = ['/_app', '/_document', '/_error'] const reservedPages = ['/_app', '/_document', '/_error']
pages.push(...reservedPages) pages.push(...reservedPages)
const searchAllPages = pages.some(p => p.includes('**')) const searchAllPages = assumeAll || pages.some(p => p.includes('**'))
let pagePaths: string[] let pagePaths: string[]
const explodedPages = [ const explodedPages = [
...@@ -157,17 +158,22 @@ export default async function build( ...@@ -157,17 +158,22 @@ export default async function build(
? [process.env.__NEXT_BUILDER_EXPERIMENTAL_PAGE] ? [process.env.__NEXT_BUILDER_EXPERIMENTAL_PAGE]
: [] : []
const __selectivePageBuilding = pages ? Boolean(pages.length) : false const selectivePageBuilding = pages ? Boolean(pages.length) : false
if (__selectivePageBuilding && config.target !== 'serverless') { if (selectivePageBuilding && config.target !== 'serverless') {
throw new Error( throw new Error(
'Cannot use selective page building without the serverless target.' 'Cannot use selective page building without the serverless target.'
) )
} }
let pagePaths let pagePaths
if (__selectivePageBuilding) { if (selectivePageBuilding) {
pagePaths = await getSpecifiedPages(dir, pages, config.pageExtensions) pagePaths = await getSpecifiedPages(
dir,
pages,
config.pageExtensions,
config.experimental.flyingShuttle
)
} else { } else {
pagePaths = await collectPages(pagesDir, config.pageExtensions) pagePaths = await collectPages(pagesDir, config.pageExtensions)
} }
...@@ -176,7 +182,7 @@ export default async function build( ...@@ -176,7 +182,7 @@ export default async function build(
mappedPages, mappedPages,
config.target, config.target,
buildId, buildId,
__selectivePageBuilding, selectivePageBuilding,
config config
) )
const configs = await Promise.all([ const configs = await Promise.all([
...@@ -187,7 +193,7 @@ export default async function build( ...@@ -187,7 +193,7 @@ export default async function build(
config, config,
target: config.target, target: config.target,
entrypoints: entrypoints.client, entrypoints: entrypoints.client,
__selectivePageBuilding, selectivePageBuilding,
}), }),
getBaseWebpackConfig(dir, { getBaseWebpackConfig(dir, {
debug, debug,
...@@ -196,7 +202,7 @@ export default async function build( ...@@ -196,7 +202,7 @@ export default async function build(
config, config,
target: config.target, target: config.target,
entrypoints: entrypoints.server, entrypoints: entrypoints.server,
__selectivePageBuilding, selectivePageBuilding,
}), }),
]) ])
...@@ -255,5 +261,5 @@ export default async function build( ...@@ -255,5 +261,5 @@ export default async function build(
printTreeView(Object.keys(mappedPages)) printTreeView(Object.keys(mappedPages))
await writeBuildId(distDir, buildId, __selectivePageBuilding) await writeBuildId(distDir, buildId, selectivePageBuilding)
} }
...@@ -18,7 +18,7 @@ import { ChunkGraphPlugin } from './webpack/plugins/chunk-graph-plugin' ...@@ -18,7 +18,7 @@ import { ChunkGraphPlugin } from './webpack/plugins/chunk-graph-plugin'
import { WebpackEntrypoints } from './entries' import { WebpackEntrypoints } from './entries'
type ExcludesFalse = <T>(x: T | false) => x is T type ExcludesFalse = <T>(x: T | false) => x is T
export default function getBaseWebpackConfig (dir: string, {dev = false, debug = false, isServer = false, buildId, config, target = 'server', entrypoints, __selectivePageBuilding = false}: {dev?: boolean, debug?: boolean, isServer?: boolean, buildId: string, config: any, target?: string, entrypoints: WebpackEntrypoints, __selectivePageBuilding?: boolean}): webpack.Configuration { export default function getBaseWebpackConfig (dir: string, {dev = false, debug = false, isServer = false, buildId, config, target = 'server', entrypoints, selectivePageBuilding = false}: {dev?: boolean, debug?: boolean, isServer?: boolean, buildId: string, config: any, target?: string, entrypoints: WebpackEntrypoints, selectivePageBuilding?: boolean}): webpack.Configuration {
const defaultLoaders = { const defaultLoaders = {
babel: { babel: {
loader: 'next-babel-loader', loader: 'next-babel-loader',
...@@ -135,7 +135,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug = ...@@ -135,7 +135,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug =
splitChunks: false, splitChunks: false,
minimize: false minimize: false
} : { } : {
runtimeChunk: __selectivePageBuilding ? false : { runtimeChunk: selectivePageBuilding ? false : {
name: CLIENT_STATIC_FILES_RUNTIME_WEBPACK name: CLIENT_STATIC_FILES_RUNTIME_WEBPACK
}, },
splitChunks: dev ? { splitChunks: dev ? {
...@@ -143,7 +143,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug = ...@@ -143,7 +143,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug =
default: false, default: false,
vendors: false vendors: false
} }
} : __selectivePageBuilding ? { } : selectivePageBuilding ? {
cacheGroups: { cacheGroups: {
default: false, default: false,
vendors: false, vendors: false,
...@@ -175,11 +175,11 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug = ...@@ -175,11 +175,11 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug =
new TerserPlugin({...terserPluginConfig, new TerserPlugin({...terserPluginConfig,
terserOptions: { terserOptions: {
safari10: true, safari10: true,
...(__selectivePageBuilding ? { compress: false, mangle: true } : undefined) ...(selectivePageBuilding ? { compress: false, mangle: true } : undefined)
} }
}) })
] : undefined, ] : undefined,
}, __selectivePageBuilding ? { }, selectivePageBuilding ? {
providedExports: false, providedExports: false,
usedExports: false, usedExports: false,
concatenateModules: false, concatenateModules: false,
...@@ -224,7 +224,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug = ...@@ -224,7 +224,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug =
// @ts-ignore this is filtered // @ts-ignore this is filtered
module: { module: {
rules: [ rules: [
__selectivePageBuilding && !isServer && { selectivePageBuilding && !isServer && {
test: /\.(js|mjs|jsx)$/, test: /\.(js|mjs|jsx)$/,
use: { use: {
loader: 'next-minify-loader', loader: 'next-minify-loader',
...@@ -277,7 +277,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug = ...@@ -277,7 +277,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug =
!isServer && new ReactLoadablePlugin({ !isServer && new ReactLoadablePlugin({
filename: REACT_LOADABLE_MANIFEST filename: REACT_LOADABLE_MANIFEST
}), }),
!isServer && __selectivePageBuilding && new ChunkGraphPlugin(buildId, path.resolve(dir), { filename: CHUNK_GRAPH_MANIFEST }), !isServer && selectivePageBuilding && new ChunkGraphPlugin(buildId, path.resolve(dir), { filename: CHUNK_GRAPH_MANIFEST }),
...(dev ? (() => { ...(dev ? (() => {
// Even though require.cache is server only we have to clear assets from both compilations // Even though require.cache is server only we have to clear assets from both compilations
// This is because the client compilation generates the build manifest that's used on the server side // This is because the client compilation generates the build manifest that's used on the server side
...@@ -316,12 +316,12 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug = ...@@ -316,12 +316,12 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug =
!dev && new webpack.HashedModuleIdsPlugin(), !dev && new webpack.HashedModuleIdsPlugin(),
// This must come after HashedModuleIdsPlugin (it sets any modules that // This must come after HashedModuleIdsPlugin (it sets any modules that
// were missed by HashedModuleIdsPlugin) // were missed by HashedModuleIdsPlugin)
!dev && __selectivePageBuilding && new AllModulesIdentifiedPlugin(dir), !dev && selectivePageBuilding && new AllModulesIdentifiedPlugin(dir),
// This sets chunk ids to be hashed versions of their names to reduce // This sets chunk ids to be hashed versions of their names to reduce
// bundle churn // bundle churn
!dev && new HashedChunkIdsPlugin(buildId), !dev && new HashedChunkIdsPlugin(buildId),
// On the client we want to share the same runtime cache // On the client we want to share the same runtime cache
!isServer && __selectivePageBuilding && new SharedRuntimePlugin(), !isServer && selectivePageBuilding && new SharedRuntimePlugin(),
!dev && new webpack.IgnorePlugin({ !dev && new webpack.IgnorePlugin({
checkResource: (resource: string) => { checkResource: (resource: string) => {
return /react-is/.test(resource) return /react-is/.test(resource)
...@@ -330,7 +330,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug = ...@@ -330,7 +330,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, debug =
return /next-server[\\/]dist[\\/]/.test(context) || /next[\\/]dist[\\/]/.test(context) return /next-server[\\/]dist[\\/]/.test(context) || /next[\\/]dist[\\/]/.test(context)
} }
}), }),
target === 'serverless' && (isServer || __selectivePageBuilding) && new ServerlessPlugin(buildId, { isServer }), target === 'serverless' && (isServer || selectivePageBuilding) && new ServerlessPlugin(buildId, { isServer }),
target !== 'serverless' && isServer && new PagesManifestPlugin(), target !== 'serverless' && isServer && new PagesManifestPlugin(),
target !== 'serverless' && isServer && new NextJsSSRModuleCachePlugin({ outputPath }), target !== 'serverless' && isServer && new NextJsSSRModuleCachePlugin({ outputPath }),
isServer && new NextJsSsrImportPlugin(), isServer && new NextJsSsrImportPlugin(),
......
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