Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 866319c

Browse files
committed
Merge with master.
2 parents 4f26e84 + 9347c8b commit 866319c

File tree

22 files changed

+288
-80
lines changed

22 files changed

+288
-80
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ npm-debug.log
1111
# coverage
1212
.nyc_output
1313
coverage
14+
15+
.DS_Store

bin/next-build

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ if (argv.help) {
2222
Usage
2323
$ next build <dir>
2424
25-
<dir> represents where the compiled .next folder should go.
26-
If no directory is provided, .next will be created in the current directory
25+
<dir> represents where the compiled dist folder should go.
26+
If no directory is provided, the dist folder will be created in the current directory.
27+
You can set a custom folder in config https://github.com/zeit/next.js#custom-configuration, otherwise it will be created inside '.next'
2728
`)
2829
process.exit(0)
2930
}

bin/next-dev

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ if (argv.help) {
2929
Usage
3030
$ next dev <dir> -p <port number>
3131
32-
<dir> represents where the compiled .next folder should go.
33-
If no directory is provided, .next will be created in the current directory
32+
<dir> represents where the compiled folder should go.
33+
If no directory is provided, the folder will be created in the current directory.
34+
You can set a custom folder in config https://github.com/zeit/next.js#custom-configuration.
3435
3536
Options
3637
--port, -p A port number on which to start the application

bin/next-start

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { resolve } from 'path'
44
import parseArgs from 'minimist'
55
import Server from '../server'
66
import { existsSync } from 'fs'
7+
import getConfig from '../server/config'
78

89
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
910

@@ -32,9 +33,10 @@ if (argv.help) {
3233
Usage
3334
$ next start <dir> -p <port>
3435
35-
<dir> is the directory that contains the compiled .next folder
36+
<dir> is the directory that contains the compiled dist folder
3637
created by running \`next build\`.
3738
If no directory is provided, the current directory will be assumed.
39+
You can set a custom dist folder in config https://github.com/zeit/next.js#custom-configuration
3840
3941
Options
4042
--port, -p A port number on which to start the application
@@ -45,11 +47,12 @@ if (argv.help) {
4547
}
4648

4749
const dir = resolve(argv._[0] || '.')
50+
const dist = getConfig(dir).distDir
4851

4952
const srv = new Server({ dir })
5053

51-
if (!existsSync(resolve(dir, '.next', 'BUILD_ID'))) {
52-
console.error(`> Could not find a valid build in the '.next' directory! Try building your app with 'next build' before starting the server.`)
54+
if (!existsSync(resolve(dir, dist, 'BUILD_ID'))) {
55+
console.error(`> Could not find a valid build in the '${dist}' directory! Try building your app with 'next build' before starting the server.`)
5356
process.exit(1)
5457
}
5558

examples/with-glamorous/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
# Example app with [glamorous](https://github.com/kentcdodds/glamorous)
3+
4+
## How to use
5+
6+
Download the example [or clone the repo](https://github.com/zeit/next.js):
7+
8+
```bash
9+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-glamorous
10+
cd with-glamorous
11+
```
12+
13+
Install it and run:
14+
15+
```bash
16+
npm install
17+
npm run dev
18+
```
19+
20+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
21+
22+
```bash
23+
now
24+
```
25+
26+
## The idea behind the example
27+
28+
This example features how to use [glamorous](https://github.com/kentcdodds/glamorous) as the styling solution instead of [styled-jsx](https://github.com/zeit/styled-jsx). It also incorporates [glamor](https://github.com/threepointone/glamor) since `glamor` is a dependency for `glamorous`.
29+
30+
We are creating three `div` elements with custom styles being shared across the elements. The styles includes the use of pseedo-elements and CSS animations.

examples/with-glamorous/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "with-glamorous",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"dev": "next",
6+
"build": "next build",
7+
"start": "next start"
8+
},
9+
"dependencies": {
10+
"glamor": "^2.20.24",
11+
"glamorous": "^1.0.0",
12+
"next": "^2.0.1",
13+
"react": "^15.4.2",
14+
"react-dom": "^15.4.2"
15+
},
16+
"author": "",
17+
"license": "ISC"
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Document, { Head, Main, NextScript } from 'next/document'
2+
import { renderStatic } from 'glamor/server'
3+
4+
export default class MyDocument extends Document {
5+
static async getInitialProps ({ renderPage }) {
6+
const page = renderPage()
7+
const styles = renderStatic(() => page.html)
8+
return { ...page, ...styles }
9+
}
10+
11+
constructor (props) {
12+
super(props)
13+
const { __NEXT_DATA__, ids } = props
14+
if (ids) {
15+
__NEXT_DATA__.ids = this.props.ids
16+
}
17+
}
18+
19+
render () {
20+
return (
21+
<html>
22+
<Head>
23+
<title>With Glamorous</title>
24+
<style dangerouslySetInnerHTML={{ __html: this.props.css }} />
25+
</Head>
26+
<body>
27+
<Main />
28+
<NextScript />
29+
</body>
30+
</html>
31+
)
32+
}
33+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from 'react'
2+
import { rehydrate, css } from 'glamor'
3+
import glamorous from 'glamorous'
4+
5+
// Adds server generated styles to glamor cache.
6+
// Has to run before any `style()` calls
7+
// '__NEXT_DATA__.ids' is set in '_document.js'
8+
if (typeof window !== 'undefined') {
9+
rehydrate(window.__NEXT_DATA__.ids)
10+
}
11+
12+
export default () => {
13+
css.global('html, body', { padding: '3rem 1rem', margin: 0, background: 'papayawhip', 'min-height': '100%', 'font-family': 'Helvetica, Arial, sans-serif', 'font-size': '24px' })
14+
15+
const basicStyles = {
16+
backgroundColor: 'white',
17+
color: 'cornflowerblue',
18+
border: '1px solid lightgreen',
19+
borderRight: 'none',
20+
borderBottom: 'none',
21+
boxShadow: '5px 5px 0 0 lightgreen, 10px 10px 0 0 lightyellow',
22+
transition: 'all 0.1s linear',
23+
margin: `3rem 0`,
24+
padding: `1rem 0.5rem`
25+
}
26+
27+
const hoverStyles = {
28+
':hover': {
29+
color: 'white',
30+
backgroundColor: 'lightgray',
31+
borderColor: 'aqua',
32+
boxShadow: `-15px -15px 0 0 aqua, -30px -30px 0 0 cornflowerblue`
33+
},
34+
'& code': {
35+
backgroundColor: 'linen'
36+
}
37+
}
38+
39+
const crazyStyles = props => {
40+
const crazyStyles = hoverStyles
41+
const bounce = css.keyframes({
42+
'0%': { transform: `scale(1.01)` },
43+
'100%': { transform: `scale(0.99)` }
44+
})
45+
crazyStyles.animation = `${bounce} 0.2s infinite ease-in-out alternate`
46+
return crazyStyles
47+
}
48+
49+
const Basic = glamorous.div(basicStyles)
50+
const Combined = glamorous.div(basicStyles, hoverStyles)
51+
const Animated = glamorous.div(basicStyles, hoverStyles, crazyStyles)
52+
53+
return (
54+
<div>
55+
<Basic>
56+
Cool Styles
57+
</Basic>
58+
<Combined>
59+
With <code>:hover</code>.
60+
</Combined>
61+
<Animated>
62+
Let's bounce.
63+
</Animated>
64+
</div>
65+
)
66+
}

examples/with-universal-configuration/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
Download the example [or clone the repo](https://github.com/zeit/next.js):
77

88
```bash
9-
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/basic-css
10-
cd basic-css
9+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-universal-configuration
10+
cd with-universal-configuration
1111
```
1212

1313
Install it and run:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"cross-spawn": "5.1.0",
6666
"del": "2.2.2",
6767
"friendly-errors-webpack-plugin": "1.5.0",
68+
"glob": "^7.1.1",
6869
"glob-promise": "3.1.0",
6970
"htmlescape": "1.1.1",
7071
"http-status": "1.0.1",
@@ -90,7 +91,7 @@
9091
"uuid": "3.0.1",
9192
"webpack": "2.3.3",
9293
"webpack-dev-middleware": "1.10.1",
93-
"webpack-hot-middleware": "2.17.1",
94+
"webpack-hot-middleware": "2.18.0",
9495
"write-file-webpack-plugin": "4.0.0"
9596
},
9697
"devDependencies": {

readme.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,17 @@ module.exports = {
644644
}
645645
```
646646

647+
#### Setting a custom build directory
648+
649+
You can specify a name to use for a custom build directory. For example, the following config will create a `build` folder instead of a `.next` folder. If no configuration is specified then next will create a `.next` folder.
650+
651+
```javascript
652+
// next.config.js
653+
module.exports = {
654+
distDir: 'build'
655+
}
656+
```
657+
647658
### Customizing webpack config
648659

649660
In order to extend our usage of `webpack`, you can define a function that extends its config via `next.config.js`.
@@ -718,7 +729,7 @@ Then run `now` and enjoy!
718729

719730
Next.js can be deployed to other hosting solutions too. Please have a look at the ['Deployment'](https://github.com/zeit/next.js/wiki/Deployment) section of the wiki.
720731

721-
Note: we recommend putting `.next` in `.npmignore` or `.gitignore`. Otherwise, use `files` or `now.files` to opt-into a whitelist of files you want to deploy (and obviously exclude `.next`)
732+
Note: we recommend putting `.next`, or your custom dist folder (Please have a look at ['Custom Config'](You can set a custom folder in config https://github.com/zeit/next.js#custom-configuration.)), in `.npmignore` or `.gitignore`. Otherwise, use `files` or `now.files` to opt-into a whitelist of files you want to deploy (and obviously exclude `.next` or your custom dist folder)
722733

723734
## FAQ
724735

server/build/clean.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { resolve } from 'path'
22
import del from 'del'
3+
import getConfig from '../config'
34

45
export default function clean (dir) {
5-
return del(resolve(dir, '.next'))
6+
const dist = getConfig(dir).distDir
7+
return del(resolve(dir, dist))
68
}

server/build/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { tmpdir } from 'os'
22
import { join } from 'path'
3+
import getConfig from '../config'
34
import fs from 'mz/fs'
45
import uuid from 'uuid'
56
import del from 'del'
@@ -13,8 +14,10 @@ export default async function build (dir) {
1314

1415
try {
1516
await runCompiler(compiler)
16-
await writeBuildStats(buildDir)
17-
await writeBuildId(buildDir)
17+
18+
// Pass in both the buildDir and the dir to retrieve config
19+
await writeBuildStats(buildDir, dir)
20+
await writeBuildId(buildDir, dir)
1821
} catch (err) {
1922
console.error(`> Failed to build on ${buildDir}`)
2023
throw err
@@ -45,22 +48,24 @@ function runCompiler (compiler) {
4548
})
4649
}
4750

48-
async function writeBuildStats (dir) {
51+
async function writeBuildStats (buildDir, dir) {
52+
const dist = getConfig(dir).distDir
4953
// Here we can't use hashes in webpack chunks.
5054
// That's because the "app.js" is not tied to a chunk.
5155
// It's created by merging a few assets. (commons.js and main.js)
5256
// So, we need to generate the hash ourself.
5357
const assetHashMap = {
5458
'app.js': {
55-
hash: await md5File(join(dir, '.next', 'app.js'))
59+
hash: await md5File(join(buildDir, dist, 'app.js'))
5660
}
5761
}
58-
const buildStatsPath = join(dir, '.next', 'build-stats.json')
62+
const buildStatsPath = join(buildDir, dist, 'build-stats.json')
5963
await fs.writeFile(buildStatsPath, JSON.stringify(assetHashMap), 'utf8')
6064
}
6165

62-
async function writeBuildId (dir) {
63-
const buildIdPath = join(dir, '.next', 'BUILD_ID')
66+
async function writeBuildId (buildDir, dir) {
67+
const dist = getConfig(dir).distDir
68+
const buildIdPath = join(buildDir, dist, 'BUILD_ID')
6469
const buildId = uuid.v4()
6570
await fs.writeFile(buildIdPath, buildId, 'utf8')
6671
}

server/build/replace.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import mv from 'mv'
22
import { join } from 'path'
3+
import getConfig from '../config'
34

45
export default async function replaceCurrentBuild (dir, buildDir) {
5-
const _dir = join(dir, '.next')
6-
const _buildDir = join(buildDir, '.next')
7-
const oldDir = join(buildDir, '.next.old')
6+
const dist = getConfig(dir).distDir
7+
const buildDist = getConfig(buildDir).distDir
8+
const _dir = join(dir, dist)
9+
const _buildDir = join(buildDir, dist)
10+
const oldDir = join(buildDir, `${buildDist}.old`)
811

912
try {
1013
await move(_dir, oldDir)

server/build/webpack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
265265
context: dir,
266266
entry,
267267
output: {
268-
path: join(buildDir || dir, '.next'),
268+
path: join(buildDir || dir, config.distDir),
269269
filename: '[name]',
270270
libraryTarget: 'commonjs2',
271271
publicPath: '/_webpack/',

server/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const cache = new Map()
55

66
const defaultConfig = {
77
webpack: null,
8-
poweredByHeader: true
8+
poweredByHeader: true,
9+
distDir: '.next'
910
}
1011

1112
export default function getConfig (dir) {

0 commit comments

Comments
 (0)