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
dcc32284
Commit
dcc32284
authored
May 08, 2017
by
Arunoda Susiripala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow next export to build html pages.
parent
be2e5a8c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
6 deletions
+48
-6
document.js
server/document.js
+2
-2
export.js
server/export.js
+46
-4
No files found.
server/document.js
View file @
dcc32284
...
@@ -71,7 +71,7 @@ export class Head extends Component {
...
@@ -71,7 +71,7 @@ export class Head extends Component {
return
<
head
>
return
<
head
>
<
link
rel
=
'preload'
href
=
{
`
${
assetPrefix
}
/_next/
${
buildId
}
/page
${
realPathname
}
`
}
as
=
'script'
/>
<
link
rel
=
'preload'
href
=
{
`
${
assetPrefix
}
/_next/
${
buildId
}
/page
${
realPathname
}
`
}
as
=
'script'
/>
<
link
rel
=
'preload'
href
=
{
`
${
assetPrefix
}
/_next/
${
buildId
}
/page/_error`
}
as
=
'script'
/>
<
link
rel
=
'preload'
href
=
{
`
${
assetPrefix
}
/_next/
${
buildId
}
/page/_error
.js
`
}
as
=
'script'
/>
{
this
.
getPreloadMainLinks
()}
{
this
.
getPreloadMainLinks
()}
{(
head
||
[]).
map
((
h
,
i
)
=>
React
.
cloneElement
(
h
,
{
key
:
i
}))}
{(
head
||
[]).
map
((
h
,
i
)
=>
React
.
cloneElement
(
h
,
{
key
:
i
}))}
{
styles
||
null
}
{
styles
||
null
}
...
@@ -148,7 +148,7 @@ export class NextScript extends Component {
...
@@ -148,7 +148,7 @@ export class NextScript extends Component {
`
`
}}
/>
}
}}
/>
}
<
script
async
type
=
'text/javascript'
src
=
{
`
${
assetPrefix
}
/_next/
${
buildId
}
/page
${
realPathname
}
`
}
/
>
<
script
async
type
=
'text/javascript'
src
=
{
`
${
assetPrefix
}
/_next/
${
buildId
}
/page
${
realPathname
}
`
}
/
>
<
script
async
type
=
'text/javascript'
src
=
{
`
${
assetPrefix
}
/_next/
${
buildId
}
/page/_error`
}
/
>
<
script
async
type
=
'text/javascript'
src
=
{
`
${
assetPrefix
}
/_next/
${
buildId
}
/page/_error
.js
`
}
/
>
{
staticMarkup
?
null
:
this
.
getScripts
()}
{
staticMarkup
?
null
:
this
.
getScripts
()}
<
/div
>
<
/div
>
}
}
...
...
server/export.js
View file @
dcc32284
import
del
from
'del'
import
del
from
'del'
import
cp
from
'recursive-copy'
import
cp
from
'recursive-copy'
import
mkdirp
from
'mkdirp-then'
import
mkdirp
from
'mkdirp-then'
import
{
resolve
,
join
}
from
'path'
import
{
resolve
,
join
,
dirname
,
sep
}
from
'path'
import
{
existsSync
,
readFileSync
}
from
'fs'
import
{
existsSync
,
readFileSync
,
writeFileSync
}
from
'fs'
import
getConfig
from
'./config'
import
{
renderToHTML
}
from
'./render'
import
{
printAndExit
}
from
'../lib/utils'
export
default
async
function
(
dir
)
{
export
default
async
function
(
dir
)
{
const
outDir
=
resolve
(
dir
,
'.out'
)
dir
=
resolve
(
dir
)
const
nextDir
=
resolve
(
dir
,
'.next'
)
const
outDir
=
join
(
dir
,
'.out'
)
const
nextDir
=
join
(
dir
,
'.next'
)
if
(
!
existsSync
(
nextDir
))
{
if
(
!
existsSync
(
nextDir
))
{
console
.
error
(
'Build your with "next build" before running "next start".'
)
console
.
error
(
'Build your with "next build" before running "next start".'
)
process
.
exit
(
1
)
process
.
exit
(
1
)
}
}
const
config
=
getConfig
(
dir
)
const
buildId
=
readFileSync
(
join
(
nextDir
,
'BUILD_ID'
),
'utf8'
)
const
buildId
=
readFileSync
(
join
(
nextDir
,
'BUILD_ID'
),
'utf8'
)
const
buildStats
=
require
(
join
(
nextDir
,
'build-stats.json'
))
const
buildStats
=
require
(
join
(
nextDir
,
'build-stats.json'
))
...
@@ -31,4 +36,41 @@ export default async function (dir) {
...
@@ -31,4 +36,41 @@ export default async function (dir) {
join
(
nextDir
,
'bundles'
,
'pages'
),
join
(
nextDir
,
'bundles'
,
'pages'
),
join
(
outDir
,
'_next'
,
buildId
,
'page'
)
join
(
outDir
,
'_next'
,
buildId
,
'page'
)
)
)
// Start the rendering process
const
renderOpts
=
{
dir
,
buildStats
,
buildId
,
assetPrefix
:
config
.
assetPrefix
.
replace
(
/
\/
$/
,
''
),
dev
:
false
,
staticMarkup
:
false
,
hotReloader
:
null
}
// Get the exportPathMap from the `next.config.js`
if
(
typeof
config
.
exportPathMap
!==
'function'
)
{
printAndExit
(
'> Could not found "exportPathMap" function inside "next.config.js"
\
n'
+
'> "next export" uses that function build html pages.'
)
}
const
exportPathMap
=
await
config
.
exportPathMap
()
const
exportPaths
=
Object
.
keys
(
exportPathMap
)
for
(
const
path
of
exportPaths
)
{
const
{
page
,
query
}
=
exportPathMap
[
path
]
const
req
=
{
url
:
path
}
const
res
=
{}
const
htmlFilename
=
page
===
'/'
?
'index.html'
:
`
${
page
}${
sep
}
index.html`
const
baseDir
=
join
(
outDir
,
dirname
(
htmlFilename
))
const
htmlFilepath
=
join
(
outDir
,
htmlFilename
)
await
mkdirp
(
baseDir
)
const
html
=
await
renderToHTML
(
req
,
res
,
page
,
query
,
renderOpts
)
writeFileSync
(
htmlFilepath
,
html
,
'utf8'
)
}
}
}
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