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
bd249180
Unverified
Commit
bd249180
authored
Feb 12, 2019
by
Connor Davis
Committed by
GitHub
Feb 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Runtime Config in `next export` (#6258)
parent
33b9ebc7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
10 deletions
+30
-10
index.js
packages/next/export/index.js
+1
-6
worker.js
packages/next/export/worker.js
+6
-0
next.config.js
test/integration/export/next.config.js
+6
-0
about.js
test/integration/export/pages/about.js
+10
-2
browser.js
test/integration/export/test/browser.js
+2
-2
ssr.js
test/integration/export/test/ssr.js
+5
-0
No files found.
packages/next/export/index.js
View file @
bd249180
...
@@ -7,7 +7,6 @@ import { resolve, join } from 'path'
...
@@ -7,7 +7,6 @@ import { resolve, join } from 'path'
import
{
existsSync
,
readFileSync
}
from
'fs'
import
{
existsSync
,
readFileSync
}
from
'fs'
import
loadConfig
from
'next-server/next-config'
import
loadConfig
from
'next-server/next-config'
import
{
PHASE_EXPORT
,
SERVER_DIRECTORY
,
PAGES_MANIFEST
,
CONFIG_FILE
,
BUILD_ID_FILE
,
CLIENT_STATIC_FILES_PATH
}
from
'next-server/constants'
import
{
PHASE_EXPORT
,
SERVER_DIRECTORY
,
PAGES_MANIFEST
,
CONFIG_FILE
,
BUILD_ID_FILE
,
CLIENT_STATIC_FILES_PATH
}
from
'next-server/constants'
import
*
as
envConfig
from
'next-server/config'
import
createProgress
from
'tty-aware-progress'
import
createProgress
from
'tty-aware-progress'
export
default
async
function
(
dir
,
options
,
configuration
)
{
export
default
async
function
(
dir
,
options
,
configuration
)
{
...
@@ -98,11 +97,6 @@ export default async function (dir, options, configuration) {
...
@@ -98,11 +97,6 @@ export default async function (dir, options, configuration) {
renderOpts
.
runtimeConfig
=
publicRuntimeConfig
renderOpts
.
runtimeConfig
=
publicRuntimeConfig
}
}
envConfig
.
setConfig
({
serverRuntimeConfig
,
publicRuntimeConfig
})
// We need this for server rendering the Link component.
// We need this for server rendering the Link component.
global
.
__NEXT_DATA__
=
{
global
.
__NEXT_DATA__
=
{
nextExport
:
true
nextExport
:
true
...
@@ -138,6 +132,7 @@ export default async function (dir, options, configuration) {
...
@@ -138,6 +132,7 @@ export default async function (dir, options, configuration) {
exportPathMap
:
chunk
.
pathMap
,
exportPathMap
:
chunk
.
pathMap
,
outDir
,
outDir
,
renderOpts
,
renderOpts
,
serverRuntimeConfig
,
concurrency
concurrency
})
})
worker
.
on
(
'message'
,
({
type
,
payload
})
=>
{
worker
.
on
(
'message'
,
({
type
,
payload
})
=>
{
...
...
packages/next/export/worker.js
View file @
bd249180
...
@@ -8,6 +8,7 @@ const { renderToHTML } = require('next-server/dist/server/render')
...
@@ -8,6 +8,7 @@ const { renderToHTML } = require('next-server/dist/server/render')
const
{
writeFile
}
=
require
(
'fs'
)
const
{
writeFile
}
=
require
(
'fs'
)
const
Sema
=
require
(
'async-sema'
)
const
Sema
=
require
(
'async-sema'
)
const
{
loadComponents
}
=
require
(
'next-server/dist/server/load-components'
)
const
{
loadComponents
}
=
require
(
'next-server/dist/server/load-components'
)
const
envConfig
=
require
(
'next-server/config'
)
process
.
on
(
process
.
on
(
'message'
,
'message'
,
...
@@ -18,6 +19,7 @@ process.on(
...
@@ -18,6 +19,7 @@ process.on(
exportPathMap
,
exportPathMap
,
outDir
,
outDir
,
renderOpts
,
renderOpts
,
serverRuntimeConfig
,
concurrency
concurrency
})
=>
{
})
=>
{
const
sema
=
new
Sema
(
concurrency
,
{
capacity
:
exportPaths
.
length
})
const
sema
=
new
Sema
(
concurrency
,
{
capacity
:
exportPaths
.
length
})
...
@@ -27,6 +29,10 @@ process.on(
...
@@ -27,6 +29,10 @@ process.on(
const
{
page
,
query
=
{}
}
=
exportPathMap
[
path
]
const
{
page
,
query
=
{}
}
=
exportPathMap
[
path
]
const
req
=
{
url
:
path
}
const
req
=
{
url
:
path
}
const
res
=
{}
const
res
=
{}
envConfig
.
setConfig
({
serverRuntimeConfig
,
publicRuntimeConfig
:
renderOpts
.
runtimeConfig
})
let
htmlFilename
=
`
${
path
}${
sep
}
index.html`
let
htmlFilename
=
`
${
path
}${
sep
}
index.html`
if
(
extname
(
path
)
!==
''
)
{
if
(
extname
(
path
)
!==
''
)
{
...
...
test/integration/export/next.config.js
View file @
bd249180
...
@@ -3,6 +3,12 @@ const {PHASE_DEVELOPMENT_SERVER} = require('next-server/constants')
...
@@ -3,6 +3,12 @@ const {PHASE_DEVELOPMENT_SERVER} = require('next-server/constants')
module
.
exports
=
(
phase
)
=>
{
module
.
exports
=
(
phase
)
=>
{
return
{
return
{
distDir
:
phase
===
PHASE_DEVELOPMENT_SERVER
?
'.next-dev'
:
'.next'
,
distDir
:
phase
===
PHASE_DEVELOPMENT_SERVER
?
'.next-dev'
:
'.next'
,
publicRuntimeConfig
:
{
foo
:
'foo'
},
serverRuntimeConfig
:
{
bar
:
'bar'
},
exportPathMap
:
function
()
{
exportPathMap
:
function
()
{
return
{
return
{
'/'
:
{
page
:
'/'
},
'/'
:
{
page
:
'/'
},
...
...
test/integration/export/pages/about.js
View file @
bd249180
import
Link
from
'next/link'
import
Link
from
'next/link'
import
getConfig
from
'next/config'
const
{
publicRuntimeConfig
,
serverRuntimeConfig
}
=
getConfig
()
export
default
(
)
=>
(
const
About
=
({
bar
}
)
=>
(
<
div
id
=
'about-page'
>
<
div
id
=
'about-page'
>
<
div
>
<
div
>
<
Link
href
=
'/'
>
<
Link
href
=
'/'
>
<
a
>
Go
Back
<
/a
>
<
a
>
Go
Back
<
/a
>
<
/Link
>
<
/Link
>
<
/div
>
<
/div
>
<
p
>
This
is
the
About
page
<
/p
>
<
p
>
{
`This is the About page
${
publicRuntimeConfig
.
foo
}${
bar
||
''
}
`
}
<
/p
>
<
/div
>
<
/div
>
)
)
About
.
getInitialProps
=
async
(
ctx
)
=>
{
return
{
bar
:
serverRuntimeConfig
.
bar
}
}
export
default
About
test/integration/export/test/browser.js
View file @
bd249180
...
@@ -20,7 +20,7 @@ export default function (context) {
...
@@ -20,7 +20,7 @@ export default function (context) {
.
waitForElementByCss
(
'#about-page'
)
.
waitForElementByCss
(
'#about-page'
)
.
elementByCss
(
'#about-page p'
).
text
()
.
elementByCss
(
'#about-page p'
).
text
()
expect
(
text
).
toBe
(
'This is the About page'
)
expect
(
text
).
toBe
(
'This is the About page
foo
'
)
browser
.
close
()
browser
.
close
()
})
})
...
@@ -31,7 +31,7 @@ export default function (context) {
...
@@ -31,7 +31,7 @@ export default function (context) {
.
waitForElementByCss
(
'#about-page'
)
.
waitForElementByCss
(
'#about-page'
)
.
elementByCss
(
'#about-page p'
).
text
()
.
elementByCss
(
'#about-page p'
).
text
()
expect
(
text
).
toBe
(
'This is the About page'
)
expect
(
text
).
toBe
(
'This is the About page
foo
'
)
browser
.
close
()
browser
.
close
()
})
})
...
...
test/integration/export/test/ssr.js
View file @
bd249180
...
@@ -9,6 +9,11 @@ export default function (context) {
...
@@ -9,6 +9,11 @@ export default function (context) {
expect
(
html
).
toMatch
(
/This is the home page/
)
expect
(
html
).
toMatch
(
/This is the home page/
)
})
})
it
(
'should render the about page'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
context
.
port
,
'/about'
)
expect
(
html
).
toMatch
(
/This is the About page foobar/
)
})
it
(
'should render links correctly'
,
async
()
=>
{
it
(
'should render links correctly'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
context
.
port
,
'/'
)
const
html
=
await
renderViaHTTP
(
context
.
port
,
'/'
)
const
$
=
cheerio
.
load
(
html
)
const
$
=
cheerio
.
load
(
html
)
...
...
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