Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
1cc3dbe3
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,发现更多精彩内容 >>
提交
1cc3dbe3
编写于
10月 20, 2017
作者:
T
Tim Neutkens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "Sourcemap and Breakpoint Fixes (#3121)"
This reverts commit
964f229f
.
上级
81479eb6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
88 addition
and
97 deletion
+88
-97
server/build/plugins/combine-assets-plugin.js
server/build/plugins/combine-assets-plugin.js
+13
-15
server/build/plugins/dynamic-chunks-plugin.js
server/build/plugins/dynamic-chunks-plugin.js
+31
-29
server/build/plugins/pages-plugin.js
server/build/plugins/pages-plugin.js
+36
-42
server/index.js
server/index.js
+2
-10
server/render.js
server/render.js
+6
-1
未找到文件。
server/build/plugins/combine-assets-plugin.js
浏览文件 @
1cc3dbe3
import
{
ConcatSource
}
from
'
webpack-sources
'
// This plugin combines a set of assets into a single asset
// This should be only used with text assets,
// otherwise the result is unpredictable.
...
...
@@ -10,23 +8,23 @@ export default class CombineAssetsPlugin {
}
apply
(
compiler
)
{
compiler
.
plugin
(
'
compilation
'
,
(
compilation
)
=>
{
compilation
.
plugin
(
'
optimize-chunk-assets
'
,
(
chunks
,
callback
)
=>
{
const
concat
=
new
ConcatSource
()
this
.
input
.
forEach
((
name
)
=>
{
const
asset
=
compilation
.
assets
[
name
]
if
(
!
asset
)
return
compiler
.
plugin
(
'
after-compile
'
,
(
compilation
,
callback
)
=>
{
let
newSource
=
''
this
.
input
.
forEach
((
name
)
=>
{
const
asset
=
compilation
.
assets
[
name
]
if
(
!
asset
)
return
concat
.
add
(
asset
)
newSource
+=
`
${
asset
.
source
()}
\n`
// We keep existing assets since that helps when analyzing the bundle
})
// We keep existing assets since that helps when analyzing the bundle
})
compilation
.
assets
[
this
.
output
]
=
concat
compilation
.
assets
[
this
.
output
]
=
{
source
:
()
=>
newSource
,
size
:
()
=>
newSource
.
length
}
callback
()
})
callback
()
})
}
}
server/build/plugins/dynamic-chunks-plugin.js
浏览文件 @
1cc3dbe3
import
{
ConcatSource
}
from
'
webpack-sources
'
export
default
class
DynamicChunksPlugin
{
export
default
class
PagesPlugin
{
apply
(
compiler
)
{
const
isImportChunk
=
/^chunks
[/\\]
.*
\.
js$/
const
matchChunkName
=
/^chunks
[/\\](
.*
)
$/
compiler
.
plugin
(
'
compilation
'
,
(
compilation
)
=>
{
compilation
.
plugin
(
'
optimize-chunk-assets
'
,
(
chunks
,
callback
)
=>
{
chunks
=
chunks
.
filter
(
chunk
=>
isImportChunk
.
test
(
chunk
.
name
))
chunks
.
forEach
((
chunk
)
=>
{
const
asset
=
compilation
.
assets
[
chunk
.
name
]
if
(
!
asset
)
return
const
chunkName
=
matchChunkName
.
exec
(
chunk
.
name
)[
1
]
const
concat
=
new
ConcatSource
()
concat
.
add
(
`__NEXT_REGISTER_CHUNK('
${
chunkName
}
', function() {
`
)
concat
.
add
(
asset
)
concat
.
add
(
`
})
`
)
// Replace the exisiting chunk with the new content
compilation
.
assets
[
chunk
.
name
]
=
concat
// This is to support, webpack dynamic import support with HMR
compilation
.
assets
[
`chunks/
${
chunk
.
name
}
`
]
=
concat
})
callback
()
compiler
.
plugin
(
'
after-compile
'
,
(
compilation
,
callback
)
=>
{
const
chunks
=
Object
.
keys
(
compilation
.
namedChunks
)
.
map
(
key
=>
compilation
.
namedChunks
[
key
])
.
filter
(
chunk
=>
isImportChunk
.
test
(
chunk
.
name
))
chunks
.
forEach
((
chunk
)
=>
{
const
asset
=
compilation
.
assets
[
chunk
.
name
]
if
(
!
asset
)
return
const
chunkName
=
matchChunkName
.
exec
(
chunk
.
name
)[
1
]
const
content
=
asset
.
source
()
const
newContent
=
`
window.__NEXT_REGISTER_CHUNK('
${
chunkName
}
', function() {
${
content
}
})
`
// Replace the exisiting chunk with the new content
compilation
.
assets
[
chunk
.
name
]
=
{
source
:
()
=>
newContent
,
size
:
()
=>
newContent
.
length
}
// This is to support, webpack dynamic import support with HMR
compilation
.
assets
[
`chunks/
${
chunk
.
id
}
`
]
=
{
source
:
()
=>
newContent
,
size
:
()
=>
newContent
.
length
}
})
callback
()
})
}
}
server/build/plugins/pages-plugin.js
浏览文件 @
1cc3dbe3
import
{
ConcatSource
}
from
'
webpack-sources
'
import
{
IS_BUNDLED_PAGE
,
MATCH_ROUTE_NAME
...
...
@@ -6,48 +5,43 @@ import {
export
default
class
PagesPlugin
{
apply
(
compiler
)
{
compiler
.
plugin
(
'
compilation
'
,
(
compilation
)
=>
{
compilation
.
plugin
(
'
optimize-chunk-assets
'
,
(
chunks
,
callback
)
=>
{
const
pages
=
chunks
.
filter
(
chunk
=>
IS_BUNDLED_PAGE
.
test
(
chunk
.
name
))
pages
.
forEach
((
chunk
)
=>
{
const
pageName
=
MATCH_ROUTE_NAME
.
exec
(
chunk
.
name
)[
1
]
let
routeName
=
pageName
// We need to convert \ into / when we are in windows
// to get the proper route name
// Here we need to do windows check because it's possible
// to have "\" in the filename in unix.
// Anyway if someone did that, he'll be having issues here.
// But that's something we cannot avoid.
if
(
/^win/
.
test
(
process
.
platform
))
{
routeName
=
routeName
.
replace
(
/
\\
/g
,
'
/
'
)
}
routeName
=
`/
${
routeName
.
replace
(
/
(
^|
\/)
index$/
,
''
)}
`
// Replace the exisiting chunk with the new content
const
asset
=
compilation
.
assets
[
chunk
.
name
]
if
(
!
asset
)
return
const
concat
=
new
ConcatSource
()
concat
.
add
(
`
__NEXT_REGISTER_PAGE('
${
routeName
}
', function() {
var comp =
`
)
concat
.
add
(
asset
)
concat
.
add
(
`
return { page: comp.default }
})
`
)
// Replace the exisiting chunk with the new content
compilation
.
assets
[
chunk
.
name
]
=
concat
})
callback
()
compiler
.
plugin
(
'
after-compile
'
,
(
compilation
,
callback
)
=>
{
const
pages
=
Object
.
keys
(
compilation
.
namedChunks
)
.
map
(
key
=>
compilation
.
namedChunks
[
key
])
.
filter
(
chunk
=>
IS_BUNDLED_PAGE
.
test
(
chunk
.
name
))
pages
.
forEach
((
chunk
)
=>
{
const
page
=
compilation
.
assets
[
chunk
.
name
]
const
pageName
=
MATCH_ROUTE_NAME
.
exec
(
chunk
.
name
)[
1
]
let
routeName
=
pageName
// We need to convert \ into / when we are in windows
// to get the proper route name
// Here we need to do windows check because it's possible
// to have "\" in the filename in unix.
// Anyway if someone did that, he'll be having issues here.
// But that's something we cannot avoid.
if
(
/^win/
.
test
(
process
.
platform
))
{
routeName
=
routeName
.
replace
(
/
\\
/g
,
'
/
'
)
}
routeName
=
`/
${
routeName
.
replace
(
/
(
^|
\/)
index$/
,
''
)}
`
const
content
=
page
.
source
()
const
newContent
=
`
window.__NEXT_REGISTER_PAGE('
${
routeName
}
', function() {
var comp =
${
content
}
return { page: comp.default }
})
`
// Replace the exisiting chunk with the new content
compilation
.
assets
[
chunk
.
name
]
=
{
source
:
()
=>
newContent
,
size
:
()
=>
newContent
.
length
}
})
callback
()
})
}
}
server/index.js
浏览文件 @
1cc3dbe3
...
...
@@ -408,11 +408,7 @@ export default class Server {
}
handleBuildId
(
buildId
,
res
)
{
if
(
this
.
dev
)
{
res
.
setHeader
(
'
Cache-Control
'
,
'
no-store, must-revalidate
'
)
return
true
}
if
(
this
.
dev
)
return
true
if
(
buildId
!==
this
.
renderOpts
.
buildId
)
{
return
false
}
...
...
@@ -432,17 +428,13 @@ export default class Server {
}
handleBuildHash
(
filename
,
hash
,
res
)
{
if
(
this
.
dev
)
{
res
.
setHeader
(
'
Cache-Control
'
,
'
no-store, must-revalidate
'
)
return
true
}
if
(
this
.
dev
)
return
if
(
hash
!==
this
.
buildStats
[
filename
].
hash
)
{
throw
new
Error
(
`Invalid Build File Hash(
${
hash
}
) for chunk:
${
filename
}
`
)
}
res
.
setHeader
(
'
Cache-Control
'
,
'
max-age=365000000, immutable
'
)
return
true
}
send404
(
res
)
{
...
...
server/render.js
浏览文件 @
1cc3dbe3
...
...
@@ -93,6 +93,11 @@ async function doRender (req, res, pathname, query, {
}
const
docProps
=
await
loadGetInitialProps
(
Document
,
{
...
ctx
,
renderPage
})
// While developing, we should not cache any assets.
// So, we use a different buildId for each page load.
// With that we can ensure, we have unique URL for assets per every page load.
// So, it'll prevent issues like this: https://git.io/vHLtb
const
devBuildId
=
Date
.
now
()
if
(
res
.
finished
)
return
...
...
@@ -102,7 +107,7 @@ async function doRender (req, res, pathname, query, {
props
,
pathname
,
query
,
buildId
,
buildId
:
dev
?
devBuildId
:
buildId
,
buildStats
,
assetPrefix
,
nextExport
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录