-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add next export
for static builds
#1576
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
810decb
next-export: build static pages using next.js
matthewmueller a29d584
next-export: build static pages using next.js
matthewmueller e20f469
call getInitialProps() on load when it's a static build
matthewmueller ae6070f
remove console.log
matthewmueller e1d0126
fix up next export -h
matthewmueller 45eaee9
replace getInitialProps({ build: true }) with getBuildProps() so no e…
matthewmueller 540a0e1
add that static/ directory to the build
matthewmueller 7a8fd6b
change export signature to: next export -o <out> <dir>
matthewmueller 17c2c62
fix spacing and add a comment
matthewmueller a7df927
getBuildProps() => getStaticInitialProps()
matthewmueller a722438
fix conditional
matthewmueller d54ed04
add full page refresh test
matthewmueller a1d6cde
fix passing the query object on initial page load
matthewmueller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ npm-debug.log | |
# coverage | ||
.nyc_output | ||
coverage | ||
|
||
# osx | ||
.DS_Store | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ const commands = new Set([ | |
'init', | ||
'build', | ||
'start', | ||
'export', | ||
defaultCommand | ||
]) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env node | ||
import { resolve, join } from 'path' | ||
import { existsSync } from 'fs' | ||
import parseArgs from 'minimist' | ||
import Build from '../server/build' | ||
import Export from '../server/export' | ||
import { printAndExit } from '../lib/utils' | ||
|
||
process.env.NODE_ENV = process.env.NODE_ENV || 'production' | ||
|
||
const argv = parseArgs(process.argv.slice(2), { | ||
alias: { | ||
h: 'help', | ||
o: 'out' | ||
}, | ||
boolean: ['h'] | ||
}) | ||
|
||
if (argv.help) { | ||
console.log(` | ||
Description | ||
Compiles and exports the application to a static website | ||
|
||
Usage | ||
$ next export <dir> | ||
$ next export --out <out> <dir> | ||
|
||
<dir> represents where the compiled folder should go. | ||
If no directory is provided, <dir> will be the current directory. | ||
|
||
<out> represents where the static directory will go. | ||
If no directory is provided, <out> will be <dir>/site. | ||
`) | ||
process.exit(0) | ||
} | ||
|
||
const dir = resolve(argv._[0] || '.') | ||
const out = resolve(dir, argv['out'] || 'site') | ||
|
||
// Check if pages dir exists and warn if not | ||
if (!existsSync(dir)) { | ||
printAndExit(`> No such directory exists as the project root: ${dir}`) | ||
} | ||
|
||
if (!existsSync(join(dir, 'pages'))) { | ||
if (existsSync(join(dir, '..', 'pages'))) { | ||
printAndExit('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?') | ||
} | ||
|
||
printAndExit('> Couldn\'t find a `pages` directory. Please create one under the project root') | ||
} | ||
|
||
Build(dir) | ||
.then(() => Export({ dir, out })) | ||
.catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Component } from 'react' | ||
import Router from 'next/router' | ||
|
||
export default class About extends Component { | ||
constructor (props) { | ||
super(props) | ||
this.state = {} | ||
} | ||
|
||
static async getInitialProps (ctx) { | ||
console.log('loading about!', ctx) | ||
return {} | ||
} | ||
|
||
static async getStaticInitialProps (ctx) { | ||
console.log('build props', ctx) | ||
return {} | ||
} | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<h2>About Me</h2> | ||
<a onClick={() => Router.push('/')}>Go Back to Index</a> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Component } from 'react' | ||
import Button from '../ui/button' | ||
import Link from 'next/link' | ||
|
||
export default class Index extends Component { | ||
constructor (props) { | ||
super(props) | ||
this.state = { | ||
answer: '' | ||
} | ||
} | ||
|
||
static async getInitialProps ({ pathname }) { | ||
return { | ||
title: 'Hello Static Stack!' | ||
} | ||
} | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<h2>{this.props.title}</h2> | ||
<Link href='/about'><a>Learn more about me</a></Link> | ||
<br /> | ||
<br /> | ||
<Button onClick={() => this.setState({ answer: 'yes.' })}> | ||
Did Rehydration Work? | ||
</Button> | ||
<br /> | ||
<br /> | ||
<div>{this.state.answer}</div> | ||
<br /> | ||
<Link href='/movies'><a>Check out the movies</a></Link> | ||
<a onClick={() => (document.location.pathname = '/about')}>Go to my about page</a> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
import { Component } from 'react' | ||
import Link from 'next/link' | ||
|
||
export default class Movies extends Component { | ||
constructor (props) { | ||
super(props) | ||
this.state = {} | ||
} | ||
|
||
render (props) { | ||
return ( | ||
<div> | ||
<h2>Some of my favorite movies</h2> | ||
<Link href='/'><a>Go Back to Index</a></Link> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default ({ onClick, children }) => ( | ||
<button onClick={onClick}>{children}</button> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should remove this, add it in your ~/.gitconfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i sort of feel like it's the project's job to prevent stuff like this from getting committed, but i don't care much either way 😄. let's see what others think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with Matthew
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree it should always be in your global gitignore