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
802e879d
Unverified
Commit
802e879d
authored
Feb 27, 2018
by
Tim Neutkens
Committed by
GitHub
Feb 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement new next/config keys (#3909)
parent
a39e54c6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
44 deletions
+44
-44
index.js
client/index.js
+4
-1
readme.md
readme.md
+10
-9
export.js
server/export.js
+9
-12
index.js
server/index.js
+13
-13
next.config.js
test/integration/config/next.config.js
+5
-5
next-config.js
test/integration/config/pages/next-config.js
+3
-4
No files found.
client/index.js
View file @
802e879d
...
@@ -39,7 +39,10 @@ __webpack_public_path__ = `${assetPrefix}/_next/webpack/` //eslint-disable-line
...
@@ -39,7 +39,10 @@ __webpack_public_path__ = `${assetPrefix}/_next/webpack/` //eslint-disable-line
// Initialize next/asset with the assetPrefix
// Initialize next/asset with the assetPrefix
asset
.
setAssetPrefix
(
assetPrefix
)
asset
.
setAssetPrefix
(
assetPrefix
)
// Initialize next/config with the environment configuration
// Initialize next/config with the environment configuration
envConfig
.
setConfig
(
runtimeConfig
||
{})
envConfig
.
setConfig
({
serverRuntimeConfig
:
{},
publicRuntimeConfig
:
runtimeConfig
})
const
asPath
=
getURL
()
const
asPath
=
getURL
()
...
...
readme.md
View file @
802e879d
...
@@ -1150,11 +1150,11 @@ The `config` key allows for exposing runtime configuration in your app. All keys
...
@@ -1150,11 +1150,11 @@ The `config` key allows for exposing runtime configuration in your app. All keys
```
js
```
js
// next.config.js
// next.config.js
module
.
exports
=
{
module
.
exports
=
{
runtimeConfig
:
{
serverRuntimeConfig
:
{
// Will only be available on the server side
mySecret
:
'secret'
,
mySecret
:
'secret'
public
:
{
},
staticFolder
:
'/static'
publicRuntimeConfig
:
{
// Will be available on both server and client
}
staticFolder
:
'/static'
}
}
}
}
```
```
...
@@ -1162,12 +1162,13 @@ module.exports = {
...
@@ -1162,12 +1162,13 @@ module.exports = {
```
js
```
js
// pages/index.js
// pages/index.js
import
getConfig
from
'next/config'
import
getConfig
from
'next/config'
const
config
=
getConfig
()
const
{
serverRuntimeConfig
,
publicRuntimeConfig
}
=
getConfig
()
console
.
log
(
config
.
mySecret
)
// Will be 'secret' on the server, `undefined` on the client
console
.
log
(
config
.
public
.
staticFolder
)
// Will be '/static' on both server and client
console
.
log
(
serverRuntimeConfig
.
mySecret
)
// Will only be available on the server side
console
.
log
(
publicRuntimeConfig
.
staticFolder
)
// Will be available on both server and client
export
default
()
=>
<
div
>
export
default
()
=>
<
div
>
<
img
src
=
{
`
${
config
.
public
.
staticFolder
}
/logo.png`
}
/
>
<
img
src
=
{
`
${
publicRuntimeConfig
.
staticFolder
}
/logo.png`
}
/
>
<
/div
>
<
/div
>
```
```
...
...
server/export.js
View file @
802e879d
...
@@ -98,20 +98,17 @@ export default async function (dir, options, configuration) {
...
@@ -98,20 +98,17 @@ export default async function (dir, options, configuration) {
availableChunks
:
getAvailableChunks
(
dir
,
nextConfig
.
distDir
)
availableChunks
:
getAvailableChunks
(
dir
,
nextConfig
.
distDir
)
}
}
// Allow configuration from next.config.js to be passed to the server / client
const
{
serverRuntimeConfig
,
publicRuntimeConfig
}
=
nextConfig
if
(
nextConfig
.
runtimeConfig
)
{
// Initialize next/config with the environment configuration
if
(
publicRuntimeConfig
)
{
envConfig
.
setConfig
(
nextConfig
.
runtimeConfig
)
renderOpts
.
runtimeConfig
=
publicRuntimeConfig
// Only the `public` key is exposed to the client side
// It'll be rendered as part of __NEXT_DATA__ on the client side
if
(
nextConfig
.
runtimeConfig
.
public
)
{
renderOpts
.
runtimeConfig
=
{
public
:
nextConfig
.
runtimeConfig
.
public
}
}
}
}
envConfig
.
setConfig
({
serverRuntimeConfig
,
publicRuntimeConfig
})
// set the assetPrefix to use for 'next/asset'
// set the assetPrefix to use for 'next/asset'
setAssetPrefix
(
renderOpts
.
assetPrefix
)
setAssetPrefix
(
renderOpts
.
assetPrefix
)
...
...
server/index.js
View file @
802e879d
...
@@ -63,21 +63,21 @@ export default class Server {
...
@@ -63,21 +63,21 @@ export default class Server {
availableChunks
:
dev
?
{}
:
getAvailableChunks
(
this
.
dir
,
this
.
dist
)
availableChunks
:
dev
?
{}
:
getAvailableChunks
(
this
.
dir
,
this
.
dist
)
}
}
// Allow configuration from next.config.js to be passed to the server / client
const
{
serverRuntimeConfig
,
publicRuntimeConfig
,
assetPrefix
}
=
this
.
nextConfig
if
(
this
.
nextConfig
.
runtimeConfig
)
{
// Initialize next/config with the environment configuration
// Only the `publicRuntimeConfig` key is exposed to the client side
envConfig
.
setConfig
(
this
.
nextConfig
.
runtimeConfig
)
// It'll be rendered as part of __NEXT_DATA__ on the client side
if
(
publicRuntimeConfig
)
{
// Only the `public` key is exposed to the client side
this
.
renderOpts
.
runtimeConfig
=
publicRuntimeConfig
// It'll be rendered as part of __NEXT_DATA__ on the client side
if
(
this
.
nextConfig
.
runtimeConfig
.
public
)
{
this
.
renderOpts
.
runtimeConfig
=
{
public
:
this
.
nextConfig
.
runtimeConfig
.
public
}
}
}
}
this
.
setAssetPrefix
(
this
.
nextConfig
.
assetPrefix
)
// Initialize next/config with the environment configuration
envConfig
.
setConfig
({
serverRuntimeConfig
,
publicRuntimeConfig
})
this
.
setAssetPrefix
(
assetPrefix
)
this
.
defineRoutes
()
this
.
defineRoutes
()
}
}
...
...
test/integration/config/next.config.js
View file @
802e879d
...
@@ -6,10 +6,10 @@ module.exports = withCSS({
...
@@ -6,10 +6,10 @@ module.exports = withCSS({
maxInactiveAge
:
1000
*
60
*
60
maxInactiveAge
:
1000
*
60
*
60
},
},
cssModules
:
true
,
cssModules
:
true
,
r
untimeConfig
:
{
serverR
untimeConfig
:
{
mySecret
:
'secret'
,
mySecret
:
'secret'
public
:
{
},
staticFolder
:
'/static'
publicRuntimeConfig
:
{
}
staticFolder
:
'/static'
}
}
})
})
test/integration/config/pages/next-config.js
View file @
802e879d
// pages/index.js
import
getConfig
from
'next/config'
import
getConfig
from
'next/config'
const
config
=
getConfig
()
const
{
serverRuntimeConfig
,
publicRuntimeConfig
}
=
getConfig
()
export
default
()
=>
<
div
>
export
default
()
=>
<
div
>
<
p
id
=
'server-only'
>
{
c
onfig
.
mySecret
}
<
/p
>
<
p
id
=
'server-only'
>
{
serverRuntimeC
onfig
.
mySecret
}
<
/p
>
<
p
id
=
'server-and-client'
>
{
config
.
public
.
staticFolder
}
<
/p
>
<
p
id
=
'server-and-client'
>
{
publicRuntimeConfig
.
staticFolder
}
<
/p
>
<
/div
>
<
/div
>
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