├── .npmrc ├── test ├── isolated │ └── _resolvedata │ │ ├── one.js │ │ ├── aa │ │ └── index.js │ │ ├── cc │ │ ├── index.js │ │ └── index.json │ │ ├── one.json │ │ ├── two.json │ │ └── bb │ │ └── index.json ├── integration │ ├── basic │ │ ├── lib │ │ │ ├── data.json │ │ │ └── cdm.js │ │ ├── pages │ │ │ ├── no-default-export.js │ │ │ ├── index.js │ │ │ ├── with-cdm.js │ │ │ ├── nested-cdm │ │ │ │ └── index.js │ │ │ ├── error.js │ │ │ ├── stateless.js │ │ │ ├── json.js │ │ │ ├── dynamic │ │ │ │ ├── ssr.js │ │ │ │ ├── no-ssr.js │ │ │ │ └── no-ssr-custom-loading.js │ │ │ ├── hmr │ │ │ │ └── about.js │ │ │ ├── styled-jsx.js │ │ │ ├── link.js │ │ │ ├── empty-get-initial-props.js │ │ │ ├── finish-response.js │ │ │ ├── head.js │ │ │ ├── nav │ │ │ │ ├── about.js │ │ │ │ ├── as-path.js │ │ │ │ ├── redirect.js │ │ │ │ ├── as-path-using-router.js │ │ │ │ ├── self-reload.js │ │ │ │ ├── querystring.js │ │ │ │ └── hash-changes.js │ │ │ ├── async-props.js │ │ │ └── stateful.js │ │ ├── components │ │ │ └── hello1.js │ │ ├── next.config.js │ │ └── test │ │ │ └── misc.js │ ├── dist-dir │ │ ├── pages │ │ │ └── index.js │ │ └── next.config.js │ ├── ondemand │ │ ├── pages │ │ │ ├── about.js │ │ │ └── index.js │ │ └── next.config.js │ ├── production │ │ └── pages │ │ │ ├── about.js │ │ │ └── index.js │ └── static │ │ ├── components │ │ └── hello.js │ │ ├── pages │ │ ├── about.js │ │ ├── level1 │ │ │ ├── about.js │ │ │ └── index.js │ │ ├── dynamic-imports.js │ │ ├── dynamic.js │ │ └── counter.js │ │ ├── next.config.js │ │ └── test │ │ ├── index.test.js │ │ └── ssr.js └── unit │ └── shallow-equal.test.js ├── examples ├── .gitignore ├── .babelrc ├── with-typescript │ ├── .gitignore │ ├── components │ │ └── MyComponent.tsx │ ├── tsconfig.json │ ├── pages │ │ └── index.tsx │ ├── package.json │ └── README.md ├── with-external-scoped-css │ ├── .gitignore │ ├── pages │ │ ├── index.sass │ │ ├── index.js │ │ └── _document.js │ ├── pre-processor.js │ ├── .babelrc │ ├── package.json │ └── README.md ├── with-react-intl │ ├── .gitignore │ ├── lang │ │ ├── en.json │ │ └── fr.json │ ├── .babelrc │ ├── package.json │ ├── pages │ │ ├── about.js │ │ ├── index.js │ │ └── _document.js │ ├── components │ │ ├── Layout.js │ │ └── Nav.js │ └── scripts │ │ └── default-lang.js ├── custom-server-koa │ ├── pages │ │ ├── a.js │ │ ├── b.js │ │ └── index.js │ ├── package.json │ └── server.js ├── root-static-files │ ├── static │ │ ├── robots.txt │ │ ├── favicon.ico │ │ └── sitemap.xml │ ├── pages │ │ └── index.js │ ├── package.json │ ├── README.md │ └── server.js ├── custom-server-express │ ├── pages │ │ ├── a.js │ │ ├── b.js │ │ └── index.js │ ├── package.json │ └── server.js ├── with-i18next │ ├── static │ │ └── locales │ │ │ └── pt │ │ │ └── common.json │ ├── components │ │ └── Title.js │ ├── tools │ │ ├── startI18n.js │ │ └── translationHelpers.js │ ├── package.json │ ├── pages │ │ └── index.js │ └── README.md ├── hello-world │ ├── pages │ │ ├── about.js │ │ └── index.js │ ├── package.json │ └── README.md ├── with-shallow-routing │ ├── pages │ │ └── about.js │ ├── package.json │ └── README.md ├── custom-server │ ├── pages │ │ ├── a.js │ │ ├── b.js │ │ └── index.js │ ├── package.json │ └── server.js ├── with-flow │ ├── .flowconfig │ ├── with-flow.gif │ ├── .babelrc │ ├── pages │ │ ├── index.js │ │ ├── about.js │ │ └── contact.js │ ├── package.json │ ├── components │ │ └── layout.js │ └── README.md ├── with-react-helmet │ ├── pages │ │ └── index.js │ ├── package.json │ └── README.md ├── with-styled-jsx-postcss │ ├── .babelrc │ ├── postcss.config.js │ ├── babel-preset.js │ ├── package.json │ ├── pages │ │ └── index.js │ └── README.md ├── custom-server-hapi │ ├── pages │ │ ├── a.js │ │ ├── b.js │ │ └── index.js │ ├── package.json │ └── next-wrapper.js ├── with-firebase │ ├── credentials │ │ ├── client.js │ │ └── server.js │ └── package.json ├── with-next-routes │ ├── pages │ │ ├── about.js │ │ ├── index.js │ │ └── blog.js │ ├── routes.js │ ├── package.json │ └── server.js ├── with-webpack-bundle-analyzer │ ├── pages │ │ ├── about.js │ │ └── index.js │ ├── package.json │ ├── next.config.js │ └── README.md ├── svg-components │ ├── .babelrc │ ├── package.json │ ├── pages │ │ └── index.js │ └── README.md ├── with-amp │ ├── static │ │ ├── cat.jpg │ │ └── dog.jpg │ ├── components │ │ └── Byline.js │ ├── package.json │ └── README.md ├── with-custom-babel-config │ ├── .babelrc │ └── package.json ├── with-react-md │ ├── static │ │ └── react-md.light_blue-yellow.min.css │ ├── next.config.js │ └── package.json ├── with-scoped-stylesheets-and-postcss │ ├── pages │ │ ├── styles.css │ │ └── index.js │ ├── postcss.config.js │ ├── .babelrc │ └── package.json ├── using-inferno │ ├── pages │ │ ├── about.js │ │ └── index.js │ ├── next.config.js │ ├── package.json │ ├── server.js │ └── README.md ├── using-preact │ ├── pages │ │ ├── about.js │ │ └── index.js │ ├── package.json │ ├── next.config.js │ ├── server.js │ └── README.md ├── with-dynamic-import │ ├── components │ │ ├── hello1.js │ │ ├── hello2.js │ │ ├── hello3.js │ │ ├── hello4.js │ │ ├── hello5.js │ │ ├── Header.js │ │ └── Counter.js │ ├── pages │ │ └── about.js │ ├── package.json │ └── README.md ├── with-global-stylesheet │ ├── example.gif │ ├── styles │ │ ├── index.css │ │ └── index.scss │ ├── postcss.config.js │ ├── pages │ │ └── index.js │ ├── .babelrc │ ├── package.json │ └── next.config.js ├── with-mobx │ ├── .babelrc │ ├── package.json │ ├── server.js │ ├── components │ │ ├── Clock.js │ │ └── Page.js │ ├── pages │ │ ├── other.js │ │ └── index.js │ └── store.js ├── with-refnux │ ├── store │ │ ├── setTitle.js │ │ ├── getInitialState.js │ │ ├── counterIncrement.js │ │ └── getStore.js │ ├── package.json │ ├── helpers │ │ └── getStore.js │ └── pages │ │ ├── page2.js │ │ └── page1.js ├── with-universal-configuration │ ├── pages │ │ └── index.js │ ├── .babelrc │ ├── env-config.js │ └── package.json ├── layout-component │ ├── pages │ │ ├── index.js │ │ ├── about.js │ │ └── contact.js │ ├── package.json │ ├── components │ │ └── layout.js │ └── README.md ├── using-router │ ├── pages │ │ ├── index.js │ │ ├── about.js │ │ └── error.js │ ├── package.json │ ├── components │ │ └── Header.js │ └── README.md ├── with-prefetching │ ├── pages │ │ ├── about.js │ │ ├── index.js │ │ ├── contact.js │ │ └── features.js │ ├── package.json │ ├── components │ │ └── Header.js │ └── README.md ├── with-styled-components │ ├── .babelrc │ ├── pages │ │ ├── index.js │ │ └── _document.js │ └── package.json ├── with-jest │ ├── pages │ │ └── index.js │ ├── __tests__ │ │ ├── __snapshots__ │ │ │ └── index.test.js.snap │ │ └── index.test.js │ ├── .babelrc │ ├── package.json │ └── README.md ├── with-loading │ ├── pages │ │ ├── index.js │ │ ├── about.js │ │ └── forever.js │ ├── package.json │ └── components │ │ └── Header.js ├── with-styletron │ ├── next.config.js │ ├── layout.js │ ├── pages │ │ ├── index.js │ │ └── _document.js │ ├── package.json │ └── styletron.js ├── nested-components │ ├── components │ │ ├── paragraph.js │ │ └── post.js │ ├── package.json │ ├── pages │ │ └── index.js │ └── README.md ├── shared-modules │ ├── pages │ │ ├── index.js │ │ └── about.js │ ├── components │ │ ├── Header.js │ │ └── Counter.js │ ├── package.json │ └── README.md ├── with-fela │ ├── layout.js │ ├── package.json │ ├── fela.js │ └── pages │ │ ├── index.js │ │ └── _document.js ├── with-apollo-and-redux │ ├── lib │ │ └── reducers.js │ ├── pages │ │ └── index.js │ ├── package.json │ └── components │ │ ├── Header.js │ │ └── App.js ├── parameterized-routing │ ├── package.json │ ├── pages │ │ ├── index.js │ │ └── blog.js │ ├── server.js │ └── README.md ├── progressive-render │ ├── package.json │ ├── components │ │ └── Loading.js │ └── pages │ │ └── index.js ├── with-material-ui │ ├── next.config.js │ ├── package.json │ └── README.md ├── with-pretty-url-routing │ ├── pages │ │ ├── index.js │ │ └── greeting.js │ ├── package.json │ ├── routes.js │ ├── server.js │ └── README.md ├── with-url-object-routing │ ├── package.json │ ├── pages │ │ ├── index.js │ │ └── about.js │ ├── server.js │ └── README.md ├── basic-css │ ├── package.json │ ├── pages │ │ └── index.js │ └── README.md ├── ssr-caching │ ├── package.json │ ├── pages │ │ ├── index.js │ │ └── blog.js │ └── README.md ├── head-elements │ ├── package.json │ ├── pages │ │ └── index.js │ └── README.md ├── with-cxs │ ├── package.json │ └── pages │ │ ├── _document.js │ │ └── index.js ├── with-glamor │ ├── package.json │ └── pages │ │ ├── index.js │ │ └── _document.js ├── data-fetch │ ├── package.json │ ├── pages │ │ ├── index.js │ │ └── preact.js │ └── README.md ├── with-aphrodite │ ├── package.json │ └── pages │ │ └── index.js ├── with-apollo │ ├── pages │ │ └── index.js │ ├── package.json │ └── components │ │ ├── Header.js │ │ └── App.js ├── with-semantic-ui │ ├── package.json │ └── README.md ├── with-glamorous │ ├── package.json │ └── pages │ │ └── _document.js ├── with-socket.io │ ├── package.json │ ├── server.js │ └── README.md └── with-redux │ ├── package.json │ ├── components │ ├── Page.js │ ├── Clock.js │ └── AddCount.js │ └── pages │ ├── other.js │ └── index.js ├── css.js ├── error.js ├── head.js ├── link.js ├── pages ├── _error.js └── _document.js ├── dynamic.js ├── prefetch.js ├── router.js ├── document.js ├── babel.js ├── bench ├── pages │ ├── stateless.js │ └── stateless-big.js ├── package.json └── readme.md ├── server ├── next.js ├── require.js ├── build │ ├── clean.js │ ├── replace.js │ ├── babel │ │ └── find-config.js │ ├── plugins │ │ ├── unlink-file-plugin.js │ │ ├── watch-pages-plugin.js │ │ └── combine-assets-plugin.js │ ├── loaders │ │ └── emit-file-loader.js │ └── root-module-relative-path.js ├── router.js └── config.js ├── client ├── next.js └── on-demand-entries-client.js ├── lib ├── css.js ├── shallow-equals.js └── prefetch.js ├── .gitignore ├── .babelrc ├── .travis.yml ├── appveyor.yml ├── wallaby.js ├── contributing.md └── license.md /.npmrc: -------------------------------------------------------------------------------- 1 | save-exact = true 2 | -------------------------------------------------------------------------------- /test/isolated/_resolvedata/one.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | **/yarn.lock 2 | -------------------------------------------------------------------------------- /test/isolated/_resolvedata/aa/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/isolated/_resolvedata/cc/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/isolated/_resolvedata/one.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/isolated/_resolvedata/two.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/isolated/_resolvedata/bb/index.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/isolated/_resolvedata/cc/index.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "babelrc": false 3 | } -------------------------------------------------------------------------------- /examples/with-typescript/.gitignore: -------------------------------------------------------------------------------- 1 | **/*.js 2 | -------------------------------------------------------------------------------- /css.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/lib/css') 2 | -------------------------------------------------------------------------------- /examples/with-external-scoped-css/.gitignore: -------------------------------------------------------------------------------- 1 | static -------------------------------------------------------------------------------- /error.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/lib/error') 2 | -------------------------------------------------------------------------------- /examples/with-react-intl/.gitignore: -------------------------------------------------------------------------------- 1 | lang/.messages/ 2 | -------------------------------------------------------------------------------- /head.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/lib/head') 2 | -------------------------------------------------------------------------------- /link.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/lib/link') 2 | -------------------------------------------------------------------------------- /pages/_error.js: -------------------------------------------------------------------------------- 1 | module.exports = require('next/error') 2 | -------------------------------------------------------------------------------- /dynamic.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/lib/dynamic') 2 | -------------------------------------------------------------------------------- /prefetch.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/lib/prefetch') 2 | -------------------------------------------------------------------------------- /router.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/lib/router') 2 | -------------------------------------------------------------------------------- /document.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/server/document') 2 | -------------------------------------------------------------------------------- /pages/_document.js: -------------------------------------------------------------------------------- 1 | module.exports = require('next/document') 2 | -------------------------------------------------------------------------------- /test/integration/basic/lib/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Zeit" 3 | } -------------------------------------------------------------------------------- /babel.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/server/build/babel/preset') 2 | -------------------------------------------------------------------------------- /bench/pages/stateless.js: -------------------------------------------------------------------------------- 1 | export default () =>

My component!

2 | -------------------------------------------------------------------------------- /test/integration/basic/pages/no-default-export.js: -------------------------------------------------------------------------------- 1 | export default {} 2 | -------------------------------------------------------------------------------- /examples/custom-server-koa/pages/a.js: -------------------------------------------------------------------------------- 1 | export default () =>
a
2 | -------------------------------------------------------------------------------- /examples/custom-server-koa/pages/b.js: -------------------------------------------------------------------------------- 1 | export default () =>
b
2 | -------------------------------------------------------------------------------- /examples/root-static-files/static/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: / 3 | -------------------------------------------------------------------------------- /examples/custom-server-express/pages/a.js: -------------------------------------------------------------------------------- 1 | export default () =>
a
2 | -------------------------------------------------------------------------------- /examples/custom-server-express/pages/b.js: -------------------------------------------------------------------------------- 1 | export default () =>
b
2 | -------------------------------------------------------------------------------- /examples/with-i18next/static/locales/pt/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "hello": "e ae tche" 3 | } -------------------------------------------------------------------------------- /test/integration/basic/pages/index.js: -------------------------------------------------------------------------------- 1 | import CDM from '../lib/cdm' 2 | export default CDM 3 | -------------------------------------------------------------------------------- /examples/hello-world/pages/about.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
About us
3 | ) 4 | -------------------------------------------------------------------------------- /test/integration/basic/pages/with-cdm.js: -------------------------------------------------------------------------------- 1 | import CDM from '../lib/cdm' 2 | export default CDM 3 | -------------------------------------------------------------------------------- /examples/with-shallow-routing/pages/about.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
About us
3 | ) 4 | -------------------------------------------------------------------------------- /test/integration/basic/components/hello1.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |

Hello World 1

3 | ) 4 | -------------------------------------------------------------------------------- /test/integration/dist-dir/pages/index.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
Hello World
3 | ) 4 | -------------------------------------------------------------------------------- /examples/custom-server/pages/a.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default () =>
a
4 | -------------------------------------------------------------------------------- /examples/custom-server/pages/b.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default () =>
b
4 | -------------------------------------------------------------------------------- /examples/with-flow/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | [include] 4 | 5 | [libs] 6 | types/ 7 | 8 | [options] 9 | -------------------------------------------------------------------------------- /examples/with-react-helmet/pages/index.js: -------------------------------------------------------------------------------- 1 | export default () => (
2 | Hello World! 3 |
) 4 | -------------------------------------------------------------------------------- /examples/with-styled-jsx-postcss/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "./babel-preset" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /test/integration/basic/pages/nested-cdm/index.js: -------------------------------------------------------------------------------- 1 | import CDM from '../../lib/cdm' 2 | export default CDM 3 | -------------------------------------------------------------------------------- /examples/custom-server-hapi/pages/a.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default () =>
a
4 | -------------------------------------------------------------------------------- /examples/custom-server-hapi/pages/b.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default () =>
b
4 | -------------------------------------------------------------------------------- /examples/with-firebase/credentials/client.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // TODO firebase client config 3 | } 4 | -------------------------------------------------------------------------------- /examples/with-firebase/credentials/server.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // TODO firebase server config 3 | } 4 | -------------------------------------------------------------------------------- /examples/with-next-routes/pages/about.js: -------------------------------------------------------------------------------- 1 | export default props =>

About foo {props.url.query.foo}

2 | -------------------------------------------------------------------------------- /examples/with-webpack-bundle-analyzer/pages/about.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
About us
3 | ) 4 | -------------------------------------------------------------------------------- /server/next.js: -------------------------------------------------------------------------------- 1 | import Server from './' 2 | 3 | module.exports = (opts) => { 4 | return new Server(opts) 5 | } 6 | -------------------------------------------------------------------------------- /examples/svg-components/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ "next/babel" ], 3 | "plugins": [ "inline-react-svg" ] 4 | } 5 | -------------------------------------------------------------------------------- /examples/with-amp/static/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tscanlin/next.js/v3-beta/examples/with-amp/static/cat.jpg -------------------------------------------------------------------------------- /examples/with-amp/static/dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tscanlin/next.js/v3-beta/examples/with-amp/static/dog.jpg -------------------------------------------------------------------------------- /examples/with-custom-babel-config/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "next/babel", 4 | "stage-0" 5 | ], 6 | } 7 | -------------------------------------------------------------------------------- /examples/with-flow/with-flow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tscanlin/next.js/v3-beta/examples/with-flow/with-flow.gif -------------------------------------------------------------------------------- /test/integration/basic/pages/error.js: -------------------------------------------------------------------------------- 1 | export default () => { 2 | throw new Error('This is an expected error') 3 | } 4 | -------------------------------------------------------------------------------- /examples/with-external-scoped-css/pages/index.sass: -------------------------------------------------------------------------------- 1 | .example 2 | font-size: 36px 3 | width: 300px 4 | margin: 100px auto -------------------------------------------------------------------------------- /examples/with-react-md/static/react-md.light_blue-yellow.min.css: -------------------------------------------------------------------------------- 1 | ../node_modules/react-md/dist/react-md.light_blue-yellow.min.css -------------------------------------------------------------------------------- /examples/with-scoped-stylesheets-and-postcss/pages/styles.css: -------------------------------------------------------------------------------- 1 | .paragraph { 2 | font-size: 20px; 3 | color: red; 4 | } 5 | -------------------------------------------------------------------------------- /test/integration/basic/pages/stateless.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default () =>

My component!

4 | -------------------------------------------------------------------------------- /test/integration/ondemand/pages/about.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
3 |

About Page

4 |
5 | ) 6 | -------------------------------------------------------------------------------- /test/integration/production/pages/about.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
About Page
3 | ) 4 | -------------------------------------------------------------------------------- /examples/using-inferno/pages/about.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default () => ( 4 |
About us
5 | ) 6 | -------------------------------------------------------------------------------- /examples/using-preact/pages/about.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default () => ( 4 |
About us
5 | ) 6 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/components/hello1.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |

Hello World 1 (imported dynamiclly)

3 | ) 4 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/components/hello2.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |

Hello World 2 (imported dynamiclly)

3 | ) 4 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/components/hello3.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |

Hello World 3 (imported dynamiclly)

3 | ) 4 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/components/hello4.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |

Hello World 4 (imported dynamiclly)

3 | ) 4 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/components/hello5.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |

Hello World 5 (imported dynamiclly)

3 | ) 4 | -------------------------------------------------------------------------------- /test/integration/static/components/hello.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |

3 | Welcome to dynamic imports. 4 |

5 | ) 6 | -------------------------------------------------------------------------------- /test/integration/basic/pages/json.js: -------------------------------------------------------------------------------- 1 | import data from '../lib/data' 2 | 3 | export default () => ( 4 |
{data.name}
5 | ) 6 | -------------------------------------------------------------------------------- /test/integration/ondemand/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | onDemandEntries: { 3 | maxInactiveAge: 1000 * 5 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /client/next.js: -------------------------------------------------------------------------------- 1 | import next from './' 2 | 3 | next() 4 | .catch((err) => { 5 | console.error(`${err.message}\n${err.stack}`) 6 | }) 7 | -------------------------------------------------------------------------------- /examples/with-global-stylesheet/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tscanlin/next.js/v3-beta/examples/with-global-stylesheet/example.gif -------------------------------------------------------------------------------- /examples/with-global-stylesheet/styles/index.css: -------------------------------------------------------------------------------- 1 | @import 'normalize.css'; 2 | 3 | p { 4 | font-size: xx-large; 5 | color: black; 6 | } 7 | -------------------------------------------------------------------------------- /examples/with-styled-jsx-postcss/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = () => ({ 2 | plugins: { 3 | 'postcss-cssnext': {} 4 | } 5 | }) 6 | -------------------------------------------------------------------------------- /examples/root-static-files/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tscanlin/next.js/v3-beta/examples/root-static-files/static/favicon.ico -------------------------------------------------------------------------------- /examples/with-amp/components/Byline.js: -------------------------------------------------------------------------------- 1 | export default ({ author }) => ( 2 |
3 | By {author} 4 |
5 | ) 6 | -------------------------------------------------------------------------------- /examples/with-mobx/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "next/babel" 4 | ], 5 | "plugins": [ 6 | "transform-decorators-legacy" 7 | ] 8 | } -------------------------------------------------------------------------------- /examples/with-scoped-stylesheets-and-postcss/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | require('postcss-cssnext')() 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /examples/with-flow/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "next/babel" 4 | ], 5 | "plugins": [ 6 | "transform-flow-strip-types" 7 | ] 8 | } -------------------------------------------------------------------------------- /examples/with-refnux/store/setTitle.js: -------------------------------------------------------------------------------- 1 | 2 | const setTitle = (newTitle) => ({title}) => { 3 | return { title: newTitle } 4 | } 5 | 6 | export default setTitle 7 | -------------------------------------------------------------------------------- /examples/hello-world/pages/index.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | export default () => ( 3 |
Hello World. About
4 | ) 5 | -------------------------------------------------------------------------------- /examples/with-i18next/components/Title.js: -------------------------------------------------------------------------------- 1 | import { translate } from 'react-i18next' 2 | export default translate(['common'])((props) => (

{props.t('hello')}

)) 3 | -------------------------------------------------------------------------------- /examples/with-universal-configuration/pages/index.js: -------------------------------------------------------------------------------- 1 | /* global BACKEND_URL */ 2 | 3 | export default () => ( 4 |
Loading data from { BACKEND_URL }
5 | ) 6 | -------------------------------------------------------------------------------- /examples/with-typescript/components/MyComponent.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | 3 | export default () => 4 |
5 |

This is my component

6 |
7 | -------------------------------------------------------------------------------- /lib/css.js: -------------------------------------------------------------------------------- 1 | throw new Error(`'next/css' has been removed in Next.js 2.0. Please refer to the migration guide: https://github.com/zeit/next.js/wiki/Migrating-from-next-css`) 2 | -------------------------------------------------------------------------------- /test/integration/basic/pages/dynamic/ssr.js: -------------------------------------------------------------------------------- 1 | import dynamic from 'next/dynamic' 2 | 3 | const Hello = dynamic(import('../../components/hello1')) 4 | 5 | export default Hello 6 | -------------------------------------------------------------------------------- /examples/with-universal-configuration/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "next/babel" 4 | ], 5 | "plugins": [ 6 | ["transform-define", "./env-config.js"] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /server/require.js: -------------------------------------------------------------------------------- 1 | import resolve from './resolve' 2 | 3 | export default async function requireModule (path) { 4 | const f = await resolve(path) 5 | return require(f) 6 | } 7 | -------------------------------------------------------------------------------- /examples/layout-component/pages/index.js: -------------------------------------------------------------------------------- 1 | import Layout from '../components/layout' 2 | 3 | export default () => ( 4 | 5 |
Hello World.
6 |
7 | ) 8 | -------------------------------------------------------------------------------- /examples/with-global-stylesheet/styles/index.scss: -------------------------------------------------------------------------------- 1 | @import 'normalize.css'; 2 | 3 | $primary-color: black; 4 | 5 | p { 6 | font-size: xx-large; 7 | color: $primary-color; 8 | } 9 | -------------------------------------------------------------------------------- /examples/with-refnux/store/getInitialState.js: -------------------------------------------------------------------------------- 1 | const getInitialState = () => { 2 | return { 3 | title: '', 4 | counter: 0 5 | } 6 | } 7 | 8 | export default getInitialState 9 | -------------------------------------------------------------------------------- /examples/with-webpack-bundle-analyzer/pages/index.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | export default () => ( 3 |
Hello World. About
4 | ) 5 | -------------------------------------------------------------------------------- /test/integration/basic/pages/hmr/about.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
3 |

4 | This is the about page. 5 |

6 |
7 | ) 8 | -------------------------------------------------------------------------------- /examples/with-refnux/store/counterIncrement.js: -------------------------------------------------------------------------------- 1 | 2 | const counterIncrement = ({counter}, dispatch) => { 3 | return { counter: counter + 1 } 4 | } 5 | 6 | export default counterIncrement 7 | -------------------------------------------------------------------------------- /test/integration/basic/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | onDemandEntries: { 3 | // Make sure entries are not getting disposed. 4 | maxInactiveAge: 1000 * 60 * 60 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/integration/basic/pages/styled-jsx.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
3 |

This is blue

4 | 5 |
6 | ) 7 | -------------------------------------------------------------------------------- /examples/using-router/pages/index.js: -------------------------------------------------------------------------------- 1 | import Header from '../components/Header' 2 | 3 | export default () => ( 4 |
5 |
6 |

HOME PAGE is here!

7 |
8 | ) 9 | -------------------------------------------------------------------------------- /test/integration/basic/pages/dynamic/no-ssr.js: -------------------------------------------------------------------------------- 1 | import dynamic from 'next/dynamic' 2 | 3 | const Hello = dynamic(import('../../components/hello1'), { ssr: false }) 4 | 5 | export default Hello 6 | -------------------------------------------------------------------------------- /examples/layout-component/pages/about.js: -------------------------------------------------------------------------------- 1 | import Layout from '../components/layout' 2 | 3 | export default () => ( 4 | 5 |
About us
6 |
7 | ) 8 | -------------------------------------------------------------------------------- /examples/layout-component/pages/contact.js: -------------------------------------------------------------------------------- 1 | import Layout from '../components/layout' 2 | 3 | export default () => ( 4 | 5 |
Contact
6 |
7 | ) 8 | -------------------------------------------------------------------------------- /examples/using-router/pages/about.js: -------------------------------------------------------------------------------- 1 | import Header from '../components/Header' 2 | 3 | export default () => ( 4 |
5 |
6 |

This is the about page.

7 |
8 | ) 9 | -------------------------------------------------------------------------------- /test/integration/basic/pages/link.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | export default () => ( 4 |
Hello World. About
5 | ) 6 | -------------------------------------------------------------------------------- /examples/using-preact/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | 4 | export default () => ( 5 |
Hello World. About
6 | ) 7 | -------------------------------------------------------------------------------- /examples/with-flow/pages/index.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 3 | import Layout from '../components/layout' 4 | 5 | export default () => ( 6 | 7 |
Hello World.
8 |
9 | ) 10 | -------------------------------------------------------------------------------- /examples/with-prefetching/pages/about.js: -------------------------------------------------------------------------------- 1 | import Header from '../components/Header' 2 | 3 | export default () => ( 4 |
5 |
6 |

This is the ABOUT page.

7 |
8 | ) 9 | -------------------------------------------------------------------------------- /examples/with-prefetching/pages/index.js: -------------------------------------------------------------------------------- 1 | import Header from '../components/Header' 2 | 3 | export default () => ( 4 |
5 |
6 |

This is the HOME page

7 |
8 | ) 9 | -------------------------------------------------------------------------------- /examples/with-prefetching/pages/contact.js: -------------------------------------------------------------------------------- 1 | import Header from '../components/Header' 2 | 3 | export default () => ( 4 |
5 |
6 |

This is the CONTACT page.

7 |
8 | ) 9 | -------------------------------------------------------------------------------- /examples/with-prefetching/pages/features.js: -------------------------------------------------------------------------------- 1 | import Header from '../components/Header' 2 | 3 | export default () => ( 4 |
5 |
6 |

This is the FEATURES page.

7 |
8 | ) 9 | -------------------------------------------------------------------------------- /examples/with-typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es2015", 5 | "jsx": "react", 6 | "allowJs": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/using-inferno/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | 4 | export default () => ( 5 |
Hello World. About
6 | ) 7 | -------------------------------------------------------------------------------- /examples/with-styled-components/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "next/babel" 4 | ], 5 | "plugins": [ 6 | ["styled-components", { "ssr": true, "displayName": true, "preprocess": false } ] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/integration/basic/pages/empty-get-initial-props.js: -------------------------------------------------------------------------------- 1 | const EmptyInitialPropsPage = () => (
My Page
) 2 | EmptyInitialPropsPage.getInitialProps = () => null 3 | 4 | export default EmptyInitialPropsPage 5 | -------------------------------------------------------------------------------- /test/integration/production/pages/index.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 |
5 | About Page 6 |

Hello World

7 |
8 | ) 9 | -------------------------------------------------------------------------------- /examples/with-flow/pages/about.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 3 | import Layout from '../components/layout' 4 | 5 | export default () => ( 6 | 7 |
About us
8 |
9 | ) 10 | -------------------------------------------------------------------------------- /examples/with-jest/pages/index.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
3 | 8 |

Hello World!

9 |
10 | ) 11 | -------------------------------------------------------------------------------- /examples/with-scoped-stylesheets-and-postcss/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "next/babel" 4 | ], 5 | "plugins": [ 6 | ["wrap-in-js", { 7 | "extensions": ["css$"] 8 | }] 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /examples/with-universal-configuration/env-config.js: -------------------------------------------------------------------------------- 1 | const prod = process.env.NODE_ENV === 'production' 2 | 3 | module.exports = { 4 | 'BACKEND_URL': prod ? 'https://api.example.com' : 'https://localhost:8080' 5 | } 6 | -------------------------------------------------------------------------------- /test/integration/dist-dir/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | onDemandEntries: { 3 | // Make sure entries are not getting disposed. 4 | maxInactiveAge: 1000 * 60 * 60 5 | }, 6 | distDir: 'dist' 7 | } 8 | -------------------------------------------------------------------------------- /examples/with-flow/pages/contact.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 3 | import Layout from '../components/layout' 4 | 5 | export default () => ( 6 | 7 |
Contact
8 |
9 | ) 10 | -------------------------------------------------------------------------------- /examples/with-next-routes/routes.js: -------------------------------------------------------------------------------- 1 | const nextRoutes = require('next-routes') 2 | const routes = module.exports = nextRoutes() 3 | 4 | routes.add('blog', '/blog/:slug') 5 | routes.add('about', '/about-us/:foo(bar|baz)') 6 | -------------------------------------------------------------------------------- /examples/with-loading/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Header from '../components/Header' 3 | 4 | export default () => ( 5 |
6 |
7 |

Hello Next!

8 |
9 | ) 10 | -------------------------------------------------------------------------------- /test/integration/ondemand/pages/index.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 |
5 |

Index Page

6 | About Page 7 |
8 | ) 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # build output 2 | dist 3 | .next 4 | 5 | # dependencies 6 | node_modules 7 | 8 | # logs 9 | *.log 10 | 11 | # coverage 12 | .nyc_output 13 | coverage 14 | 15 | # test output 16 | test/**/out 17 | .DS_Store 18 | -------------------------------------------------------------------------------- /examples/with-typescript/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import MyComponent from '../components/MyComponent' 3 | 4 | export default () => 5 |
6 |

Hello world

7 | 8 |
9 | -------------------------------------------------------------------------------- /examples/root-static-files/static/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://www.example.com/foo.html 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/with-styletron/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | webpack: function (config) { 3 | config.externals = config.externals || {} 4 | config.externals['styletron-server'] = 'styletron-server' 5 | return config 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/with-react-intl/lang/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "React Intl Next.js Example", 3 | "nav.home": "Home", 4 | "nav.about": "About", 5 | "description": "An example app integrating React Intl with Next.js", 6 | "greeting": "Hello, World!" 7 | } -------------------------------------------------------------------------------- /server/build/clean.js: -------------------------------------------------------------------------------- 1 | import { resolve } from 'path' 2 | import del from 'del' 3 | import getConfig from '../config' 4 | 5 | export default function clean (dir) { 6 | const dist = getConfig(dir).distDir 7 | return del(resolve(dir, dist)) 8 | } 9 | -------------------------------------------------------------------------------- /examples/with-styled-components/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import styled from 'styled-components' 3 | 4 | const Title = styled.h1` 5 | color: red; 6 | font-size: 50px; 7 | ` 8 | 9 | export default () => My page 10 | -------------------------------------------------------------------------------- /test/integration/basic/pages/dynamic/no-ssr-custom-loading.js: -------------------------------------------------------------------------------- 1 | import dynamic from 'next/dynamic' 2 | 3 | const Hello = dynamic(import('../../components/hello1'), { 4 | ssr: false, 5 | loading: () => (

LOADING

) 6 | }) 7 | 8 | export default Hello 9 | -------------------------------------------------------------------------------- /examples/root-static-files/pages/index.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 | 7 | ) 8 | -------------------------------------------------------------------------------- /examples/with-global-stylesheet/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | require('postcss-easy-import')({prefix: '_'}), // keep this first 4 | require('autoprefixer')({ /* ...options */ }) // so imports are auto-prefixed too 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /lib/shallow-equals.js: -------------------------------------------------------------------------------- 1 | export default function shallowEquals (a, b) { 2 | for (const i in a) { 3 | if (b[i] !== a[i]) return false 4 | } 5 | 6 | for (const i in b) { 7 | if (b[i] !== a[i]) return false 8 | } 9 | 10 | return true 11 | } 12 | -------------------------------------------------------------------------------- /examples/nested-components/components/paragraph.js: -------------------------------------------------------------------------------- 1 | export default ({ children }) => ( 2 |

3 | {children} 4 | 10 |

11 | ) 12 | -------------------------------------------------------------------------------- /examples/shared-modules/pages/index.js: -------------------------------------------------------------------------------- 1 | import Header from '../components/Header' 2 | import Counter from '../components/Counter' 3 | 4 | export default () => ( 5 |
6 |
7 |

HOME PAGE is here!

8 | 9 |
10 | ) 11 | -------------------------------------------------------------------------------- /examples/with-fela/layout.js: -------------------------------------------------------------------------------- 1 | import { Provider } from 'react-fela' 2 | import { getRenderer, getMountNode } from './fela' 3 | 4 | export default ({ children }) => ( 5 | 6 | {children} 7 | 8 | ) 9 | -------------------------------------------------------------------------------- /examples/with-react-intl/lang/fr.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "React Intl Next.js Exemple", 3 | "nav.home": "Accueil", 4 | "nav.about": "À propos de nous", 5 | "description": "Un exemple d'application intégrant React Intl avec Next.js", 6 | "greeting": "Bonjour le monde!" 7 | } 8 | -------------------------------------------------------------------------------- /examples/with-styletron/layout.js: -------------------------------------------------------------------------------- 1 | import { StyletronProvider } from 'styletron-react' 2 | import getStyletron from './styletron' 3 | 4 | export default ({ children }) => ( 5 | 6 | {children} 7 | 8 | ) 9 | -------------------------------------------------------------------------------- /examples/custom-server/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | 4 | export default () => ( 5 | 9 | ) 10 | -------------------------------------------------------------------------------- /examples/shared-modules/pages/about.js: -------------------------------------------------------------------------------- 1 | import Header from '../components/Header' 2 | import Counter from '../components/Counter' 3 | 4 | export default () => ( 5 |
6 |
7 |

This is the about page.

8 | 9 |
10 | ) 11 | -------------------------------------------------------------------------------- /examples/with-i18next/tools/startI18n.js: -------------------------------------------------------------------------------- 1 | import i18n from 'i18next' 2 | 3 | const startI18n = file => i18n.init({ 4 | fallbackLng: 'pt', 5 | resources: file, 6 | ns: ['common'], 7 | defaultNS: 'common', 8 | debug: false 9 | }) 10 | 11 | export default startI18n 12 | -------------------------------------------------------------------------------- /examples/with-react-md/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | webpack: function (config) { 3 | if (config.resolve.alias) { 4 | delete config.resolve.alias['react'] 5 | delete config.resolve.alias['react-dom'] 6 | } 7 | return config 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/custom-server-express/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | 4 | export default () => ( 5 | 9 | ) 10 | -------------------------------------------------------------------------------- /examples/custom-server-hapi/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | 4 | export default () => ( 5 | 9 | ) 10 | -------------------------------------------------------------------------------- /examples/custom-server-koa/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | 4 | export default () => ( 5 | 9 | ) 10 | -------------------------------------------------------------------------------- /test/integration/basic/pages/finish-response.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | 3 | export default class extends Component { 4 | static getInitialProps ({ res }) { 5 | res.end('hi') 6 | } 7 | 8 | render () { 9 | return
hi
10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/integration/basic/pages/head.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Head from 'next/head' 3 | 4 | export default () =>
5 | 6 | 7 | 8 | 9 |

I can haz meta tags

10 |
11 | -------------------------------------------------------------------------------- /test/integration/basic/pages/nav/about.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 |
5 | 6 | Go Back 7 | 8 | 9 |

This is the about page.

10 |
11 | ) 12 | -------------------------------------------------------------------------------- /test/integration/static/pages/about.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 |
5 |
6 | 7 | Go Back 8 | 9 |
10 |

This is the About page

11 |
12 | ) 13 | -------------------------------------------------------------------------------- /examples/with-apollo-and-redux/lib/reducers.js: -------------------------------------------------------------------------------- 1 | export default { 2 | example: (state = {}, { type, payload }) => { 3 | switch (type) { 4 | case 'EXAMPLE_ACTION': 5 | return { 6 | ...state 7 | } 8 | default: 9 | return state 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/with-external-scoped-css/pre-processor.js: -------------------------------------------------------------------------------- 1 | const sass = require('node-sass') 2 | 3 | module.exports = (data, filename) => { 4 | return sass.renderSync({ 5 | data, 6 | file: filename, 7 | indentedSyntax: true, 8 | outputStyle: 'compressed' 9 | }).css.toString('utf8') 10 | } 11 | -------------------------------------------------------------------------------- /examples/with-styletron/pages/index.js: -------------------------------------------------------------------------------- 1 | import { styled } from 'styletron-react' 2 | import Page from '../layout' 3 | 4 | const Title = styled('div', { 5 | color: 'red', 6 | fontSize: '50px' 7 | }) 8 | 9 | export default () => ( 10 | 11 | My page 12 | 13 | ) 14 | -------------------------------------------------------------------------------- /examples/custom-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "node server.js", 4 | "build": "next build", 5 | "start": "NODE_ENV=production node server.js" 6 | }, 7 | "dependencies": { 8 | "next": "latest", 9 | "react": "^15.4.2", 10 | "react-dom": "^15.4.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/pages/about.js: -------------------------------------------------------------------------------- 1 | import Header from '../components/Header' 2 | import Counter from '../components/Counter' 3 | 4 | const About = () => ( 5 |
6 |
7 |

This is the about page.

8 | 9 |
10 | ) 11 | 12 | export default About 13 | -------------------------------------------------------------------------------- /test/integration/static/pages/level1/about.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 |
5 |
6 | 7 | Go Back 8 | 9 |
10 |

This is the Level1 about page

11 |
12 | ) 13 | -------------------------------------------------------------------------------- /test/integration/static/pages/level1/index.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 |
5 |
6 | 7 | Go Back 8 | 9 |
10 |

This is the Level1 home page

11 |
12 | ) 13 | -------------------------------------------------------------------------------- /bench/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "next-bench", 3 | "scripts": { 4 | "build": "next build", 5 | "start": "npm run build && next start", 6 | "bench:stateless": "ab -c1 -n3000 http://0.0.0.0:3000/stateless", 7 | "bench:stateless-big": "ab -c1 -n500 http://0.0.0.0:3000/stateless-big" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/root-static-files/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "node server.js", 4 | "build": "next build", 5 | "start": "NODE_ENV=production node server.js" 6 | }, 7 | "dependencies": { 8 | "next": "latest", 9 | "react": "^15.5.4", 10 | "react-dom": "^15.5.4" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/with-external-scoped-css/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ss from './index.sass' 3 | 4 | export const IndexPage = () => ( 5 |
6 | This is an example from scoped style in a outside CSS file {'<3'} 7 |
8 | ) 9 | 10 | export default IndexPage 11 | -------------------------------------------------------------------------------- /examples/with-jest/__tests__/__snapshots__/index.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`With Snapshot Testing App shows "Hello world!" 1`] = ` 4 |
7 |

10 | Hello World! 11 |

12 |
13 | `; 14 | -------------------------------------------------------------------------------- /examples/with-typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "concurrently \"tsc --watch\" next" 4 | }, 5 | "dependencies": { 6 | "next": "latest" 7 | }, 8 | "devDependencies": { 9 | "@types/react": "^15.0.1", 10 | "concurrently": "^3.1.0", 11 | "typescript": "^2.1.5" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/with-external-scoped-css/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["next/babel"], 3 | "plugins": [ 4 | [ 5 | "css-modules-transform", { 6 | "extensions": [".css", ".sass"], 7 | "extractCss": "./static/css/bundle.css", 8 | "preprocessCss": "./pre-processor.js" 9 | } 10 | ] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /examples/with-jest/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "development": { 4 | "presets": "next/babel" 5 | }, 6 | "production": { 7 | "presets": "next/babel" 8 | }, 9 | "test": { 10 | "presets": [ 11 | ["env", { "modules": "commonjs" }], 12 | "next/babel" 13 | ] 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/custom-server-express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "node server.js", 4 | "build": "next build", 5 | "start": "NODE_ENV=production node server.js" 6 | }, 7 | "dependencies": { 8 | "express": "^4.14.0", 9 | "next": "latest", 10 | "react": "^15.4.2", 11 | "react-dom": "^15.4.2" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/parameterized-routing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "node server.js", 4 | "build": "next build", 5 | "start": "NODE_ENV=production node server.js" 6 | }, 7 | "dependencies": { 8 | "next": "latest", 9 | "path-match": "1.2.4", 10 | "react": "^15.4.2", 11 | "react-dom": "^15.4.2" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/with-next-routes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "node server.js", 4 | "build": "next build", 5 | "start": "NODE_ENV=production node server.js" 6 | }, 7 | "dependencies": { 8 | "next": "latest", 9 | "next-routes": "^1.0.17", 10 | "react": "^15.4.2", 11 | "react-dom": "^15.4.2" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "env", 4 | "react" 5 | ], 6 | "plugins": [ 7 | "transform-object-rest-spread", 8 | "transform-class-properties", 9 | "transform-runtime" 10 | ], 11 | "env": { 12 | "test": { 13 | "presets": [ 14 | "es2015", 15 | "./babel" 16 | ] 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/progressive-render/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "progressive-render", 3 | "scripts": { 4 | "dev": "next", 5 | "build": "next build", 6 | "start": "next start" 7 | }, 8 | "dependencies": { 9 | "next": "latest", 10 | "react": "^15.4.2", 11 | "react-dom": "^15.4.2", 12 | "react-no-ssr": "1.1.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/with-material-ui/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | webpack: (config) => { 3 | // Remove minifed react aliases for material-ui so production builds work 4 | if (config.resolve.alias) { 5 | delete config.resolve.alias.react 6 | delete config.resolve.alias['react-dom'] 7 | } 8 | 9 | return config 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/with-pretty-url-routing/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default function IndexPage () { 4 | return ( 5 |
6 |

Homepage

7 |
8 | Name: 9 | 10 |
11 |
12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /examples/with-url-object-routing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "node server.js", 4 | "build": "next build", 5 | "start": "NODE_ENV=production node server.js" 6 | }, 7 | "dependencies": { 8 | "next": "latest", 9 | "path-match": "1.2.4", 10 | "react": "^15.4.2", 11 | "react-dom": "^15.4.2" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/with-global-stylesheet/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | import stylesheet from 'styles/index.scss' 4 | // or, if you work with plain css 5 | // import stylesheet from 'styles/index.css' 6 | 7 | export default () => 8 |
9 | 14 |
15 | ) 16 | -------------------------------------------------------------------------------- /examples/svg-components/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "svg-components", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "latest" 11 | }, 12 | "devDependencies": { 13 | "babel-plugin-inline-react-svg": "^0.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/with-scoped-stylesheets-and-postcss/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Head from 'next/head' 3 | import {stylesheet, classNames} from './styles.css' 4 | 5 | export default () => ( 6 |

7 | 14 | 15 | ) 16 | -------------------------------------------------------------------------------- /examples/with-react-intl/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "next/babel" 4 | ], 5 | "env": { 6 | "development": { 7 | "plugins": [ 8 | "react-intl" 9 | ] 10 | }, 11 | "production": { 12 | "plugins": [ 13 | ["react-intl", { 14 | "messagesDir": "lang/.messages/" 15 | }] 16 | ] 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/nested-components/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nested-components", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "*", 11 | "react": "^15.4.2", 12 | "react-dom": "^15.4.2" 13 | }, 14 | "author": "", 15 | "license": "ISC" 16 | } 17 | -------------------------------------------------------------------------------- /examples/with-fela/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-fela", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "fela": "^4.1.2", 11 | "next": "latest", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2", 14 | "react-fela": "^4.1.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/with-prefetching/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-prefetching", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "latest", 11 | "react": "^15.4.2", 12 | "react-dom": "^15.4.2" 13 | }, 14 | "author": "", 15 | "license": "ISC" 16 | } 17 | -------------------------------------------------------------------------------- /examples/with-styled-jsx-postcss/babel-preset.js: -------------------------------------------------------------------------------- 1 | const nextBabelPreset = require('next/babel') 2 | 3 | nextBabelPreset.plugins = nextBabelPreset.plugins.map(plugin => { 4 | if (!Array.isArray(plugin) && plugin.indexOf('styled-jsx/babel') !== -1) { 5 | return require.resolve('styled-jsx-postcss/babel') 6 | } 7 | return plugin 8 | }) 9 | 10 | module.exports = nextBabelPreset 11 | -------------------------------------------------------------------------------- /examples/shared-modules/components/Header.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 |

5 | 6 | Home 7 | 8 | 9 | 10 | About 11 | 12 |
13 | ) 14 | 15 | const styles = { 16 | a: { 17 | marginRight: 10 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/with-shallow-routing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-shallow-routing", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "latest", 11 | "react": "^15.4.2", 12 | "react-dom": "^15.4.2" 13 | }, 14 | "author": "", 15 | "license": "ISC" 16 | } 17 | -------------------------------------------------------------------------------- /examples/with-cxs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-cxs", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "cxs": "^3.0.0", 11 | "next": "latest", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/components/Header.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 |
5 | 6 | Home 7 | 8 | 9 | 10 | About 11 | 12 |
13 | ) 14 | 15 | const styles = { 16 | a: { 17 | marginRight: 10 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/custom-server-hapi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "node server.js", 4 | "build": "next build", 5 | "start": "NODE_ENV=production node server.js" 6 | }, 7 | "dependencies": { 8 | "hapi": "^16.1.0", 9 | "next": "latest", 10 | "react": "^15.4.2", 11 | "react-dom": "^15.4.2", 12 | "good": "^7.1.0", 13 | "good-console": "^6.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/with-react-helmet/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-react-helmet", 3 | "license": "ISC", 4 | "version": "1.0.0", 5 | "scripts": { 6 | "dev": "next", 7 | "build": "next build", 8 | "start": "next start" 9 | }, 10 | "dependencies": { 11 | "next": "latest", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2", 14 | "react-helmet": "^4.0.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/custom-server-koa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-server-koa", 3 | "scripts": { 4 | "dev": "node server.js", 5 | "build": "next build", 6 | "start": "NODE_ENV=production node server.js" 7 | }, 8 | "dependencies": { 9 | "koa": "^2.0.1", 10 | "koa-router": "^7.1.0", 11 | "next": "latest", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/with-glamor/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-glamor", 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 | "next": "latest", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /examples/data-fetch/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "data-fetch", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "isomorphic-fetch": "^2.2.1", 11 | "next": "latest", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /examples/ssr-caching/pages/index.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 | 9 | ) 10 | -------------------------------------------------------------------------------- /examples/with-aphrodite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-aphrodite", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "aphrodite": "^1.1.0", 11 | "next": "latest", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /examples/with-fela/fela.js: -------------------------------------------------------------------------------- 1 | import { createRenderer } from 'fela' 2 | 3 | // add your renderer configuration here 4 | const renderer = createRenderer() 5 | 6 | export function getRenderer () { 7 | return renderer 8 | } 9 | 10 | export function getMountNode () { 11 | if (typeof window !== 'undefined') { 12 | return document.getElementById('fela-stylesheet') 13 | } 14 | 15 | return undefined 16 | } 17 | -------------------------------------------------------------------------------- /examples/with-refnux/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "next.js-example-with-refnux", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "next": "next" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "next": "latest", 13 | "react": "^15.4.2", 14 | "react-dom": "^15.4.2", 15 | "refnux": "^1.3.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/integration/basic/pages/nav/redirect.js: -------------------------------------------------------------------------------- 1 | import Router from 'next/router' 2 | 3 | const Page = () => ( 4 |

This is the page

5 | ) 6 | 7 | Page.getInitialProps = (ctx) => { 8 | if (ctx.res) { 9 | ctx.res.writeHead(302, { Location: '/nav/about' }) 10 | ctx.res.end() 11 | } else { 12 | Router.push('/nav/about') 13 | } 14 | 15 | return {} 16 | } 17 | 18 | export default Page 19 | -------------------------------------------------------------------------------- /test/integration/static/pages/dynamic-imports.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | import dynamic from 'next/dynamic' 3 | 4 | const DynamicComponent = dynamic(import('../components/hello')) 5 | 6 | export default () => ( 7 |
8 |
9 | 10 | Go Back 11 | 12 |
13 | 14 |
15 | ) 16 | -------------------------------------------------------------------------------- /examples/parameterized-routing/pages/index.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default () => ( 4 | 9 | ) 10 | -------------------------------------------------------------------------------- /examples/with-apollo/pages/index.js: -------------------------------------------------------------------------------- 1 | import App from '../components/App' 2 | import Header from '../components/Header' 3 | import Submit from '../components/Submit' 4 | import PostList from '../components/PostList' 5 | import withData from '../lib/withData' 6 | 7 | export default withData((props) => ( 8 | 9 |
10 | 11 | 12 | 13 | )) 14 | -------------------------------------------------------------------------------- /examples/with-pretty-url-routing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "node server.js", 4 | "build": "next build", 5 | "start": "NODE_ENV=production node server.js" 6 | }, 7 | "dependencies": { 8 | "express": "^4.15.2", 9 | "next": "latest", 10 | "next-url-prettifier": "^1.0.2", 11 | "prop-types": "^15.5.6", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/with-semantic-ui/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-semantic-ui", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "latest", 11 | "react": "^15.4.2", 12 | "react-dom": "^15.4.2", 13 | "semantic-ui-react": "^0.68.0" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /test/integration/static/pages/dynamic.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | const DynamicPage = ({ text }) => ( 4 |
5 |
6 | 7 | Go Back 8 | 9 |
10 |

{ text }

11 |
12 | ) 13 | 14 | DynamicPage.getInitialProps = ({ query }) => { 15 | return { text: query.text } 16 | } 17 | 18 | export default DynamicPage 19 | -------------------------------------------------------------------------------- /examples/shared-modules/components/Counter.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | let count = 0 4 | 5 | export default class Counter extends React.Component { 6 | add () { 7 | count += 1 8 | this.forceUpdate() 9 | } 10 | 11 | render () { 12 | return ( 13 |
14 |

Count is: {count}

15 | 16 |
17 | ) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/using-inferno/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | webpack: function (config, { dev }) { 3 | // For the development version, we'll use React. 4 | // Because, it support react hot loading and so on. 5 | if (dev) { 6 | return config 7 | } 8 | 9 | config.resolve.alias = { 10 | 'react': 'inferno-compat', 11 | 'react-dom': 'inferno-compat' 12 | } 13 | return config 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/with-apollo-and-redux/pages/index.js: -------------------------------------------------------------------------------- 1 | import App from '../components/App' 2 | import Header from '../components/Header' 3 | import Submit from '../components/Submit' 4 | import PostList from '../components/PostList' 5 | import withData from '../lib/withData' 6 | 7 | export default withData((props) => ( 8 | 9 |
10 | 11 | 12 | 13 | )) 14 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/components/Counter.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | let count = 0 4 | 5 | export default class Counter extends React.Component { 6 | add () { 7 | count += 1 8 | this.forceUpdate() 9 | } 10 | 11 | render () { 12 | return ( 13 |
14 |

Count is: {count}

15 | 16 |
17 | ) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | addons: 4 | apt: 5 | sources: 6 | - google-chrome 7 | packages: 8 | - google-chrome-stable 9 | language: node_js 10 | node_js: 11 | - "4" 12 | - "6" 13 | cache: 14 | directories: 15 | - node_modules 16 | before_install: 17 | - rm yarn.lock 18 | - export DISPLAY=:99.0 19 | - sh -e /etc/init.d/xvfb start 20 | - sleep 3 21 | after_script: npm run coveralls 22 | -------------------------------------------------------------------------------- /examples/with-glamorous/package.json: -------------------------------------------------------------------------------- 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 | } 19 | -------------------------------------------------------------------------------- /examples/shared-modules/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shared-modules", 3 | "version": "1.0.0", 4 | "description": "This example features:", 5 | "main": "index.js", 6 | "scripts": { 7 | "dev": "next", 8 | "build": "next build", 9 | "start": "next start" 10 | }, 11 | "dependencies": { 12 | "next": "*", 13 | "react": "^15.4.2", 14 | "react-dom": "^15.4.2" 15 | }, 16 | "author": "", 17 | "license": "ISC" 18 | } 19 | -------------------------------------------------------------------------------- /examples/using-preact/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "using-preact", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "node server.js", 6 | "build": "next build", 7 | "start": "NODE_ENV=production node server.js" 8 | }, 9 | "dependencies": { 10 | "module-alias": "^2.0.0", 11 | "next": "latest", 12 | "preact": "^7.2.0", 13 | "preact-compat": "^3.14.0" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /examples/with-global-stylesheet/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "module-resolver", { 5 | "root": ["."], 6 | "alias": { 7 | "styles": "./styles" 8 | }, 9 | "cwd": "babelrc" 10 | }], 11 | [ 12 | "wrap-in-js", 13 | { 14 | "extensions": ["css$", "scss$"] 15 | } 16 | ] 17 | ], 18 | "presets": [ 19 | "next/babel" 20 | ], 21 | "ignore": [] 22 | } 23 | -------------------------------------------------------------------------------- /examples/with-socket.io/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "express": "^4.15.2", 4 | "isomorphic-fetch": "^2.2.1", 5 | "next": "latest", 6 | "react": "^15.5.4", 7 | "react-dom": "^15.5.4", 8 | "socket.io": "^1.7.3", 9 | "socket.io-client": "^1.7.3" 10 | }, 11 | "scripts": { 12 | "dev": "node server.js", 13 | "build": "next build", 14 | "start": "NODE_ENV=production node server.js" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/with-styletron/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-styletron", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "latest", 11 | "react": "^15.4.2", 12 | "react-dom": "^15.4.2", 13 | "styletron-client": "^2.2.0", 14 | "styletron-react": "^2.2.1", 15 | "styletron-server": "^2.2.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/using-router/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shared-modules", 3 | "version": "1.0.0", 4 | "description": "This example features:", 5 | "main": "index.js", 6 | "scripts": { 7 | "dev": "next", 8 | "build": "next build", 9 | "start": "next start" 10 | }, 11 | "dependencies": { 12 | "next": "latest", 13 | "react": "^15.4.2", 14 | "react-dom": "^15.4.2" 15 | }, 16 | "author": "", 17 | "license": "ISC" 18 | } 19 | -------------------------------------------------------------------------------- /examples/with-url-object-routing/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | 4 | const href = { 5 | pathname: '/about', 6 | query: { name: 'next' } 7 | } 8 | 9 | const as = { 10 | pathname: '/about/next', 11 | hash: 'title-1' 12 | } 13 | 14 | export default () => ( 15 |
16 |

Home page

17 | 18 | Go to /about/next 19 | 20 |
21 | ) 22 | -------------------------------------------------------------------------------- /examples/with-refnux/store/getStore.js: -------------------------------------------------------------------------------- 1 | import { createStore } from 'refnux' 2 | 3 | const storeInitialState = { counter: 0, key: 'value' } 4 | 5 | const getStore = () => { 6 | let store = null 7 | if (typeof window === 'undefined') { 8 | store = createStore(storeInitialState) 9 | } else { 10 | store = window.store || createStore(storeInitialState) 11 | window.store = store 12 | } 13 | return store 14 | } 15 | 16 | export default getStore 17 | -------------------------------------------------------------------------------- /examples/basic-css/pages/index.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
3 |

Hello World

4 | 16 |
17 | ) 18 | -------------------------------------------------------------------------------- /test/integration/basic/lib/cdm.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react' 2 | 3 | export default class extends Component { 4 | constructor (props) { 5 | super(props) 6 | 7 | this.state = { 8 | mounted: false 9 | } 10 | } 11 | 12 | componentDidMount () { 13 | this.setState({mounted: true}) 14 | } 15 | 16 | render () { 17 | return

ComponentDidMount {this.state.mounted ? 'executed on client' : 'not executed'}.

18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/integration/basic/pages/async-props.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default class AsyncProps extends React.Component { 4 | static async getInitialProps () { 5 | return await fetchData() 6 | } 7 | 8 | render () { 9 | return

{this.props.name}

10 | } 11 | } 12 | 13 | function fetchData () { 14 | const p = new Promise(resolve => { 15 | setTimeout(() => resolve({ name: 'Diego Milito' }), 10) 16 | }) 17 | return p 18 | } 19 | -------------------------------------------------------------------------------- /examples/using-preact/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | webpack: function (config, { dev }) { 3 | // For the development version, we'll use React. 4 | // Because, it support react hot loading and so on. 5 | if (dev) { 6 | return config 7 | } 8 | 9 | config.resolve.alias = { 10 | 'react': 'preact-compat/dist/preact-compat', 11 | 'react-dom': 'preact-compat/dist/preact-compat' 12 | } 13 | 14 | return config 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/with-i18next/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-i18next", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "i18next": "^7.1.3", 11 | "isomorphic-fetch": "^2.2.1", 12 | "next": "*", 13 | "react": "^15.4.2", 14 | "react-dom": "^15.4.2", 15 | "react-i18next": "^2.2.1" 16 | }, 17 | "author": "", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /examples/with-refnux/helpers/getStore.js: -------------------------------------------------------------------------------- 1 | import { createStore } from 'refnux' 2 | 3 | let storeMemoized = null 4 | 5 | const getStore = (initialState) => { 6 | let store = null 7 | if (typeof window === 'undefined') { 8 | store = createStore(initialState) 9 | } else { 10 | if (!storeMemoized) { 11 | storeMemoized = createStore(initialState) 12 | } 13 | store = storeMemoized 14 | } 15 | return store 16 | } 17 | 18 | export default getStore 19 | -------------------------------------------------------------------------------- /examples/with-universal-configuration/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-env", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "latest", 11 | "react": "^15.4.2", 12 | "react-dom": "^15.4.2" 13 | }, 14 | "devDependencies": { 15 | "babel-plugin-transform-define": "^1.2.0" 16 | }, 17 | "author": "", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /examples/using-router/pages/error.js: -------------------------------------------------------------------------------- 1 | import {Component} from 'react' 2 | import Header from '../components/Header' 3 | import Router from 'next/router' 4 | 5 | export default class extends Component { 6 | static getInitialProps () { 7 | console.log(Router.pathname) 8 | return {} 9 | } 10 | 11 | render () { 12 | return ( 13 |
14 |
15 |

This should not be rendered via SSR

16 |
17 | ) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/with-fela/pages/index.js: -------------------------------------------------------------------------------- 1 | import { createComponent } from 'react-fela' 2 | import Page from '../layout' 3 | 4 | const title = ({ size }) => ({ 5 | fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif', 6 | fontSize: size + 'px', 7 | color: 'red' 8 | }) 9 | 10 | const Title = createComponent(title, 'h1') 11 | 12 | export default () => ( 13 | 14 | My Title 15 | 16 | ) 17 | -------------------------------------------------------------------------------- /examples/with-loading/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-loading", 3 | "version": "1.0.0", 4 | "description": "This example features:", 5 | "main": "index.js", 6 | "scripts": { 7 | "dev": "next", 8 | "build": "next build", 9 | "start": "next start" 10 | }, 11 | "dependencies": { 12 | "next": "latest", 13 | "nprogress": "^0.2.0", 14 | "react": "^15.4.2", 15 | "react-dom": "^15.4.2" 16 | }, 17 | "author": "", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /examples/nested-components/components/post.js: -------------------------------------------------------------------------------- 1 | export default ({ title, children }) => ( 2 |
3 |

{ title }

4 | { children } 5 | 18 |
19 | ) 20 | -------------------------------------------------------------------------------- /examples/using-inferno/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "using-inferno", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "node server.js", 6 | "build": "next build", 7 | "start": "NODE_ENV=production node server.js" 8 | }, 9 | "dependencies": { 10 | "inferno": "^1.4.0", 11 | "inferno-compat": "^1.4.0", 12 | "inferno-server": "^1.4.0", 13 | "module-alias": "^2.0.0", 14 | "next": "latest" 15 | }, 16 | "author": "", 17 | "license": "MIT" 18 | } 19 | -------------------------------------------------------------------------------- /examples/with-next-routes/server.js: -------------------------------------------------------------------------------- 1 | const { createServer } = require('http') 2 | const next = require('next') 3 | const routes = require('./routes') 4 | 5 | const dev = process.env.NODE_ENV !== 'production' 6 | const app = next({ dev }) 7 | const handler = routes.getRequestHandler(app) 8 | 9 | app.prepare() 10 | .then(() => { 11 | createServer(handler) 12 | .listen(3000, (err) => { 13 | if (err) throw err 14 | console.log('> Ready on http://localhost:3000') 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /examples/with-styled-jsx-postcss/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-styled-jsx-postcss", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "latest", 11 | "postcss-cssnext": "^2.9.0", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2", 14 | "styled-jsx-postcss": "^0.1.5" 15 | }, 16 | "author": "Giuseppe Gurgone", 17 | "license": "MIT" 18 | } 19 | -------------------------------------------------------------------------------- /examples/ssr-caching/pages/blog.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default class extends React.Component { 4 | static getInitialProps ({ query: { id } }) { 5 | return { id } 6 | } 7 | 8 | render () { 9 | return
10 |

My {this.props.id} blog post

11 |

12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 13 | tempor incididunt ut labore et dolore magna aliqua. 14 |

15 |
16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/integration/basic/pages/stateful.js: -------------------------------------------------------------------------------- 1 | 2 | import React, { Component } from 'react' 3 | 4 | export default class Statefull extends Component { 5 | constructor (props) { 6 | super(props) 7 | 8 | this.state = { answer: null } 9 | } 10 | 11 | componentWillMount () { 12 | this.setState({ answer: 42 }) 13 | } 14 | 15 | render () { 16 | return ( 17 |
18 |

The answer is {this.state.answer}

19 |
20 | ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-dynamic-import", 3 | "version": "1.0.0", 4 | "description": "This example features:", 5 | "main": "index.js", 6 | "scripts": { 7 | "dev": "next", 8 | "build": "next build", 9 | "start": "next start" 10 | }, 11 | "dependencies": { 12 | "async-reactor": "^1.1.1", 13 | "next": "^3.0.0-beta3", 14 | "react": "^15.4.2", 15 | "react-dom": "^15.4.2" 16 | }, 17 | "author": "", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /examples/with-jest/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-jest", 3 | "dependencies": { 4 | "next": "latest", 5 | "react": "^15.5.4", 6 | "react-dom": "^15.5.4" 7 | }, 8 | "devDependencies": { 9 | "enzyme": "^2.8.2", 10 | "jest": "^20.0.0", 11 | "react-addons-test-utils": "^15.5.1", 12 | "react-test-renderer": "^15.5.4" 13 | }, 14 | "scripts": { 15 | "test": "jest", 16 | "dev": "next", 17 | "build": "next build", 18 | "start": "next start" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/parameterized-routing/pages/blog.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default class extends React.Component { 4 | static getInitialProps ({ query: { id } }) { 5 | return { id } 6 | } 7 | 8 | render () { 9 | return
10 |

My {this.props.id} blog post

11 |

12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 13 | tempor incididunt ut labore et dolore magna aliqua. 14 |

15 |
16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/with-apollo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-apollo", 3 | "version": "2.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "graphql": "^0.9.3", 11 | "isomorphic-fetch": "^2.2.1", 12 | "next": "latest", 13 | "prop-types": "^15.5.8", 14 | "react": "^15.5.4", 15 | "react-dom": "^15.5.4", 16 | "react-apollo": "^1.1.3" 17 | }, 18 | "author": "", 19 | "license": "ISC" 20 | } 21 | -------------------------------------------------------------------------------- /examples/with-redux/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-redux", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "latest", 11 | "next-redux-wrapper": "^1.0.0", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2", 14 | "react-redux": "^5.0.1", 15 | "redux": "^3.6.0", 16 | "redux-thunk": "^2.1.0" 17 | }, 18 | "author": "", 19 | "license": "ISC" 20 | } 21 | -------------------------------------------------------------------------------- /examples/custom-server-hapi/next-wrapper.js: -------------------------------------------------------------------------------- 1 | const pathWrapper = (app, pathName, opts) => ({ raw, query }, hapiReply) => 2 | app.renderToHTML(raw.req, raw.res, pathName, query, opts) 3 | .then(hapiReply) 4 | 5 | const defaultHandlerWrapper = app => { 6 | const handler = app.getRequestHandler() 7 | return ({ raw, url }, hapiReply) => 8 | handler(raw.req, raw.res, url) 9 | .then(() => { 10 | hapiReply.close(false) 11 | }) 12 | } 13 | module.exports = { pathWrapper, defaultHandlerWrapper } 14 | -------------------------------------------------------------------------------- /examples/with-react-md/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-react-md", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "next": "latest", 11 | "react": "^15.4.2", 12 | "react-addons-css-transition-group": "^15.4.2", 13 | "react-addons-transition-group": "^15.4.2", 14 | "react-dom": "^15.4.2", 15 | "react-md": "^1.0.1" 16 | }, 17 | "author": "", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /examples/with-webpack-bundle-analyzer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-webpack-bundle-analyzer", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start", 8 | "bundle:view": "webpack-bundle-analyzer .next/stats.json" 9 | }, 10 | "dependencies": { 11 | "next": "latest", 12 | "react": "^15.4.2", 13 | "react-dom": "^15.4.2", 14 | "webpack-bundle-analyzer": "^2.3.0" 15 | }, 16 | "author": "", 17 | "license": "ISC" 18 | } 19 | -------------------------------------------------------------------------------- /examples/with-loading/pages/about.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import Header from '../components/Header' 3 | 4 | export default class About extends Component { 5 | // Add some delay 6 | static async getInitialProps () { 7 | await new Promise((resolve) => { 8 | setTimeout(resolve, 500) 9 | }) 10 | return {} 11 | } 12 | 13 | render () { 14 | return ( 15 |
16 |
17 |

This is about Next!

18 |
19 | ) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/with-glamor/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { style, rehydrate } from 'glamor' 3 | 4 | // Adds server generated styles to glamor cache. 5 | // Has to run before any `style()` calls 6 | // '__NEXT_DATA__.ids' is set in '_document.js' 7 | if (typeof window !== 'undefined') { 8 | rehydrate(window.__NEXT_DATA__.ids) 9 | } 10 | 11 | export default () =>

My page

12 | 13 | const styles = { 14 | title: style({ 15 | color: 'red', 16 | fontSize: 50 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /examples/with-redux/components/Page.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | import { connect } from 'react-redux' 3 | import Clock from './Clock' 4 | import AddCount from './AddCount' 5 | 6 | export default connect(state => state)(({ title, linkTo, lastUpdate, light }) => { 7 | return ( 8 |
9 |

{title}

10 | 11 | 12 | 15 |
16 | ) 17 | }) 18 | -------------------------------------------------------------------------------- /examples/with-styled-components/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-styled-components", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "babel-plugin-styled-components": "^1.1.4", 11 | "babel-preset-stage-0": "^6.24.1", 12 | "next": "latest", 13 | "react": "^15.4.2", 14 | "react-dom": "^15.4.2", 15 | "styled-components": "^2.0.0-17" 16 | }, 17 | "author": "", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /test/integration/basic/pages/nav/as-path-using-router.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Router from 'next/router' 3 | 4 | export default class extends React.Component { 5 | constructor (...args) { 6 | super(...args) 7 | this.state = {} 8 | } 9 | 10 | componentDidMount () { 11 | const asPath = Router.asPath 12 | this.setState({ asPath }) 13 | } 14 | 15 | render () { 16 | return ( 17 |
18 | {this.state.asPath} 19 |
20 | ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/with-loading/pages/forever.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import Header from '../components/Header' 3 | 4 | export default class Forever extends Component { 5 | // Add some delay 6 | static async getInitialProps () { 7 | await new Promise((resolve) => { 8 | setTimeout(resolve, 3000) 9 | }) 10 | return {} 11 | } 12 | 13 | render () { 14 | return ( 15 |
16 |
17 |

This page was rendered for a while!

18 |
19 | ) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/with-external-scoped-css/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-external-scoped-css", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "ISC", 6 | "author": "", 7 | "scripts": { 8 | "start": "next", 9 | "build": "next build", 10 | "run": "next start" 11 | }, 12 | "dependencies":{ 13 | "next": "latest", 14 | "react": "^15.4.2", 15 | "react-dom": "^15.4.2" 16 | }, 17 | "devDependencies": { 18 | "babel-plugin-css-modules-transform": "^1.2.1", 19 | "node-sass": "^4.5.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/with-custom-babel-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-custom-babel-config", 3 | "version": "1.0.0", 4 | "description": "This example features:", 5 | "main": "index.js", 6 | "scripts": { 7 | "dev": "next", 8 | "build": "next build", 9 | "start": "next start" 10 | }, 11 | "dependencies": { 12 | "next": "latest", 13 | "react": "^15.4.2", 14 | "react-dom": "^15.4.2" 15 | }, 16 | "author": "", 17 | "license": "ISC", 18 | "devDependencies": { 19 | "babel-preset-stage-0": "^6.16.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/with-apollo-and-redux/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-apollo-and-redux", 3 | "version": "2.0.0", 4 | "scripts": { 5 | "dev": "next", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "graphql": "^0.9.3", 11 | "isomorphic-fetch": "^2.2.1", 12 | "next": "latest", 13 | "prop-types": "^15.5.8", 14 | "react": "^15.5.4", 15 | "react-apollo": "^1.1.3", 16 | "react-dom": "^15.5.4", 17 | "redux": "^3.6.0" 18 | }, 19 | "author": "", 20 | "license": "ISC" 21 | } 22 | -------------------------------------------------------------------------------- /examples/with-firebase/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "node server.js", 4 | "build": "next build", 5 | "start": "NODE_ENV=production node server.js" 6 | }, 7 | "dependencies": { 8 | "body-parser": "^1.17.1", 9 | "express": "^4.14.0", 10 | "express-session": "^1.15.2", 11 | "firebase": "^3.7.5", 12 | "firebase-admin": "^4.2.0", 13 | "isomorphic-fetch": "2.2.1", 14 | "next": "latest", 15 | "react": "^15.4.2", 16 | "react-dom": "^15.4.2", 17 | "session-file-store": "^1.0.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/integration/static/next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | exportPathMap: function () { 3 | return { 4 | '/': { page: '/' }, 5 | '/about': { page: '/about' }, 6 | '/counter': { page: '/counter' }, 7 | '/dynamic-imports': { page: '/dynamic-imports' }, 8 | '/dynamic': { page: '/dynamic', query: { text: 'cool dynamic text' } }, 9 | '/dynamic/one': { page: '/dynamic', query: { text: 'next export is nice' } }, 10 | '/dynamic/two': { page: '/dynamic', query: { text: 'zeit is awesome' } } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/with-mobx/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-mobx", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "node server.js", 6 | "build": "next build", 7 | "start": "NODE_ENV=production node server.js" 8 | }, 9 | "dependencies": { 10 | "mobx": "^2.7.0", 11 | "mobx-react": "^4.0.4", 12 | "next": "latest", 13 | "react": "^15.4.2", 14 | "react-dom": "^15.4.2" 15 | }, 16 | "author": "", 17 | "license": "ISC", 18 | "devDependencies": { 19 | "babel-plugin-transform-decorators-legacy": "^1.3.4" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/with-flow/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-flow", 3 | "version": "1.0.0", 4 | "license": "MIT", 5 | "author": "Jag Reehal", 6 | "scripts": { 7 | "dev": "next", 8 | "build": "next build", 9 | "flow": "flow", 10 | "start": "next start" 11 | }, 12 | "dependencies": { 13 | "next": "latest", 14 | "react": "^15.4.2", 15 | "react-dom": "^15.4.2" 16 | }, 17 | "devDependencies": { 18 | "babel-eslint": "^7.1.1", 19 | "babel-plugin-transform-flow-strip-types": "^6.21.0", 20 | "flow-bin": "^0.37.4" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/with-react-intl/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-react-intl", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "node server.js", 6 | "build": "next build && node ./scripts/default-lang", 7 | "start": "NODE_ENV=production node server.js" 8 | }, 9 | "dependencies": { 10 | "accepts": "^1.3.3", 11 | "babel-plugin-react-intl": "^2.3.1", 12 | "glob": "^7.1.1", 13 | "intl": "^1.2.5", 14 | "next": "latest", 15 | "react": "^15.4.2", 16 | "react-dom": "^15.4.2", 17 | "react-intl": "^2.2.3" 18 | }, 19 | "author": "", 20 | "license": "ISC" 21 | } 22 | -------------------------------------------------------------------------------- /test/integration/basic/pages/nav/self-reload.js: -------------------------------------------------------------------------------- 1 | import { Component } from 'react' 2 | import Link from 'next/link' 3 | 4 | let count = 0 5 | 6 | export default class SelfReload extends Component { 7 | static getInitialProps ({ res }) { 8 | if (res) return { count: 0 } 9 | count += 1 10 | 11 | return { count } 12 | } 13 | 14 | render () { 15 | return ( 16 |
17 | 18 | Self Reload 19 | 20 |

COUNT: {this.props.count}

21 |
22 | ) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - nodejs_version: "4" 4 | - nodejs_version: "6" 5 | 6 | # Install scripts. (runs after repo cloning) 7 | install: 8 | # Install Google Chrome for e2e testing 9 | - choco install googlechrome 10 | # Get the latest stable version of Node.js or io.js 11 | - ps: Install-Product node $env:nodejs_version 12 | # install modules 13 | - npm install 14 | 15 | # Post-install test scripts. 16 | test_script: 17 | # Output useful info for debugging. 18 | - node --version 19 | - npm --version 20 | # run tests 21 | - npm test 22 | 23 | # Don't actually build. 24 | build: off -------------------------------------------------------------------------------- /examples/with-mobx/server.js: -------------------------------------------------------------------------------- 1 | const dev = process.env.NODE_ENV !== 'production' 2 | 3 | const { createServer } = require('http') 4 | const { parse } = require('url') 5 | const next = require('next') 6 | const mobxReact = require('mobx-react') 7 | const app = next({ dev }) 8 | const handle = app.getRequestHandler() 9 | 10 | mobxReact.useStaticRendering(true) 11 | 12 | app.prepare().then(() => { 13 | createServer((req, res) => { 14 | const parsedUrl = parse(req.url, true) 15 | handle(req, res, parsedUrl) 16 | }).listen(3000, err => { 17 | if (err) throw err 18 | console.log('> Ready on http://localhost:3000') 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /examples/with-styled-jsx-postcss/pages/index.js: -------------------------------------------------------------------------------- 1 | export default () => ( 2 |
3 |

Hello World

4 | 21 |
22 | ) 23 | -------------------------------------------------------------------------------- /bench/readme.md: -------------------------------------------------------------------------------- 1 | # Next.js server-side benchmarks 2 | 3 | ## Installation 4 | 5 | Follow the steps in [contributing.md](../contributing.md) 6 | 7 | Both benchmarks use `ab`. So make sure you have that installed. 8 | 9 | ## Usage 10 | 11 | Before running the test: 12 | 13 | ``` 14 | npm run start 15 | ``` 16 | 17 | Then run one of these tests: 18 | 19 | - Stateless application which renders `

My component!

`. Runs 3000 http requests. 20 | ``` 21 | npm run bench:stateless 22 | ``` 23 | 24 | - Stateless application which renders `
  • This is row {i}
  • ` 10.000 times. Runs 500 http requests. 25 | ``` 26 | npm run bench:stateless-big 27 | ``` 28 | -------------------------------------------------------------------------------- /examples/with-pretty-url-routing/routes.js: -------------------------------------------------------------------------------- 1 | const UrlPrettifier = require('next-url-prettifier').default 2 | 3 | const routes = [ 4 | { 5 | page: 'index', 6 | prettyUrl: '/home' 7 | }, 8 | { 9 | page: 'greeting', 10 | prettyUrl: ({lang = '', name = ''}) => 11 | (lang === 'fr' ? `/bonjour/${name}` : `/hello/${name}`), 12 | prettyUrlPatterns: [ 13 | {pattern: '/hello/:name', defaultParams: {lang: 'en'}}, 14 | {pattern: '/bonjour/:name', defaultParams: {lang: 'fr'}} 15 | ] 16 | } 17 | ] 18 | 19 | const urlPrettifier = new UrlPrettifier(routes) 20 | exports.default = routes 21 | exports.Router = urlPrettifier 22 | -------------------------------------------------------------------------------- /examples/with-webpack-bundle-analyzer/next.config.js: -------------------------------------------------------------------------------- 1 | const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer') 2 | module.exports = { 3 | webpack: (config, { dev }) => { 4 | // Perform customizations to config 5 | config.plugins.push( 6 | new BundleAnalyzerPlugin({ 7 | analyzerMode: 'disabled', 8 | // For all options see https://github.com/th0r/webpack-bundle-analyzer#as-plugin 9 | generateStatsFile: true, 10 | // Will be available at `.next/stats.json` 11 | statsFilename: 'stats.json' 12 | }) 13 | ) 14 | // Important: return the modified config 15 | return config 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /wallaby.js: -------------------------------------------------------------------------------- 1 | module.exports = function (wallaby) { 2 | return { 3 | files: [ 4 | 'server/**/*.js', 5 | 'client/**/*.js', 6 | 'lib/**/*.js', 7 | 'dist/**/*.js', 8 | 'test/**/*.*', 9 | '!test/**/*.test.js' 10 | ], 11 | 12 | tests: [ 13 | 'test/**/*.test.js', 14 | '!test/integration/**/*.test.js' 15 | ], 16 | 17 | compilers: { 18 | '**/*.js': wallaby.compilers.babel() 19 | }, 20 | 21 | env: { 22 | type: 'node', 23 | runner: 'node', 24 | params: { 25 | env: 'NODE_PATH=test/lib' 26 | } 27 | }, 28 | 29 | testFramework: 'jest' 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/with-next-routes/pages/index.js: -------------------------------------------------------------------------------- 1 | import { Link, Router } from '../routes' 2 | 3 | export default () => ( 4 | 11 | ) 12 | -------------------------------------------------------------------------------- /examples/with-styletron/styletron.js: -------------------------------------------------------------------------------- 1 | 2 | const isServer = typeof window === 'undefined' 3 | 4 | let styletron 5 | 6 | export default function getStyletron () { 7 | if (isServer) { 8 | const Styletron = require('styletron-server') 9 | styletron = new Styletron() 10 | } else if (!styletron) { 11 | const Styletron = require('styletron-client') 12 | const styleElements = document.getElementsByClassName('_styletron_hydrate_') 13 | styletron = new Styletron(styleElements) 14 | } 15 | 16 | return styletron 17 | } 18 | 19 | export function flush () { 20 | const _styletron = styletron 21 | styletron = null 22 | return _styletron 23 | } 24 | -------------------------------------------------------------------------------- /examples/data-fetch/pages/index.js: -------------------------------------------------------------------------------- 1 | 2 | import React from 'react' 3 | import Link from 'next/link' 4 | import 'isomorphic-fetch' 5 | 6 | export default class MyPage extends React.Component { 7 | static async getInitialProps () { 8 | // eslint-disable-next-line no-undef 9 | const res = await fetch('https://api.github.com/repos/zeit/next.js') 10 | const json = await res.json() 11 | return { stars: json.stargazers_count } 12 | } 13 | 14 | render () { 15 | return ( 16 |
    17 |

    Next.js has {this.props.stars} ⭐️

    18 | How about preact? 19 |
    20 | ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/with-external-scoped-css/pages/_document.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Document, { Head, Main, NextScript } from 'next/document' 3 | 4 | export default class MyDocument extends Document { 5 | static getInitialProps ({ renderPage }) { 6 | const {html, head} = renderPage() 7 | return { html, head } 8 | } 9 | 10 | render () { 11 | return ( 12 | 13 | 14 | 15 | 16 | 17 | {this.props.customValue} 18 |
    19 | 20 | 21 | 22 | ) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/with-jest/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-jest) 2 | # Example app with jest tests 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-jest 10 | cd with-jest 11 | ``` 12 | 13 | Install it and test: 14 | 15 | ```bash 16 | npm install 17 | npm test 18 | ``` 19 | 20 | ## The idea behind the example 21 | 22 | This example features: 23 | 24 | * An app with jest tests 25 | -------------------------------------------------------------------------------- /examples/with-jest/__tests__/index.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-env jest */ 2 | 3 | import { shallow } from 'enzyme' 4 | import React from 'react' 5 | import renderer from 'react-test-renderer' 6 | 7 | import App from '../pages/index.js' 8 | 9 | describe('With Enzyme', () => { 10 | it('App shows "Hello world!"', () => { 11 | const app = shallow() 12 | 13 | expect(app.find('p').text()).toEqual('Hello World!') 14 | }) 15 | }) 16 | 17 | describe('With Snapshot Testing', () => { 18 | it('App shows "Hello world!"', () => { 19 | const component = renderer.create() 20 | const tree = component.toJSON() 21 | expect(tree).toMatchSnapshot() 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /examples/with-next-routes/pages/blog.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | const posts = [ 4 | { slug: 'hello-world', title: 'Hello world' }, 5 | { slug: 'another-blog-post', title: 'Another blog post' } 6 | ] 7 | 8 | export default class extends React.Component { 9 | static async getInitialProps ({ query, res }) { 10 | const post = posts.find(post => post.slug === query.slug) 11 | 12 | if (!post && res) { 13 | res.statusCode = 404 14 | } 15 | 16 | return { post } 17 | } 18 | 19 | render () { 20 | const { post } = this.props 21 | 22 | if (!post) return

    Post not found

    23 | 24 | return

    {post.title}

    25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/data-fetch/pages/preact.js: -------------------------------------------------------------------------------- 1 | 2 | import React from 'react' 3 | import Link from 'next/link' 4 | import 'isomorphic-fetch' 5 | 6 | export default class MyPage extends React.Component { 7 | static async getInitialProps () { 8 | // eslint-disable-next-line no-undef 9 | const res = await fetch('https://api.github.com/repos/developit/preact') 10 | const json = await res.json() 11 | return { stars: json.stargazers_count } 12 | } 13 | 14 | render () { 15 | return ( 16 |
    17 |

    Preact has {this.props.stars} ⭐️

    18 | I bet next has more stars (?) 19 |
    20 | ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/with-react-intl/pages/about.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react' 2 | import {FormattedRelative} from 'react-intl' 3 | import pageWithIntl from '../components/PageWithIntl' 4 | import Layout from '../components/Layout' 5 | 6 | class About extends Component { 7 | static async getInitialProps ({req}) { 8 | return {someDate: Date.now()} 9 | } 10 | 11 | render () { 12 | return ( 13 | 14 |

    15 | 19 |

    20 |
    21 | ) 22 | } 23 | } 24 | 25 | export default pageWithIntl(About) 26 | -------------------------------------------------------------------------------- /server/build/replace.js: -------------------------------------------------------------------------------- 1 | import mv from 'mv' 2 | import { join } from 'path' 3 | import getConfig from '../config' 4 | 5 | export default async function replaceCurrentBuild (dir, buildDir) { 6 | const dist = getConfig(dir).distDir 7 | const _dir = join(dir, dist) 8 | const _buildDir = join(buildDir, '.next') 9 | const oldDir = join(buildDir, '.next.old') 10 | 11 | try { 12 | await move(_dir, oldDir) 13 | } catch (err) { 14 | if (err.code !== 'ENOENT') throw err 15 | } 16 | await move(_buildDir, _dir) 17 | return oldDir 18 | } 19 | 20 | function move (from, to) { 21 | return new Promise((resolve, reject) => 22 | mv(from, to, err => err ? reject(err) : resolve())) 23 | } 24 | -------------------------------------------------------------------------------- /examples/with-mobx/components/Clock.js: -------------------------------------------------------------------------------- 1 | export default (props) => { 2 | return ( 3 |
    4 | {format(new Date(props.lastUpdate))} 5 | 18 |
    19 | ) 20 | } 21 | 22 | const format = t => `${pad(t.getUTCHours())}:${pad(t.getUTCMinutes())}:${pad(t.getUTCSeconds())}` 23 | 24 | const pad = n => n < 10 ? `0${n}` : n 25 | -------------------------------------------------------------------------------- /examples/with-url-object-routing/pages/about.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | import Router from 'next/router' 4 | 5 | const href = { 6 | pathname: '/about', 7 | query: { name: 'zeit' } 8 | } 9 | 10 | const as = { 11 | pathname: '/about/zeit', 12 | hash: 'title-1' 13 | } 14 | 15 | const handleClick = () => Router.push(href, as) 16 | 17 | export default (props) => ( 18 |
    19 |

    About {props.url.query.name}

    20 | {props.url.query.name === 'zeit' ? ( 21 | 22 | Go to home page 23 | 24 | ) : ( 25 | 26 | )} 27 |
    28 | ) 29 | -------------------------------------------------------------------------------- /examples/with-apollo/components/Header.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default ({ pathname }) => ( 4 |
    5 | 6 | Home 7 | 8 | 9 | 10 | About 11 | 12 | 13 | 26 |
    27 | ) 28 | -------------------------------------------------------------------------------- /examples/with-react-intl/components/Layout.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {defineMessages, injectIntl} from 'react-intl' 3 | import Head from 'next/head' 4 | import Nav from './Nav' 5 | 6 | const messages = defineMessages({ 7 | title: { 8 | id: 'title', 9 | defaultMessage: 'React Intl Next.js Example' 10 | } 11 | }) 12 | 13 | export default injectIntl(({intl, title, children}) => ( 14 |
    15 | 16 | 17 | {title || intl.formatMessage(messages.title)} 18 | 19 | 20 |
    21 |
    23 | 24 | {children} 25 | 26 |
    27 | )) 28 | -------------------------------------------------------------------------------- /examples/with-react-intl/components/Nav.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {FormattedMessage} from 'react-intl' 3 | import Link from 'next/link' 4 | 5 | export default () => ( 6 | 28 | ) 29 | -------------------------------------------------------------------------------- /examples/with-redux/components/Clock.js: -------------------------------------------------------------------------------- 1 | export default ({ lastUpdate, light }) => { 2 | return ( 3 |
    4 | {format(new Date(lastUpdate))} 5 | 18 |
    19 | ) 20 | } 21 | 22 | const format = t => `${pad(t.getUTCHours())}:${pad(t.getUTCMinutes())}:${pad(t.getUTCSeconds())}` 23 | 24 | const pad = n => n < 10 ? `0${n}` : n 25 | -------------------------------------------------------------------------------- /examples/with-pretty-url-routing/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const next = require('next') 3 | const Router = require('./routes').Router 4 | 5 | const dev = process.env.NODE_ENV !== 'production' 6 | const port = parseInt(process.env.PORT, 10) || 3000 7 | const app = next({dev}) 8 | const handle = app.getRequestHandler() 9 | 10 | app.prepare() 11 | .then(() => { 12 | const server = express() 13 | 14 | Router.forEachPattern((page, pattern, defaultParams) => server.get(pattern, (req, res) => 15 | app.render(req, res, `/${page}`, Object.assign({}, defaultParams, req.query, req.params)) 16 | )) 17 | 18 | server.get('*', (req, res) => handle(req, res)) 19 | server.listen(port) 20 | }) 21 | -------------------------------------------------------------------------------- /examples/with-apollo-and-redux/components/Header.js: -------------------------------------------------------------------------------- 1 | import Link from 'next/link' 2 | 3 | export default ({ pathname }) => ( 4 |
    5 | 6 | Home 7 | 8 | 9 | 10 | About 11 | 12 | 13 | 26 |
    27 | ) 28 | -------------------------------------------------------------------------------- /examples/with-cxs/pages/_document.js: -------------------------------------------------------------------------------- 1 | import Document, { Head, Main, NextScript } from 'next/document' 2 | import cxs from 'cxs/lite' 3 | 4 | export default class MyDocument extends Document { 5 | static async getInitialProps ({ renderPage }) { 6 | const page = renderPage() 7 | const style = cxs.getCss() 8 | return { ...page, style } 9 | } 10 | 11 | render () { 12 | return ( 13 | 14 | 15 | My page 16 | 29 |
    30 | ) 31 | -------------------------------------------------------------------------------- /examples/custom-server-express/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const next = require('next') 3 | 4 | const dev = process.env.NODE_ENV !== 'production' 5 | const app = next({ dev }) 6 | const handle = app.getRequestHandler() 7 | 8 | app.prepare() 9 | .then(() => { 10 | const server = express() 11 | 12 | server.get('/a', (req, res) => { 13 | return app.render(req, res, '/b', req.query) 14 | }) 15 | 16 | server.get('/b', (req, res) => { 17 | return app.render(req, res, '/a', req.query) 18 | }) 19 | 20 | server.get('*', (req, res) => { 21 | return handle(req, res) 22 | }) 23 | 24 | server.listen(3000, (err) => { 25 | if (err) throw err 26 | console.log('> Ready on http://localhost:3000') 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /examples/with-dynamic-import/README.md: -------------------------------------------------------------------------------- 1 | # Example app with dynamic-imports 2 | 3 | ## How to use 4 | 5 | Download the example [or clone the repo](https://github.com/zeit/next.js): 6 | 7 | ```bash 8 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-dynamic-import 9 | cd with-dynamic-import 10 | ``` 11 | 12 | Install it and run: 13 | 14 | ```bash 15 | npm install 16 | npm run dev 17 | ``` 18 | 19 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 20 | 21 | ```bash 22 | now 23 | ``` 24 | 25 | ## The idea behind the example 26 | 27 | This examples shows how to dynamically import modules via [`import()`](https://github.com/tc39/proposal-dynamic-import) API 28 | -------------------------------------------------------------------------------- /server/build/babel/find-config.js: -------------------------------------------------------------------------------- 1 | import { join } from 'path' 2 | import buildConfigChain from 'babel-core/lib/transformation/file/options/build-config-chain' 3 | 4 | export default function findBabelConfig (dir) { 5 | // We need to provide a location of a filename inside the `dir`. 6 | // For the name of the file, we could be provide anything. 7 | const filename = join(dir, 'filename.js') 8 | const options = { babelrc: true, filename } 9 | 10 | // First We need to build the config chain. 11 | // Then we need to remove the config item with the location as "base". 12 | // That's the config we are passing as the "options" below 13 | const configList = buildConfigChain(options).filter(i => i.loc !== 'base') 14 | 15 | return configList[0] 16 | } 17 | -------------------------------------------------------------------------------- /test/integration/basic/pages/nav/hash-changes.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import Link from 'next/link' 3 | 4 | let count = 0 5 | 6 | export default class SelfReload extends Component { 7 | static getInitialProps ({ res }) { 8 | if (res) return { count: 0 } 9 | count += 1 10 | 11 | return { count } 12 | } 13 | 14 | render () { 15 | return ( 16 |
    17 | 18 | Via Link 19 | 20 | Via A 21 | 22 | Page URL 23 | 24 |

    COUNT: {this.props.count}

    25 |
    26 | ) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/with-mobx/components/Page.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from 'next/link' 3 | import { inject, observer } from 'mobx-react' 4 | import Clock from './Clock' 5 | 6 | @inject('store') @observer 7 | class Page extends React.Component { 8 | componentDidMount () { 9 | this.props.store.start() 10 | } 11 | 12 | componentWillUnmount () { 13 | this.props.store.stop() 14 | } 15 | 16 | render () { 17 | return ( 18 |
    19 |

    {this.props.title}

    20 | 21 | 24 |
    25 | ) 26 | } 27 | } 28 | 29 | export default Page 30 | -------------------------------------------------------------------------------- /examples/using-router/components/Header.js: -------------------------------------------------------------------------------- 1 | import Router from 'next/router' 2 | 3 | export default () => ( 4 |
    5 | Home 6 | About 7 | Error 8 |
    9 | ) 10 | 11 | // typically you want to use `next/link` for this usecase 12 | // but this example shows how you can also access the router 13 | // and use it manually 14 | 15 | function onClickHandler (href) { 16 | return (e) => { 17 | e.preventDefault() 18 | Router.push(href) 19 | } 20 | } 21 | 22 | const Link = ({ children, href }) => ( 23 | 24 | {children} 25 | 30 | 31 | ) 32 | -------------------------------------------------------------------------------- /server/router.js: -------------------------------------------------------------------------------- 1 | import pathMatch from 'path-match' 2 | 3 | const route = pathMatch() 4 | 5 | export default class Router { 6 | constructor () { 7 | this.routes = new Map() 8 | } 9 | 10 | add (method, path, fn) { 11 | const routes = this.routes.get(method) || new Set() 12 | routes.add({ match: route(path), fn }) 13 | this.routes.set(method, routes) 14 | } 15 | 16 | match (req, res, parsedUrl) { 17 | const routes = this.routes.get(req.method) 18 | if (!routes) return 19 | 20 | const { pathname } = parsedUrl 21 | for (const r of routes) { 22 | const params = r.match(pathname) 23 | if (params) { 24 | return async () => { 25 | return r.fn(req, res, params, parsedUrl) 26 | } 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/with-scoped-stylesheets-and-postcss/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "next.js-with-scoped-stylesheets-and-postcss", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start" 9 | }, 10 | "author": "Thomas Lindstrøm ", 11 | "license": "ISC", 12 | "dependencies": { 13 | "babel-plugin-wrap-in-js": "^1.1.1", 14 | "css-loader": "^0.26.1", 15 | "next": "latest", 16 | "postcss-cssnext": "^2.9.0", 17 | "postcss-loader": "^1.3.0", 18 | "raw-loader": "^0.5.1", 19 | "react": "^15.4.2", 20 | "react-dom": "^15.4.2", 21 | "skeleton-loader": "0.0.7", 22 | "val-loader": "^0.5.0" 23 | }, 24 | "devDependencies": { 25 | "now": "^3.1.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/with-react-intl/scripts/default-lang.js: -------------------------------------------------------------------------------- 1 | const {readFileSync, writeFileSync} = require('fs') 2 | const {resolve} = require('path') 3 | const glob = require('glob') 4 | 5 | const defaultMessages = glob.sync('./lang/.messages/**/*.json') 6 | .map((filename) => readFileSync(filename, 'utf8')) 7 | .map((file) => JSON.parse(file)) 8 | .reduce((messages, descriptors) => { 9 | descriptors.forEach(({id, defaultMessage}) => { 10 | if (messages.hasOwnProperty(id)) { 11 | throw new Error(`Duplicate message id: ${id}`) 12 | } 13 | messages[id] = defaultMessage 14 | }) 15 | return messages 16 | }, {}) 17 | 18 | writeFileSync('./lang/en.json', JSON.stringify(defaultMessages, null, 2)) 19 | console.log(`> Wrote default messages to: "${resolve('./lang/en.json')}"`) 20 | -------------------------------------------------------------------------------- /examples/custom-server/server.js: -------------------------------------------------------------------------------- 1 | const { createServer } = require('http') 2 | const { parse } = require('url') 3 | const next = require('next') 4 | 5 | const dev = process.env.NODE_ENV !== 'production' 6 | const app = next({ dev }) 7 | const handle = app.getRequestHandler() 8 | 9 | app.prepare() 10 | .then(() => { 11 | createServer((req, res) => { 12 | const parsedUrl = parse(req.url, true) 13 | const { pathname, query } = parsedUrl 14 | 15 | if (pathname === '/a') { 16 | app.render(req, res, '/b', query) 17 | } else if (pathname === '/b') { 18 | app.render(req, res, '/a', query) 19 | } else { 20 | handle(req, res, parsedUrl) 21 | } 22 | }) 23 | .listen(3000, (err) => { 24 | if (err) throw err 25 | console.log('> Ready on http://localhost:3000') 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /examples/with-mobx/store.js: -------------------------------------------------------------------------------- 1 | import { action, observable } from 'mobx' 2 | 3 | let store = null 4 | 5 | class Store { 6 | @observable lastUpdate = 0 7 | @observable light = false 8 | 9 | constructor (isServer, lastUpdate) { 10 | this.lastUpdate = lastUpdate 11 | } 12 | 13 | @action start = () => { 14 | this.timer = setInterval(() => { 15 | this.lastUpdate = Date.now() 16 | this.light = true 17 | }) 18 | } 19 | 20 | stop = () => clearInterval(this.timer) 21 | } 22 | 23 | export function initStore (isServer, lastUpdate = Date.now()) { 24 | if (isServer && typeof window === 'undefined') { 25 | return new Store(isServer, lastUpdate) 26 | } else { 27 | if (store === null) { 28 | store = new Store(isServer, lastUpdate) 29 | } 30 | return store 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/with-prefetching/components/Header.js: -------------------------------------------------------------------------------- 1 | import Router from 'next/router' 2 | import Link from 'next/link' 3 | 4 | export default () => ( 5 |
    6 | { /* Prefetch using the declarative API */ } 7 | 8 | Home 9 | 10 | 11 | 12 | Features 13 | 14 | 15 | { /* we imperatively prefetch on hover */ } 16 | 17 | { Router.prefetch('/about'); console.log('prefetching /about!') }}>About 18 | 19 | 20 | 21 | Contact (NO-PREFETCHING) 22 | 23 | 24 | 29 |
    30 | ) 31 | -------------------------------------------------------------------------------- /examples/with-i18next/pages/index.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { I18nextProvider } from 'react-i18next' 3 | import startI18n from '../tools/startI18n' 4 | import { getTranslation } from '../tools/translationHelpers' 5 | import Title from '../components/Title' 6 | 7 | export default class Homepage extends Component { 8 | static async getInitialProps () { 9 | const translations = await getTranslation('pt', 'common', 'http://localhost:3000/static/locales/') 10 | 11 | return { translations } 12 | } 13 | 14 | constructor (props) { 15 | super(props) 16 | 17 | this.i18n = startI18n(props.translations) 18 | } 19 | 20 | render (props) { 21 | return ( 22 | 23 | 24 | </ I18nextProvider> 25 | ) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /server/build/plugins/unlink-file-plugin.js: -------------------------------------------------------------------------------- 1 | import { join } from 'path' 2 | import { unlink } from 'mz/fs' 3 | 4 | export default class UnlinkFilePlugin { 5 | constructor () { 6 | this.prevAssets = {} 7 | } 8 | 9 | apply (compiler) { 10 | compiler.plugin('after-emit', (compilation, callback) => { 11 | const removed = Object.keys(this.prevAssets) 12 | .filter((a) => !compilation.assets[a]) 13 | 14 | this.prevAssets = compilation.assets 15 | 16 | Promise.all(removed.map(async (f) => { 17 | const path = join(compiler.outputPath, f) 18 | try { 19 | await unlink(path) 20 | } catch (err) { 21 | if (err.code === 'ENOENT') return 22 | throw err 23 | } 24 | })) 25 | .then(() => callback(), callback) 26 | }) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/with-url-object-routing/server.js: -------------------------------------------------------------------------------- 1 | const { createServer } = require('http') 2 | const { parse } = require('url') 3 | const next = require('next') 4 | const pathMatch = require('path-match') 5 | 6 | const dev = process.env.NODE_ENV !== 'production' 7 | const app = next({ dev }) 8 | const handle = app.getRequestHandler() 9 | const route = pathMatch() 10 | const match = route('/about/:name') 11 | 12 | app.prepare() 13 | .then(() => { 14 | createServer((req, res) => { 15 | const { pathname } = parse(req.url) 16 | const params = match(pathname) 17 | if (params === false) { 18 | handle(req, res) 19 | return 20 | } 21 | 22 | app.render(req, res, '/about', params) 23 | }) 24 | .listen(3000, (err) => { 25 | if (err) throw err 26 | console.log('> Ready on http://localhost:3000') 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /server/config.js: -------------------------------------------------------------------------------- 1 | import { join } from 'path' 2 | import { existsSync } from 'fs' 3 | 4 | const cache = new Map() 5 | 6 | const defaultConfig = { 7 | webpack: null, 8 | webpackDevMiddleware: null, 9 | poweredByHeader: true, 10 | distDir: '.next', 11 | assetPrefix: '' 12 | } 13 | 14 | export default function getConfig (dir) { 15 | if (!cache.has(dir)) { 16 | cache.set(dir, loadConfig(dir)) 17 | } 18 | return cache.get(dir) 19 | } 20 | 21 | function loadConfig (dir) { 22 | const path = join(dir, 'next.config.js') 23 | 24 | let userConfig = {} 25 | 26 | const userHasConfig = existsSync(path) 27 | if (userHasConfig) { 28 | const userConfigModule = require(path) 29 | userConfig = userConfigModule.default || userConfigModule 30 | } 31 | 32 | return Object.assign({}, defaultConfig, userConfig) 33 | } 34 | -------------------------------------------------------------------------------- /examples/with-react-intl/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {FormattedMessage, FormattedNumber, defineMessages} from 'react-intl' 3 | import Head from 'next/head' 4 | import pageWithIntl from '../components/PageWithIntl' 5 | import Layout from '../components/Layout' 6 | 7 | const {description} = defineMessages({ 8 | description: { 9 | id: 'description', 10 | defaultMessage: 'An example app integrating React Intl with Next.js' 11 | } 12 | }) 13 | 14 | export default pageWithIntl(({intl}) => ( 15 | <Layout> 16 | <Head> 17 | <meta name='description' content={intl.formatMessage(description)} /> 18 | </Head> 19 | <p> 20 | <FormattedMessage id='greeting' defaultMessage='Hello, World!' /> 21 | </p> 22 | <p> 23 | <FormattedNumber value={1000} /> 24 | </p> 25 | </Layout> 26 | )) 27 | -------------------------------------------------------------------------------- /examples/with-flow/components/layout.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 3 | import type {Element} from 'React' 4 | import Link from 'next/link' 5 | import Head from 'next/head' 6 | 7 | type Props = { 8 | children?: Element<any>, 9 | title?: string 10 | } 11 | 12 | export default ({children, title = 'This is the default title'}: Props) => ( 13 | <div> 14 | <Head> 15 | <title>{title} 16 | 17 | 18 | 19 |
    20 | 25 |
    26 | {children} 27 |
    28 | I`m here to stay 29 |
    30 | 31 | ) 32 | -------------------------------------------------------------------------------- /examples/with-cxs/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import cxs from 'cxs/lite' 3 | 4 | // Using cxs/lite on both the server and client, 5 | // the styles will need to be rehydrated. 6 | if (typeof window !== 'undefined') { 7 | const styleTag = document.getElementById('cxs-style') 8 | const serverCss = styleTag.innerHTML 9 | cxs.rehydrate(serverCss) 10 | } 11 | 12 | export default () => ( 13 |
    14 |

    My page

    15 |
    16 | ) 17 | 18 | const cx = { 19 | root: cxs({ 20 | width: 80, 21 | height: 60, 22 | background: 'white', 23 | ':hover': { 24 | background: 'black' 25 | } 26 | }), 27 | 28 | title: cxs({ 29 | marginLeft: 5, 30 | color: 'black', 31 | fontSize: 22, 32 | ':hover': { 33 | color: 'white' 34 | } 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /server/build/loaders/emit-file-loader.js: -------------------------------------------------------------------------------- 1 | import loaderUtils from 'loader-utils' 2 | 3 | module.exports = function (content, sourceMap) { 4 | this.cacheable() 5 | 6 | const query = loaderUtils.getOptions(this) 7 | const name = query.name || '[hash].[ext]' 8 | const context = query.context || this.options.context 9 | const regExp = query.regExp 10 | const opts = { context, content, regExp } 11 | const interpolatedName = loaderUtils.interpolateName(this, name, opts) 12 | 13 | const emit = (code, map) => { 14 | this.emitFile(interpolatedName, code, map) 15 | this.callback(null, code, map) 16 | } 17 | 18 | if (query.transform) { 19 | const transformed = query.transform({ content, sourceMap, interpolatedName }) 20 | return emit(transformed.content, transformed.sourceMap) 21 | } 22 | 23 | return emit(content, sourceMap) 24 | } 25 | -------------------------------------------------------------------------------- /server/build/plugins/watch-pages-plugin.js: -------------------------------------------------------------------------------- 1 | import { resolve, join } from 'path' 2 | 3 | export default class WatchPagesPlugin { 4 | constructor (dir) { 5 | this.dir = resolve(dir, 'pages') 6 | } 7 | 8 | apply (compiler) { 9 | compiler.plugin('compilation', (compilation) => { 10 | compilation.plugin('optimize-assets', (assets, callback) => { 11 | // transpile pages/_document.js and descendants, 12 | // but don't need the bundle file 13 | delete assets[join('bundles', 'pages', '_document.js')] 14 | callback() 15 | }) 16 | }) 17 | 18 | compiler.plugin('emit', (compilation, callback) => { 19 | // watch the pages directory 20 | compilation.contextDependencies = [ 21 | ...compilation.contextDependencies, 22 | this.dir 23 | ] 24 | callback() 25 | }) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/integration/basic/test/misc.js: -------------------------------------------------------------------------------- 1 | /* global describe, test, expect */ 2 | import fetch from 'node-fetch' 3 | 4 | export default function (context) { 5 | describe('Misc', () => { 6 | test('finishes response', async () => { 7 | const res = { 8 | finished: false, 9 | end () { 10 | this.finished = true 11 | } 12 | } 13 | const html = await context.app.renderToHTML({}, res, '/finish-response', {}) 14 | expect(html).toBeFalsy() 15 | }) 16 | 17 | test('allow etag header support', async () => { 18 | const url = `http://localhost:${context.appPort}/stateless` 19 | const etag = (await fetch(url)).headers.get('ETag') 20 | 21 | const headers = { 'If-None-Match': etag } 22 | const res2 = await fetch(url, { headers }) 23 | expect(res2.status).toBe(304) 24 | }) 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /test/integration/static/test/index.test.js: -------------------------------------------------------------------------------- 1 | /* global jasmine, describe, beforeAll, afterAll */ 2 | 3 | import { join } from 'path' 4 | import { 5 | nextBuild, 6 | nextExport, 7 | startStaticServer, 8 | stopApp 9 | } from 'next-test-utils' 10 | 11 | import ssr from './ssr' 12 | import browser from './browser' 13 | 14 | jasmine.DEFAULT_TIMEOUT_INTERVAL = 40000 15 | const appDir = join(__dirname, '../') 16 | const context = {} 17 | 18 | describe('Static Export', () => { 19 | beforeAll(async () => { 20 | const outdir = join(appDir, 'out') 21 | await nextBuild(appDir) 22 | await nextExport(appDir, { outdir }) 23 | 24 | context.server = await startStaticServer(join(appDir, 'out')) 25 | context.port = context.server.address().port 26 | }) 27 | afterAll(() => stopApp(context.server)) 28 | 29 | ssr(context) 30 | browser(context) 31 | }) 32 | -------------------------------------------------------------------------------- /examples/root-static-files/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/custom-server) 2 | 3 | # Root static files example 4 | 5 | ## How to use 6 | 7 | Download the example [or clone the repo](https://github.com/zeit/next.js): 8 | 9 | ```bash 10 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/custom-server 11 | cd custom-server 12 | ``` 13 | 14 | Install it and run: 15 | 16 | ```bash 17 | npm install 18 | npm run dev 19 | ``` 20 | 21 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 22 | 23 | ```bash 24 | now 25 | ``` 26 | 27 | ## The idea behind the example 28 | 29 | This example demonstrates how to serve files such as /robots.txt and /sitemap.xml from the root. 30 | -------------------------------------------------------------------------------- /examples/using-preact/server.js: -------------------------------------------------------------------------------- 1 | const dev = process.env.NODE_ENV !== 'production' 2 | const moduleAlias = require('module-alias') 3 | 4 | // For the development version, we'll use React. 5 | // Because, it support react hot loading and so on. 6 | if (!dev) { 7 | moduleAlias.addAlias('react', 'preact-compat') 8 | moduleAlias.addAlias('react-dom', 'preact-compat') 9 | } 10 | 11 | const { createServer } = require('http') 12 | const { parse } = require('url') 13 | const next = require('next') 14 | 15 | const app = next({ dev }) 16 | const handle = app.getRequestHandler() 17 | 18 | app.prepare() 19 | .then(() => { 20 | createServer((req, res) => { 21 | const parsedUrl = parse(req.url, true) 22 | handle(req, res, parsedUrl) 23 | }) 24 | .listen(3000, (err) => { 25 | if (err) throw err 26 | console.log('> Ready on http://localhost:3000') 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /examples/with-global-stylesheet/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "next.js-css-global-style-test", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start" 9 | }, 10 | "author": "Davide Bertola ", 11 | "license": "ISC", 12 | "dependencies": { 13 | "autoprefixer": "6.7.6", 14 | "babel-plugin-module-resolver": "2.5.0", 15 | "babel-plugin-wrap-in-js": "^1.1.0", 16 | "glob": "7.1.1", 17 | "next": "latest", 18 | "node-sass": "^4.4.0", 19 | "normalize.css": "5.0.0", 20 | "postcss-easy-import": "2.0.0", 21 | "postcss-loader": "1.3.3", 22 | "raw-loader": "^0.5.1", 23 | "react": "^15.4.2", 24 | "react-dom": "^15.4.2", 25 | "sass-loader": "^4.1.1" 26 | }, 27 | "devDependencies": { 28 | "now": "^3.1.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/with-fela/pages/_document.js: -------------------------------------------------------------------------------- 1 | import Document, { Head, Main, NextScript } from 'next/document' 2 | import { getRenderer } from '../fela' 3 | 4 | export default class MyDocument extends Document { 5 | static getInitialProps ({ renderPage }) { 6 | const page = renderPage() 7 | const renderer = getRenderer() 8 | const css = renderer.renderToString() 9 | 10 | renderer.clear() 11 | 12 | return { 13 | ...page, 14 | css 15 | } 16 | } 17 | 18 | render () { 19 | return ( 20 | 21 | 22 | My page 23 | 20 |

    AddCount: {count}

    21 | 22 | 23 | ) 24 | } 25 | } 26 | 27 | const mapStateToProps = ({ count }) => ({ count }) 28 | 29 | const mapDispatchToProps = (dispatch) => { 30 | return { 31 | addCount: bindActionCreators(addCount, dispatch) 32 | } 33 | } 34 | 35 | export default connect(mapStateToProps, mapDispatchToProps)(AddCount) 36 | -------------------------------------------------------------------------------- /examples/using-router/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/using-router) 2 | # Example app utilizing next/router for routing 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/using-router 10 | cd using-router 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: 29 | 30 | * An app linking pages using `next/router` instead of `` component. 31 | * Access the pathname using `next/router` and render it in a component 32 | -------------------------------------------------------------------------------- /examples/with-typescript/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-typescript) 2 | # TypeScript Next.js example 3 | This is a really simple project that show the usage of Next.js with TypeScript. 4 | 5 | ## How to use it? 6 | ``` 7 | npm install # to install dependencies 8 | npm run dev # to compile TypeScript files and to run next.js 9 | ``` 10 | 11 | Output JS files are aside the related TypeScript ones. 12 | 13 | ## To fix 14 | In tsconfig.json the options `jsx="react"` compiles JSX syntax into nested React.createElement calls. 15 | This solution doesn't work well with some Next.js features like `next/head` or `next/link`. 16 | The workaround is to create JS files that just return the mentioned module and require them from TSX files. 17 | Like 18 | 19 | ```js 20 | import Link from 'next/link' 21 | 22 | export default Link 23 | ``` 24 | -------------------------------------------------------------------------------- /examples/with-redux/pages/other.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { bindActionCreators } from 'redux' 3 | import { initStore, startClock, addCount, serverRenderClock } from '../store' 4 | import withRedux from 'next-redux-wrapper' 5 | import Page from '../components/Page' 6 | 7 | class Counter extends React.Component { 8 | static getInitialProps ({ store, isServer }) { 9 | store.dispatch(serverRenderClock(isServer)) 10 | store.dispatch(addCount()) 11 | return { isServer } 12 | } 13 | 14 | componentDidMount () { 15 | this.timer = this.props.startClock() 16 | } 17 | 18 | render () { 19 | return ( 20 | 21 | ) 22 | } 23 | } 24 | 25 | const mapDispatchToProps = (dispatch) => { 26 | return { 27 | addCount: bindActionCreators(addCount, dispatch), 28 | startClock: bindActionCreators(startClock, dispatch) 29 | } 30 | } 31 | 32 | export default withRedux(initStore, null, mapDispatchToProps)(Counter) 33 | -------------------------------------------------------------------------------- /examples/with-shallow-routing/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-shallow-routing) 2 | 3 | # Shallow Routing Example 4 | 5 | ## How to use 6 | 7 | Download the example [or clone the repo](https://github.com/zeit/next.js): 8 | 9 | ```bash 10 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/hello-world 11 | cd hello-world 12 | ``` 13 | 14 | Install it and run: 15 | 16 | ```bash 17 | npm install 18 | npm run dev 19 | ``` 20 | 21 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 22 | 23 | ```bash 24 | now 25 | ``` 26 | 27 | ## The idea behind the example 28 | 29 | With shallow routing, we could change the URL without actually running the `getInitialProps` every time you change the URL. 30 | 31 | We do this passing the `shallow: true` option to `Router.push` or `Router.replace`. -------------------------------------------------------------------------------- /examples/with-refnux/pages/page1.js: -------------------------------------------------------------------------------- 1 | import { connect } from 'refnux' 2 | import Link from 'next/link' 3 | 4 | import withRefnux from '../helpers/withRefnux' 5 | import getInitialState from '../store/getInitialState' 6 | 7 | // actions 8 | import counterIncrement from '../store/counterIncrement' 9 | import setTitle from '../store/setTitle' 10 | 11 | const Page1 = connect( 12 | (state, dispatch) => 13 |
    14 |

    {state.title}

    15 |

    Current state: {JSON.stringify(state, null, 2)}

    16 | 17 | 18 |
    19 | ) 20 | 21 | Page1.getInitialProps = async function (context) { 22 | const {store} = context 23 | // dispatch actions to store to set it up for this page / route 24 | store.dispatch(setTitle('Page 1')) 25 | return {} // we have a store, we don't need props! 26 | } 27 | 28 | export default withRefnux(getInitialState, Page1) 29 | -------------------------------------------------------------------------------- /examples/with-styletron/pages/_document.js: -------------------------------------------------------------------------------- 1 | import Document, { Head, Main, NextScript } from 'next/document' 2 | import { flush } from '../styletron' 3 | 4 | export default class MyDocument extends Document { 5 | static getInitialProps ({ renderPage }) { 6 | const page = renderPage() 7 | const styletron = flush() 8 | const stylesheets = styletron ? styletron.getStylesheets() : [] 9 | return { ...page, stylesheets } 10 | } 11 | 12 | render () { 13 | return ( 14 | 15 | 16 | My page 17 | {this.props.stylesheets.map((sheet, i) => ( 18 | 44 | 45 | ) 46 | -------------------------------------------------------------------------------- /examples/custom-server-koa/server.js: -------------------------------------------------------------------------------- 1 | const Koa = require('koa') 2 | const next = require('next') 3 | const Router = require('koa-router') 4 | 5 | const dev = process.env.NODE_ENV !== 'production' 6 | const app = next({ dev }) 7 | const handle = app.getRequestHandler() 8 | 9 | app.prepare() 10 | .then(() => { 11 | const server = new Koa() 12 | const router = new Router() 13 | 14 | router.get('/a', async ctx => { 15 | await app.render(ctx.req, ctx.res, '/b', ctx.query) 16 | ctx.respond = false 17 | }) 18 | 19 | router.get('/b', async ctx => { 20 | await app.render(ctx.req, ctx.res, '/a', ctx.query) 21 | ctx.respond = false 22 | }) 23 | 24 | router.get('*', async ctx => { 25 | await handle(ctx.req, ctx.res) 26 | ctx.respond = false 27 | }) 28 | 29 | server.use(async (ctx, next) => { 30 | ctx.res.statusCode = 200 31 | await next() 32 | }) 33 | 34 | server.use(router.routes()) 35 | server.listen(3000, (err) => { 36 | if (err) throw err 37 | console.log('> Ready on http://localhost:3000') 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /server/build/root-module-relative-path.js: -------------------------------------------------------------------------------- 1 | // Next.js needs to use module.resolve to generate paths to modules it includes, 2 | // but those paths need to be relative to something so that they're portable 3 | // across directories and machines. 4 | // 5 | // This function returns paths relative to the top-level 'node_modules' 6 | // directory found in the path. If none is found, returns the complete path. 7 | 8 | import { sep } from 'path' 9 | 10 | const RELATIVE_START = `node_modules${sep}` 11 | 12 | // Pass in the module's `require` object since it's module-specific. 13 | export default (moduleRequire) => (path) => { 14 | // package.json removed because babel-runtime is resolved as 15 | // "babel-runtime/package" 16 | const absolutePath = moduleRequire.resolve(path) 17 | .replace(/[\\/]package\.json$/, '') 18 | 19 | const relativeStartIndex = absolutePath.indexOf(RELATIVE_START) 20 | 21 | if (relativeStartIndex === -1) { 22 | return absolutePath 23 | } 24 | 25 | return absolutePath.substring(relativeStartIndex + RELATIVE_START.length) 26 | } 27 | -------------------------------------------------------------------------------- /examples/head-elements/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/head-elements) 2 | 3 | # Head elements example 4 | 5 | ## How to use 6 | 7 | Download the example [or clone the repo](https://github.com/zeit/next.js): 8 | 9 | ```bash 10 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/head-elements 11 | cd head-elements 12 | ``` 13 | 14 | Install it and run: 15 | 16 | ```bash 17 | npm install 18 | npm run dev 19 | ``` 20 | 21 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 22 | 23 | ```bash 24 | now 25 | ``` 26 | 27 | ## The idea behind the example 28 | 29 | For every page you can inject elements into the page head. This way you can add stylesheets, JS scripts, meta tags, a custom title or whatever you think is convenient to add inside the `` of your page. 30 | 31 | This example shows in `pages/index.js` how to add a title and a couple of meta tags. 32 | -------------------------------------------------------------------------------- /examples/data-fetch/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/data-fetch) 2 | 3 | # Data fetch example 4 | 5 | ## How to use 6 | 7 | Download the example [or clone the repo](https://github.com/zeit/next.js): 8 | 9 | ```bash 10 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/data-fetch 11 | cd data-fetch 12 | ``` 13 | 14 | Install it and run: 15 | 16 | ```bash 17 | npm install 18 | npm run dev 19 | ``` 20 | 21 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 22 | 23 | ```bash 24 | now 25 | ``` 26 | 27 | ## The idea behind the example 28 | 29 | Next.js was conceived to make it easy to create universal apps. That's why fetching data 30 | on the server and the client when necessary it's so easy with Next. 31 | 32 | Using `getInitialProps` we will fetch data in the server for SSR and then in the client only when the component is re-mounted but not in the first paint. 33 | -------------------------------------------------------------------------------- /examples/nested-components/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/nested-components) 2 | 3 | # Example app using nested components 4 | 5 | ## How to use 6 | 7 | Download the example [or clone the repo](https://github.com/zeit/next.js): 8 | 9 | ```bash 10 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/nested-components 11 | cd nested-components 12 | ``` 13 | 14 | Install it and run: 15 | 16 | ```bash 17 | npm install 18 | npm run dev 19 | ``` 20 | 21 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 22 | 23 | ```bash 24 | now 25 | ``` 26 | 27 | ## The idea behind the example 28 | 29 | Taking advantage of the composable nature of React components we can modularize our apps in self-contained, meaningful components. This example has a page under `pages/index.js` that uses `components/paragraph.js` and `components/post.js` that can be styled and managed separately. 30 | -------------------------------------------------------------------------------- /examples/with-apollo/components/App.js: -------------------------------------------------------------------------------- 1 | export default ({ children }) => ( 2 |
    3 | {children} 4 | 39 |
    40 | ) 41 | -------------------------------------------------------------------------------- /examples/with-redux/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { bindActionCreators } from 'redux' 3 | import { initStore, startClock, addCount, serverRenderClock } from '../store' 4 | import withRedux from 'next-redux-wrapper' 5 | import Page from '../components/Page' 6 | 7 | class Counter extends React.Component { 8 | static getInitialProps ({ store, isServer }) { 9 | store.dispatch(serverRenderClock(isServer)) 10 | store.dispatch(addCount()) 11 | 12 | return { isServer } 13 | } 14 | 15 | componentDidMount () { 16 | this.timer = this.props.startClock() 17 | } 18 | 19 | componentWillUnmount () { 20 | clearInterval(this.timer) 21 | } 22 | 23 | render () { 24 | return ( 25 | 26 | ) 27 | } 28 | } 29 | 30 | const mapDispatchToProps = (dispatch) => { 31 | return { 32 | addCount: bindActionCreators(addCount, dispatch), 33 | startClock: bindActionCreators(startClock, dispatch) 34 | } 35 | } 36 | 37 | export default withRedux(initStore, null, mapDispatchToProps)(Counter) 38 | -------------------------------------------------------------------------------- /examples/with-apollo-and-redux/components/App.js: -------------------------------------------------------------------------------- 1 | export default ({ children }) => ( 2 |
    3 | {children} 4 | 39 |
    40 | ) 41 | -------------------------------------------------------------------------------- /examples/with-styled-jsx-postcss/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-styled-jsx-postcss) 2 | 3 | # Example app with styled-jsx-postcss 4 | 5 | This example features how you use PostCSS with styled-jsx via [styled-jsx-postcss](https://github.com/giuseppeg/styled-jsx-postcss) 6 | 7 | N.B. In order to integrate `styled-jsx-postcss` with Next.js you need to patch Next.js' 8 | babel preset. See [babel-preset.js](./babel-preset.js) and [.babelrc](./.babelrc). 9 | 10 | ## How to use 11 | 12 | Download the example [or clone the repo](https://github.com/zeit/next.js): 13 | 14 | ```bash 15 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-styled-jsx-postcss 16 | cd with-styled-jsx-postcss 17 | ``` 18 | 19 | Install it and run: 20 | 21 | ```bash 22 | npm install 23 | npm run dev 24 | ``` 25 | 26 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 27 | 28 | ```bash 29 | now 30 | ``` 31 | -------------------------------------------------------------------------------- /examples/with-url-object-routing/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-url-object-routing) 2 | # URL object routing 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-url-object-routing 10 | cd with-url-object-routing 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 | Next.js allows using [Node.js URL objects](https://nodejs.org/api/url.html#url_url_strings_and_url_objects) as `href` and `as` values for `` component and parameters of `Router#push` and `Router#replace`. 29 | 30 | This simplify the usage of parameterized URLs when you have many query values. 31 | -------------------------------------------------------------------------------- /examples/using-preact/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/using-preact) 2 | 3 | # Hello World example 4 | 5 | ## How to use 6 | 7 | Download the example [or clone the repo](https://github.com/zeit/next.js): 8 | 9 | ```bash 10 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/using-preact 11 | cd using-preact 12 | ``` 13 | 14 | Install it and run: 15 | 16 | ```bash 17 | npm install 18 | npm run dev 19 | ``` 20 | 21 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 22 | 23 | ```bash 24 | now 25 | ``` 26 | 27 | ## The idea behind the example 28 | 29 | This example uses [Preact](https://github.com/developit/preact) instead of React. It's a React like UI framework which fast and small. Here we've customized Next.js to use Preact instead of React. 30 | 31 | Here's how we did it: 32 | 33 | * Use `next.config.js` to customize our webpack config to support [preact-compat](https://github.com/developit/preact-compat) 34 | -------------------------------------------------------------------------------- /examples/parameterized-routing/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/parameterized-routing) 2 | 3 | # Parametrized routes example (dynamic routing) 4 | 5 | ## How to use 6 | 7 | Download the example [or clone the repo](https://github.com/zeit/next.js): 8 | 9 | ```bash 10 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/parameterized-routing 11 | cd parameterized-routing 12 | ``` 13 | 14 | Install it and run: 15 | 16 | ```bash 17 | npm install 18 | npm run dev 19 | ``` 20 | 21 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 22 | 23 | ```bash 24 | now 25 | ``` 26 | 27 | ## The idea behind the example 28 | 29 | Next.js allows [Custom server and routing](https://github.com/zeit/next.js#custom-server-and-routing) so you can, as we show in this example, parametrize your routes. What we are doing in `server.js` is matching any route with the pattern `/blog/:id` and then passing the id as a parameter to the `pages/blog.js` page. 30 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Zeit, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/unit/shallow-equal.test.js: -------------------------------------------------------------------------------- 1 | /* global describe, it, expect */ 2 | 3 | import shallowEquals from '../../dist/lib/shallow-equals' 4 | 5 | describe('Shallow Equals', () => { 6 | it('should be true if both objects are the same', () => { 7 | const a = { aa: 10 } 8 | expect(shallowEquals(a, a)).toBe(true) 9 | }) 10 | 11 | it('should be true if both objects are similar', () => { 12 | const a = { aa: 10, bb: 30 } 13 | const b = { aa: 10, bb: 30 } 14 | expect(shallowEquals(a, b)).toBe(true) 15 | }) 16 | 17 | it('should be false if objects have different keys', () => { 18 | const a = { aa: 10, bb: 30 } 19 | const b = { aa: 10, cc: 50 } 20 | expect(shallowEquals(a, b)).toBe(false) 21 | }) 22 | 23 | it('should be false if objects have same keys but different values', () => { 24 | const a = { aa: 10, bb: 30 } 25 | const b = { aa: 10, bb: 50 } 26 | expect(shallowEquals(a, b)).toBe(false) 27 | }) 28 | 29 | it('should be false if objects matched deeply', () => { 30 | const a = { aa: 10, bb: { a: 10 } } 31 | const b = { aa: 10, bb: { a: 10 } } 32 | expect(shallowEquals(a, b)).toBe(false) 33 | }) 34 | }) 35 | -------------------------------------------------------------------------------- /examples/layout-component/README.md: -------------------------------------------------------------------------------- 1 | [![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/layout-component) 2 | 3 | # Layout component example 4 | 5 | ## How to use 6 | 7 | Download the example [or clone the repo](https://github.com/zeit/next.js): 8 | 9 | ```bash 10 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/layout-component 11 | cd layout-component 12 | ``` 13 | 14 | Install it and run: 15 | 16 | ```bash 17 | npm install 18 | npm run dev 19 | ``` 20 | 21 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) 22 | 23 | ```bash 24 | now 25 | ``` 26 | 27 | ## The idea behind the example 28 | 29 | This example shows a very common use case when building websites where you need to repeat some sort of layout for all your pages. Our pages are: `home`, `about` and `contact` and they all share the same `` settings, the `