Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
1cc3dbe3
Commit
1cc3dbe3
authored
Oct 20, 2017
by
Tim Neutkens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Sourcemap and Breakpoint Fixes (#3121)"
This reverts commit
964f229f
.
parent
81479eb6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
97 deletions
+88
-97
combine-assets-plugin.js
server/build/plugins/combine-assets-plugin.js
+13
-15
dynamic-chunks-plugin.js
server/build/plugins/dynamic-chunks-plugin.js
+31
-29
pages-plugin.js
server/build/plugins/pages-plugin.js
+36
-42
index.js
server/index.js
+2
-10
render.js
server/render.js
+6
-1
No files found.
server/build/plugins/combine-assets-plugin.js
View file @
1cc3dbe3
import
{
ConcatSource
}
from
'webpack-sources'
// This plugin combines a set of assets into a single asset
// This plugin combines a set of assets into a single asset
// This should be only used with text assets,
// This should be only used with text assets,
// otherwise the result is unpredictable.
// otherwise the result is unpredictable.
...
@@ -10,23 +8,23 @@ export default class CombineAssetsPlugin {
...
@@ -10,23 +8,23 @@ export default class CombineAssetsPlugin {
}
}
apply
(
compiler
)
{
apply
(
compiler
)
{
compiler
.
plugin
(
'compilation'
,
(
compilation
)
=>
{
compiler
.
plugin
(
'after-compile'
,
(
compilation
,
callback
)
=>
{
compilation
.
plugin
(
'optimize-chunk-assets'
,
(
chunks
,
callback
)
=>
{
let
newSource
=
''
const
concat
=
new
ConcatSource
()
this
.
input
.
forEach
((
name
)
=>
{
const
asset
=
compilation
.
assets
[
name
]
this
.
input
.
forEach
((
name
)
=>
{
if
(
!
asset
)
return
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
View file @
1cc3dbe3
import
{
ConcatSource
}
from
'webpack-sources'
export
default
class
PagesPlugin
{
export
default
class
DynamicChunksPlugin
{
apply
(
compiler
)
{
apply
(
compiler
)
{
const
isImportChunk
=
/^chunks
[/\\]
.*
\.
js$/
const
isImportChunk
=
/^chunks
[/\\]
.*
\.
js$/
const
matchChunkName
=
/^chunks
[/\\](
.*
)
$/
const
matchChunkName
=
/^chunks
[/\\](
.*
)
$/
compiler
.
plugin
(
'compilation'
,
(
compilation
)
=>
{
compiler
.
plugin
(
'after-compile'
,
(
compilation
,
callback
)
=>
{
compilation
.
plugin
(
'optimize-chunk-assets'
,
(
chunks
,
callback
)
=>
{
const
chunks
=
Object
chunks
=
chunks
.
filter
(
chunk
=>
isImportChunk
.
test
(
chunk
.
name
))
.
keys
(
compilation
.
namedChunks
)
.
map
(
key
=>
compilation
.
namedChunks
[
key
])
chunks
.
forEach
((
chunk
)
=>
{
.
filter
(
chunk
=>
isImportChunk
.
test
(
chunk
.
name
))
const
asset
=
compilation
.
assets
[
chunk
.
name
]
if
(
!
asset
)
return
chunks
.
forEach
((
chunk
)
=>
{
const
asset
=
compilation
.
assets
[
chunk
.
name
]
const
chunkName
=
matchChunkName
.
exec
(
chunk
.
name
)[
1
]
if
(
!
asset
)
return
const
concat
=
new
ConcatSource
()
const
chunkName
=
matchChunkName
.
exec
(
chunk
.
name
)[
1
]
concat
.
add
(
`__NEXT_REGISTER_CHUNK('
${
chunkName
}
', function() {
`
)
const
content
=
asset
.
source
()
concat
.
add
(
asset
)
const
newContent
=
`
concat
.
add
(
`
window.__NEXT_REGISTER_CHUNK('
${
chunkName
}
', function() {
})
${
content
}
`
)
})
`
// Replace the exisiting chunk with the new content
// Replace the exisiting chunk with the new content
compilation
.
assets
[
chunk
.
name
]
=
concat
compilation
.
assets
[
chunk
.
name
]
=
{
source
:
()
=>
newContent
,
// This is to support, webpack dynamic import support with HMR
size
:
()
=>
newContent
.
length
compilation
.
assets
[
`chunks/
${
chunk
.
name
}
`
]
=
concat
}
})
// This is to support, webpack dynamic import support with HMR
callback
()
compilation
.
assets
[
`chunks/
${
chunk
.
id
}
`
]
=
{
source
:
()
=>
newContent
,
size
:
()
=>
newContent
.
length
}
})
})
callback
()
})
})
}
}
}
}
server/build/plugins/pages-plugin.js
View file @
1cc3dbe3
import
{
ConcatSource
}
from
'webpack-sources'
import
{
import
{
IS_BUNDLED_PAGE
,
IS_BUNDLED_PAGE
,
MATCH_ROUTE_NAME
MATCH_ROUTE_NAME
...
@@ -6,48 +5,43 @@ import {
...
@@ -6,48 +5,43 @@ import {
export
default
class
PagesPlugin
{
export
default
class
PagesPlugin
{
apply
(
compiler
)
{
apply
(
compiler
)
{
compiler
.
plugin
(
'compilation'
,
(
compilation
)
=>
{
compiler
.
plugin
(
'after-compile'
,
(
compilation
,
callback
)
=>
{
compilation
.
plugin
(
'optimize-chunk-assets'
,
(
chunks
,
callback
)
=>
{
const
pages
=
Object
const
pages
=
chunks
.
filter
(
chunk
=>
IS_BUNDLED_PAGE
.
test
(
chunk
.
name
))
.
keys
(
compilation
.
namedChunks
)
.
map
(
key
=>
compilation
.
namedChunks
[
key
])
pages
.
forEach
((
chunk
)
=>
{
.
filter
(
chunk
=>
IS_BUNDLED_PAGE
.
test
(
chunk
.
name
))
const
pageName
=
MATCH_ROUTE_NAME
.
exec
(
chunk
.
name
)[
1
]
let
routeName
=
pageName
pages
.
forEach
((
chunk
)
=>
{
const
page
=
compilation
.
assets
[
chunk
.
name
]
// We need to convert \ into / when we are in windows
const
pageName
=
MATCH_ROUTE_NAME
.
exec
(
chunk
.
name
)[
1
]
// to get the proper route name
let
routeName
=
pageName
// Here we need to do windows check because it's possible
// to have "\" in the filename in unix.
// We need to convert \ into / when we are in windows
// Anyway if someone did that, he'll be having issues here.
// to get the proper route name
// But that's something we cannot avoid.
// Here we need to do windows check because it's possible
if
(
/^win/
.
test
(
process
.
platform
))
{
// to have "\" in the filename in unix.
routeName
=
routeName
.
replace
(
/
\\
/g
,
'/'
)
// 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
(
/
(
^|
\/)
index$/
,
''
)}
`
routeName
=
routeName
.
replace
(
/
\\
/g
,
'/'
)
}
// Replace the exisiting chunk with the new content
const
asset
=
compilation
.
assets
[
chunk
.
name
]
routeName
=
`/
${
routeName
.
replace
(
/
(
^|
\/)
index$/
,
''
)}
`
if
(
!
asset
)
return
const
content
=
page
.
source
()
const
concat
=
new
ConcatSource
()
const
newContent
=
`
window.__NEXT_REGISTER_PAGE('
${
routeName
}
', function() {
concat
.
add
(
`
var comp =
${
content
}
__NEXT_REGISTER_PAGE('
${
routeName
}
', function() {
return { page: comp.default }
var comp =
})
`
)
`
concat
.
add
(
asset
)
// Replace the exisiting chunk with the new content
concat
.
add
(
`
compilation
.
assets
[
chunk
.
name
]
=
{
return { page: comp.default }
source
:
()
=>
newContent
,
})
size
:
()
=>
newContent
.
length
`
)
}
// Replace the exisiting chunk with the new content
compilation
.
assets
[
chunk
.
name
]
=
concat
})
callback
()
})
})
callback
()
})
})
}
}
}
}
server/index.js
View file @
1cc3dbe3
...
@@ -408,11 +408,7 @@ export default class Server {
...
@@ -408,11 +408,7 @@ export default class Server {
}
}
handleBuildId
(
buildId
,
res
)
{
handleBuildId
(
buildId
,
res
)
{
if
(
this
.
dev
)
{
if
(
this
.
dev
)
return
true
res
.
setHeader
(
'Cache-Control'
,
'no-store, must-revalidate'
)
return
true
}
if
(
buildId
!==
this
.
renderOpts
.
buildId
)
{
if
(
buildId
!==
this
.
renderOpts
.
buildId
)
{
return
false
return
false
}
}
...
@@ -432,17 +428,13 @@ export default class Server {
...
@@ -432,17 +428,13 @@ export default class Server {
}
}
handleBuildHash
(
filename
,
hash
,
res
)
{
handleBuildHash
(
filename
,
hash
,
res
)
{
if
(
this
.
dev
)
{
if
(
this
.
dev
)
return
res
.
setHeader
(
'Cache-Control'
,
'no-store, must-revalidate'
)
return
true
}
if
(
hash
!==
this
.
buildStats
[
filename
].
hash
)
{
if
(
hash
!==
this
.
buildStats
[
filename
].
hash
)
{
throw
new
Error
(
`Invalid Build File Hash(
${
hash
}
) for chunk:
${
filename
}
`
)
throw
new
Error
(
`Invalid Build File Hash(
${
hash
}
) for chunk:
${
filename
}
`
)
}
}
res
.
setHeader
(
'Cache-Control'
,
'max-age=365000000, immutable'
)
res
.
setHeader
(
'Cache-Control'
,
'max-age=365000000, immutable'
)
return
true
}
}
send404
(
res
)
{
send404
(
res
)
{
...
...
server/render.js
View file @
1cc3dbe3
...
@@ -93,6 +93,11 @@ async function doRender (req, res, pathname, query, {
...
@@ -93,6 +93,11 @@ async function doRender (req, res, pathname, query, {
}
}
const
docProps
=
await
loadGetInitialProps
(
Document
,
{
...
ctx
,
renderPage
})
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
if
(
res
.
finished
)
return
...
@@ -102,7 +107,7 @@ async function doRender (req, res, pathname, query, {
...
@@ -102,7 +107,7 @@ async function doRender (req, res, pathname, query, {
props
,
props
,
pathname
,
pathname
,
query
,
query
,
buildId
,
buildId
:
dev
?
devBuildId
:
buildId
,
buildStats
,
buildStats
,
assetPrefix
,
assetPrefix
,
nextExport
,
nextExport
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment