Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
802e879d
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,发现更多精彩内容 >>
未验证
提交
802e879d
编写于
2月 27, 2018
作者:
T
Tim Neutkens
提交者:
GitHub
2月 27, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement new next/config keys (#3909)
上级
a39e54c6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
44 addition
and
44 deletion
+44
-44
client/index.js
client/index.js
+4
-1
readme.md
readme.md
+10
-9
server/export.js
server/export.js
+9
-12
server/index.js
server/index.js
+13
-13
test/integration/config/next.config.js
test/integration/config/next.config.js
+5
-5
test/integration/config/pages/next-config.js
test/integration/config/pages/next-config.js
+3
-4
未找到文件。
client/index.js
浏览文件 @
802e879d
...
...
@@ -39,7 +39,10 @@ __webpack_public_path__ = `${assetPrefix}/_next/webpack/` //eslint-disable-line
// Initialize next/asset with the assetPrefix
asset
.
setAssetPrefix
(
assetPrefix
)
// Initialize next/config with the environment configuration
envConfig
.
setConfig
(
runtimeConfig
||
{})
envConfig
.
setConfig
({
serverRuntimeConfig
:
{},
publicRuntimeConfig
:
runtimeConfig
})
const
asPath
=
getURL
()
...
...
readme.md
浏览文件 @
802e879d
...
...
@@ -1150,11 +1150,11 @@ The `config` key allows for exposing runtime configuration in your app. All keys
```
js
// next.config.js
module
.
exports
=
{
runtimeConfig
:
{
mySecret
:
'
secret
'
,
public
:
{
staticFolder
:
'
/static
'
}
serverRuntimeConfig
:
{
// Will only be available on the server side
mySecret
:
'
secret
'
},
publicRuntimeConfig
:
{
// Will be available on both server and client
staticFolder
:
'
/static
'
}
}
```
...
...
@@ -1162,12 +1162,13 @@ module.exports = {
```
js
// pages/index.js
import
getConfig
from
'
next/config
'
const
config
=
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
const
{
serverRuntimeConfig
,
publicRuntimeConfig
}
=
getConfig
()
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
>
<
img
src
=
{
`
${
config
.
public
.
staticFolder
}
/logo.png`
}
/
>
<
img
src
=
{
`
${
publicRuntimeConfig
.
staticFolder
}
/logo.png`
}
/
>
<
/div>
```
...
...
server/export.js
浏览文件 @
802e879d
...
...
@@ -98,20 +98,17 @@ export default async function (dir, options, configuration) {
availableChunks
:
getAvailableChunks
(
dir
,
nextConfig
.
distDir
)
}
// Allow configuration from next.config.js to be passed to the server / client
if
(
nextConfig
.
runtimeConfig
)
{
// Initialize next/config with the environment configuration
envConfig
.
setConfig
(
nextConfig
.
runtimeConfig
)
// 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
}
}
const
{
serverRuntimeConfig
,
publicRuntimeConfig
}
=
nextConfig
if
(
publicRuntimeConfig
)
{
renderOpts
.
runtimeConfig
=
publicRuntimeConfig
}
envConfig
.
setConfig
({
serverRuntimeConfig
,
publicRuntimeConfig
})
// set the assetPrefix to use for 'next/asset'
setAssetPrefix
(
renderOpts
.
assetPrefix
)
...
...
server/index.js
浏览文件 @
802e879d
...
...
@@ -63,21 +63,21 @@ export default class Server {
availableChunks
:
dev
?
{}
:
getAvailableChunks
(
this
.
dir
,
this
.
dist
)
}
// Allow configuration from next.config.js to be passed to the server / client
if
(
this
.
nextConfig
.
runtimeConfig
)
{
// Initialize next/config with the environment configuration
envConfig
.
setConfig
(
this
.
nextConfig
.
runtimeConfig
)
// Only the `public` key is exposed to the client side
// 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
}
}
const
{
serverRuntimeConfig
,
publicRuntimeConfig
,
assetPrefix
}
=
this
.
nextConfig
// Only the `publicRuntimeConfig` key is exposed to the client side
// It'll be rendered as part of __NEXT_DATA__ on the client side
if
(
publicRuntimeConfig
)
{
this
.
renderOpts
.
runtimeConfig
=
publicRuntimeConfig
}
this
.
setAssetPrefix
(
this
.
nextConfig
.
assetPrefix
)
// Initialize next/config with the environment configuration
envConfig
.
setConfig
({
serverRuntimeConfig
,
publicRuntimeConfig
})
this
.
setAssetPrefix
(
assetPrefix
)
this
.
defineRoutes
()
}
...
...
test/integration/config/next.config.js
浏览文件 @
802e879d
...
...
@@ -6,10 +6,10 @@ module.exports = withCSS({
maxInactiveAge
:
1000
*
60
*
60
},
cssModules
:
true
,
r
untimeConfig
:
{
mySecret
:
'
secret
'
,
public
:
{
staticFolder
:
'
/static
'
}
serverR
untimeConfig
:
{
mySecret
:
'
secret
'
},
publicRuntimeConfig
:
{
staticFolder
:
'
/static
'
}
})
test/integration/config/pages/next-config.js
浏览文件 @
802e879d
// pages/index.js
import
getConfig
from
'
next/config
'
const
config
=
getConfig
()
const
{
serverRuntimeConfig
,
publicRuntimeConfig
}
=
getConfig
()
export
default
()
=>
<
div
>
<
p
id
=
'
server-only
'
>
{
c
onfig
.
mySecret
}
<
/p
>
<
p
id
=
'
server-and-client
'
>
{
config
.
public
.
staticFolder
}
<
/p
>
<
p
id
=
'
server-only
'
>
{
serverRuntimeC
onfig
.
mySecret
}
<
/p
>
<
p
id
=
'
server-and-client
'
>
{
publicRuntimeConfig
.
staticFolder
}
<
/p
>
<
/div
>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录