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
85769c3d
Unverified
Commit
85769c3d
authored
Jun 25, 2018
by
Tim Neutkens
Committed by
GitHub
Jun 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass through buildId to webpack config in development (#4665)
Fixes #4664
parent
e70c5951
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
12 deletions
+24
-12
hot-reloader.js
server/hot-reloader.js
+4
-9
index.js
server/index.js
+1
-2
next.config.js
test/integration/config/next.config.js
+10
-1
build-id.js
test/integration/config/pages/build-id.js
+3
-0
index.test.js
test/integration/config/test/index.test.js
+1
-0
rendering.js
test/integration/config/test/rendering.js
+5
-0
No files found.
server/hot-reloader.js
View file @
85769c3d
...
@@ -5,14 +5,14 @@ import del from 'del'
...
@@ -5,14 +5,14 @@ import del from 'del'
import
onDemandEntryHandler
from
'./on-demand-entry-handler'
import
onDemandEntryHandler
from
'./on-demand-entry-handler'
import
webpack
from
'webpack'
import
webpack
from
'webpack'
import
getBaseWebpackConfig
from
'../build/webpack'
import
getBaseWebpackConfig
from
'../build/webpack'
import
UUID
from
'uuid'
import
{
import
{
addCorsSupport
addCorsSupport
}
from
'./utils'
}
from
'./utils'
import
{
IS_BUNDLED_PAGE_REGEX
}
from
'../lib/constants'
import
{
IS_BUNDLED_PAGE_REGEX
}
from
'../lib/constants'
export
default
class
HotReloader
{
export
default
class
HotReloader
{
constructor
(
dir
,
{
quiet
,
config
}
=
{})
{
constructor
(
dir
,
{
quiet
,
config
,
buildId
}
=
{})
{
this
.
buildId
=
buildId
this
.
dir
=
dir
this
.
dir
=
dir
this
.
quiet
=
quiet
this
.
quiet
=
quiet
this
.
middlewares
=
[]
this
.
middlewares
=
[]
...
@@ -25,11 +25,6 @@ export default class HotReloader {
...
@@ -25,11 +25,6 @@ export default class HotReloader {
this
.
prevChunkNames
=
null
this
.
prevChunkNames
=
null
this
.
prevFailedChunkNames
=
null
this
.
prevFailedChunkNames
=
null
this
.
prevChunkHashes
=
null
this
.
prevChunkHashes
=
null
// Here buildId could be any value.
// Our router accepts any value in the dev mode.
// But for the webpack-compiler and for the webpack-dev-server
// it should be the same value.
this
.
buildId
=
UUID
.
v4
()
this
.
config
=
config
this
.
config
=
config
}
}
...
@@ -62,8 +57,8 @@ export default class HotReloader {
...
@@ -62,8 +57,8 @@ export default class HotReloader {
await
this
.
clean
()
await
this
.
clean
()
const
configs
=
await
Promise
.
all
([
const
configs
=
await
Promise
.
all
([
getBaseWebpackConfig
(
this
.
dir
,
{
dev
:
true
,
isServer
:
false
,
config
:
this
.
config
}),
getBaseWebpackConfig
(
this
.
dir
,
{
dev
:
true
,
isServer
:
false
,
config
:
this
.
config
,
buildId
:
this
.
buildId
}),
getBaseWebpackConfig
(
this
.
dir
,
{
dev
:
true
,
isServer
:
true
,
config
:
this
.
config
})
getBaseWebpackConfig
(
this
.
dir
,
{
dev
:
true
,
isServer
:
true
,
config
:
this
.
config
,
buildId
:
this
.
buildId
})
])
])
const
compiler
=
webpack
(
configs
)
const
compiler
=
webpack
(
configs
)
...
...
server/index.js
View file @
85769c3d
...
@@ -37,8 +37,6 @@ export default class Server {
...
@@ -37,8 +37,6 @@ export default class Server {
this
.
nextConfig
=
loadConfig
(
phase
,
this
.
dir
,
conf
)
this
.
nextConfig
=
loadConfig
(
phase
,
this
.
dir
,
conf
)
this
.
distDir
=
join
(
this
.
dir
,
this
.
nextConfig
.
distDir
)
this
.
distDir
=
join
(
this
.
dir
,
this
.
nextConfig
.
distDir
)
this
.
hotReloader
=
dev
?
this
.
getHotReloader
(
this
.
dir
,
{
quiet
,
config
:
this
.
nextConfig
})
:
null
// Only serverRuntimeConfig needs the default
// Only serverRuntimeConfig needs the default
// publicRuntimeConfig gets it's default in client/index.js
// publicRuntimeConfig gets it's default in client/index.js
const
{
serverRuntimeConfig
=
{},
publicRuntimeConfig
,
assetPrefix
,
generateEtags
}
=
this
.
nextConfig
const
{
serverRuntimeConfig
=
{},
publicRuntimeConfig
,
assetPrefix
,
generateEtags
}
=
this
.
nextConfig
...
@@ -48,6 +46,7 @@ export default class Server {
...
@@ -48,6 +46,7 @@ export default class Server {
process
.
exit
(
1
)
process
.
exit
(
1
)
}
}
this
.
buildId
=
!
dev
?
this
.
readBuildId
()
:
'-'
this
.
buildId
=
!
dev
?
this
.
readBuildId
()
:
'-'
this
.
hotReloader
=
dev
?
this
.
getHotReloader
(
this
.
dir
,
{
quiet
,
config
:
this
.
nextConfig
,
buildId
:
this
.
buildId
})
:
null
this
.
renderOpts
=
{
this
.
renderOpts
=
{
dev
,
dev
,
staticMarkup
,
staticMarkup
,
...
...
test/integration/config/next.config.js
View file @
85769c3d
const
withCSS
=
require
(
'@zeit/next-css'
)
const
withCSS
=
require
(
'@zeit/next-css'
)
const
webpack
=
require
(
'webpack'
)
module
.
exports
=
withCSS
({
module
.
exports
=
withCSS
({
onDemandEntries
:
{
onDemandEntries
:
{
// Make sure entries are not getting disposed.
// Make sure entries are not getting disposed.
...
@@ -11,5 +11,14 @@ module.exports = withCSS({
...
@@ -11,5 +11,14 @@ module.exports = withCSS({
},
},
publicRuntimeConfig
:
{
publicRuntimeConfig
:
{
staticFolder
:
'/static'
staticFolder
:
'/static'
},
webpack
(
config
,
{
buildId
})
{
config
.
plugins
.
push
(
new
webpack
.
DefinePlugin
({
'process.env.CONFIG_BUILD_ID'
:
JSON
.
stringify
(
buildId
)
})
)
return
config
}
}
})
})
test/integration/config/pages/build-id.js
0 → 100644
View file @
85769c3d
export
default
()
=>
{
return
<
p
id
=
'buildId'
>
{
process
.
env
.
CONFIG_BUILD_ID
}
<
/p
>
}
test/integration/config/test/index.test.js
View file @
85769c3d
...
@@ -24,6 +24,7 @@ describe('Configuration', () => {
...
@@ -24,6 +24,7 @@ describe('Configuration', () => {
// pre-build all pages at the start
// pre-build all pages at the start
await
Promise
.
all
([
await
Promise
.
all
([
renderViaHTTP
(
context
.
appPort
,
'/next-config'
),
renderViaHTTP
(
context
.
appPort
,
'/next-config'
),
renderViaHTTP
(
context
.
appPort
,
'/build-id'
),
renderViaHTTP
(
context
.
appPort
,
'/webpack-css'
)
renderViaHTTP
(
context
.
appPort
,
'/webpack-css'
)
])
])
})
})
...
...
test/integration/config/test/rendering.js
View file @
85769c3d
...
@@ -28,5 +28,10 @@ export default function ({ app }, suiteName, render, fetch) {
...
@@ -28,5 +28,10 @@ export default function ({ app }, suiteName, render, fetch) {
const
$
=
await
get
$
(
'/next-config'
)
const
$
=
await
get
$
(
'/next-config'
)
expect
(
$
(
'#server-and-client'
).
text
()
===
'/static'
)
expect
(
$
(
'#server-and-client'
).
text
()
===
'/static'
)
})
})
test
(
'renders the build id in development mode'
,
async
()
=>
{
const
$
=
await
get
$
(
'/build-id'
)
expect
(
$
(
'#buildId'
).
text
()
===
'-'
)
})
})
})
}
}
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