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
Show 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 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
()
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
})
compilation
.
assets
[
this
.
output
]
=
concat
compilation
.
assets
[
this
.
output
]
=
{
source
:
()
=>
newSource
,
size
:
()
=>
newSource
.
length
}
callback
()
})
})
}
}
server/build/plugins/dynamic-chunks-plugin.js
View file @
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
))
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
concat
=
new
ConcatSource
()
concat
.
add
(
`__NEXT_REGISTER_CHUNK('
${
chunkName
}
', function() {
`
)
concat
.
add
(
asset
)
concat
.
add
(
`
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
]
=
concat
compilation
.
assets
[
chunk
.
name
]
=
{
source
:
()
=>
newContent
,
size
:
()
=>
newContent
.
length
}
// This is to support, webpack dynamic import support with HMR
compilation
.
assets
[
`chunks/
${
chunk
.
name
}
`
]
=
concat
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
{
IS_BUNDLED_PAGE
,
MATCH_ROUTE_NAME
...
...
@@ -6,11 +5,14 @@ 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
))
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
...
...
@@ -26,28 +28,20 @@ export default class PagesPlugin {
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
(
`
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
]
=
concat
compilation
.
assets
[
chunk
.
name
]
=
{
source
:
()
=>
newContent
,
size
:
()
=>
newContent
.
length
}
})
callback
()
})
})
}
}
server/index.js
View file @
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
View file @
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
,
...
...
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