Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
a63a4933
N
next.js
项目概览
CoCo_Code_Op2
/
next.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
next.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a63a4933
编写于
4月 02, 2019
作者:
J
Joe Haddad
提交者:
GitHub
4月 02, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine selective page building (#6866)
上级
7c57d2f5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
20 deletion
+61
-20
packages/next-server/server/config.js
packages/next-server/server/config.js
+1
-2
packages/next/build/index.ts
packages/next/build/index.ts
+55
-11
packages/next/build/webpack-config.ts
packages/next/build/webpack-config.ts
+5
-7
未找到文件。
packages/next-server/server/config.js
浏览文件 @
a63a4933
...
...
@@ -30,8 +30,7 @@ const defaultConfig = {
),
ampBindInitData
:
false
,
exportTrailingSlash
:
true
,
profiling
:
false
,
sharedRuntime
:
false
profiling
:
false
}
}
...
...
packages/next/build/index.ts
浏览文件 @
a63a4933
import
{
join
as
pathJoin
,
relative
as
pathRelative
,
isAbsolute
as
pathIsAbsolute
,
}
from
'
path
'
import
path
from
'
path
'
import
fs
from
'
fs
'
import
nanoid
from
'
next/dist/compiled/nanoid/index.js
'
import
loadConfig
from
'
next-server/next-config
'
import
{
PHASE_PRODUCTION_BUILD
}
from
'
next-server/constants
'
...
...
@@ -44,10 +41,21 @@ function printTreeView(list: string[]) {
console
.
log
()
}
function
flatten
<
T
>
(
arr
:
T
[][]):
T
[]
{
return
arr
.
reduce
((
acc
,
val
)
=>
acc
.
concat
(
val
),
[]
as
T
[])
}
function
getPossibleFiles
(
pageExtensions
:
string
[],
pages
:
string
[])
{
const
res
=
pages
.
map
(
page
=>
[
page
].
concat
(
pageExtensions
.
map
(
e
=>
`
${
page
}
.
${
e
}
`
))
)
return
flatten
<
string
>
(
res
)
}
export
default
async
function
build
(
dir
:
string
,
conf
=
null
,
{
pages
=
[]
as
string
[]
}
=
{}
{
pages
:
_pages
=
[]
as
string
[]
}
=
{}
):
Promise
<
void
>
{
if
(
!
(
await
isWriteable
(
dir
)))
{
throw
new
Error
(
...
...
@@ -60,14 +68,48 @@ export default async function build(
const
config
=
loadConfig
(
PHASE_PRODUCTION_BUILD
,
dir
,
conf
)
const
buildId
=
await
generateBuildId
(
config
.
generateBuildId
,
nanoid
)
const
distDir
=
pathJoin
(
dir
,
config
.
distDir
)
const
pagesDir
=
pathJoin
(
dir
,
'
pages
'
)
const
distDir
=
path
.
join
(
dir
,
config
.
distDir
)
const
pagesDir
=
path
.
join
(
dir
,
'
pages
'
)
const
pages
=
Array
.
isArray
(
_pages
)
&&
_pages
.
length
?
_pages
:
process
.
env
.
__NEXT_BUILDER_EXPERIMENTAL_PAGE
?
[
process
.
env
.
__NEXT_BUILDER_EXPERIMENTAL_PAGE
]
:
[]
let
pagePaths
if
(
pages
&&
pages
.
length
)
{
// TODO: smart resolve these pages and check for them
pagePaths
=
pages
.
map
(
page
=>
'
/
'
.
concat
(
pathIsAbsolute
(
page
)
?
pathRelative
(
pagesDir
,
page
)
:
page
)
if
(
config
.
target
!==
'
serverless
'
)
{
throw
new
Error
(
'
Cannot use selective page building without the serverless target.
'
)
}
const
explodedPages
=
flatten
<
string
>
(
pages
.
map
(
p
=>
p
.
split
(
'
,
'
))).
map
(
p
=>
{
let
resolvedPage
:
string
|
undefined
if
(
path
.
isAbsolute
(
p
))
{
resolvedPage
=
getPossibleFiles
(
config
.
pageExtensions
,
[
path
.
join
(
pagesDir
,
p
),
p
,
]).
find
(
f
=>
fs
.
existsSync
(
f
))
}
else
{
resolvedPage
=
getPossibleFiles
(
config
.
pageExtensions
,
[
path
.
join
(
pagesDir
,
p
),
path
.
join
(
dir
,
p
),
]).
find
(
f
=>
fs
.
existsSync
(
f
))
}
return
{
original
:
p
,
resolved
:
resolvedPage
||
null
}
}
)
const
missingPage
=
explodedPages
.
find
(({
resolved
})
=>
!
resolved
)
if
(
missingPage
)
{
throw
new
Error
(
`Unable to identify page:
${
missingPage
.
original
}
`
)
}
pagePaths
=
explodedPages
.
map
(
page
=>
'
/
'
+
path
.
relative
(
pagesDir
,
page
.
resolved
!
)
)
}
else
{
pagePaths
=
await
collectPages
(
pagesDir
,
config
.
pageExtensions
)
...
...
@@ -86,6 +128,7 @@ export default async function build(
config
,
target
:
config
.
target
,
entrypoints
:
entrypoints
.
client
,
__selectivePageBuilding
:
pages
&&
Boolean
(
pages
.
length
),
}),
getBaseWebpackConfig
(
dir
,
{
buildId
,
...
...
@@ -93,6 +136,7 @@ export default async function build(
config
,
target
:
config
.
target
,
entrypoints
:
entrypoints
.
server
,
__selectivePageBuilding
:
pages
&&
Boolean
(
pages
.
length
),
}),
])
...
...
packages/next/build/webpack-config.ts
浏览文件 @
a63a4933
...
...
@@ -18,7 +18,7 @@ import { ChunkGraphPlugin } from './webpack/plugins/chunk-graph-plugin'
import
{
WebpackEntrypoints
}
from
'
./entries
'
type
ExcludesFalse
=
<
T
>
(
x
:
T
|
false
)
=>
x
is
T
export
default
function
getBaseWebpackConfig
(
dir
:
string
,
{
dev
=
false
,
isServer
=
false
,
buildId
,
config
,
target
=
'
server
'
,
entrypoints
}:
{
dev
?:
boolean
,
isServer
?:
boolean
,
buildId
:
string
,
config
:
any
,
target
?:
string
,
entrypoints
:
WebpackEntrypoints
}):
webpack
.
Configuration
{
export
default
function
getBaseWebpackConfig
(
dir
:
string
,
{
dev
=
false
,
isServer
=
false
,
buildId
,
config
,
target
=
'
server
'
,
entrypoints
,
__selectivePageBuilding
=
false
}:
{
dev
?:
boolean
,
isServer
?:
boolean
,
buildId
:
string
,
config
:
any
,
target
?:
string
,
entrypoints
:
WebpackEntrypoints
,
__selectivePageBuilding
?:
boolean
}):
webpack
.
Configuration
{
const
defaultLoaders
=
{
babel
:
{
loader
:
'
next-babel-loader
'
,
...
...
@@ -75,8 +75,6 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, isServe
cpus
:
config
.
experimental
.
cpus
,
}
const
sharedRuntime
=
config
.
experimental
.
sharedRuntime
&&
target
===
'
serverless
'
let
webpackConfig
:
webpack
.
Configuration
=
{
mode
:
webpackMode
,
devtool
:
dev
?
'
cheap-module-source-map
'
:
false
,
...
...
@@ -145,15 +143,15 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, isServe
})
]
:
undefined
}
:
{
runtimeChunk
:
(
!
sharedRuntime
||
dev
)
?
{
runtimeChunk
:
__selectivePageBuilding
?
false
:
{
name
:
CLIENT_STATIC_FILES_RUNTIME_WEBPACK
}
:
false
,
},
splitChunks
:
dev
?
{
cacheGroups
:
{
default
:
false
,
vendors
:
false
}
}
:
sharedRuntime
?
{
}
:
__selectivePageBuilding
?
{
cacheGroups
:
{
default
:
false
,
vendors
:
false
,
...
...
@@ -318,7 +316,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, isServe
// bundle churn
!
dev
&&
new
HashedChunkIdsPlugin
(
buildId
),
// On the client we want to share the same runtime cache
!
dev
&&
!
isServer
&&
sharedRuntime
&&
new
SharedRuntimePlugin
(),
!
isServer
&&
__selectivePageBuilding
&&
new
SharedRuntimePlugin
(),
!
dev
&&
new
webpack
.
IgnorePlugin
({
checkResource
:
(
resource
:
string
)
=>
{
return
/react-is/
.
test
(
resource
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录