├── .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
│ │ │ ├── index.js
│ │ │ ├── no-ssr-custom-loading.js
│ │ │ └── no-chunk.js
│ │ ├── hmr
│ │ │ ├── about.js
│ │ │ └── contact.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
│ │ ├── hello2.js
│ │ ├── hello-context.js
│ │ └── welcome.js
│ ├── next.config.js
│ └── test
│ │ └── misc.js
│ ├── dist-dir
│ ├── pages
│ │ └── index.js
│ └── next.config.js
│ ├── production
│ ├── components
│ │ ├── hello1.js
│ │ ├── hello2.js
│ │ ├── hello-context.js
│ │ └── welcome.js
│ └── pages
│ │ ├── about.js
│ │ ├── dynamic
│ │ ├── ssr.js
│ │ ├── no-ssr.js
│ │ ├── index.js
│ │ ├── no-ssr-custom-loading.js
│ │ └── no-chunk.js
│ │ └── index.js
│ ├── ondemand
│ ├── pages
│ │ ├── about.js
│ │ └── index.js
│ └── next.config.js
│ └── static
│ ├── components
│ └── hello.js
│ ├── pages
│ ├── about.js
│ ├── get-initial-props-with-no-query.js
│ ├── button-link.js
│ ├── level1
│ │ ├── about.js
│ │ └── index.js
│ ├── dynamic-imports.js
│ ├── counter.js
│ └── dynamic.js
│ ├── next.config.js
│ └── test
│ └── index.test.js
├── examples
├── .gitignore
├── .babelrc
├── with-dotenv
│ ├── .env
│ ├── .env.production
│ ├── pages
│ │ └── index.js
│ ├── .babelrc
│ └── package.json
├── with-typescript
│ ├── .gitignore
│ ├── components
│ │ └── MyComponent.tsx
│ ├── tsconfig.json
│ ├── pages
│ │ └── index.tsx
│ ├── package.json
│ └── README.md
├── with-external-scoped-css
│ ├── .gitignore
│ ├── global.sass
│ ├── 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
│ ├── components
│ │ ├── Layout.js
│ │ └── Nav.js
│ └── scripts
│ │ └── default-lang.js
├── custom-server-koa
│ ├── pages
│ │ ├── a.js
│ │ ├── b.js
│ │ └── index.js
│ └── package.json
├── 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
│ │ │ ├── id
│ │ │ └── common.json
│ │ │ └── pt
│ │ │ └── common.json
│ ├── components
│ │ └── Title.js
│ ├── tools
│ │ ├── startI18n.js
│ │ └── translationHelpers.js
│ ├── package.json
│ ├── README.md
│ └── pages
│ │ └── index.js
├── 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
├── with-scoped-stylesheets-and-postcss
│ ├── pages
│ │ ├── global.css
│ │ ├── styles.css
│ │ └── index.js
│ ├── postcss.config.js
│ └── package.json
├── with-styled-jsx-postcss
│ ├── .babelrc
│ ├── postcss.config.js
│ ├── babel-preset.js
│ ├── package.json
│ └── pages
│ │ └── index.js
├── 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
│ │ ├── contact.js
│ │ └── index.js
│ ├── next.config.js
│ ├── package.json
│ └── 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
├── using-inferno
│ ├── pages
│ │ ├── about.js
│ │ └── index.js
│ ├── next.config.js
│ ├── package.json
│ └── server.js
├── using-preact
│ ├── pages
│ │ ├── about.js
│ │ └── index.js
│ ├── package.json
│ ├── next.config.js
│ └── server.js
├── with-dynamic-import
│ ├── components
│ │ ├── hello1.js
│ │ ├── hello2.js
│ │ ├── hello3.js
│ │ ├── hello4.js
│ │ ├── hello5.js
│ │ ├── hello6.js
│ │ ├── hello7.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
├── with-react-ga
│ ├── pages
│ │ ├── about.js
│ │ └── index.js
│ ├── package.json
│ ├── components
│ │ └── Layout.js
│ └── utils
│ │ └── analytics.js
├── layout-component
│ ├── pages
│ │ ├── index.js
│ │ ├── about.js
│ │ └── contact.js
│ ├── package.json
│ └── components
│ │ └── layout.js
├── using-router
│ ├── pages
│ │ ├── index.js
│ │ ├── about.js
│ │ └── error.js
│ ├── package.json
│ ├── components
│ │ └── Header.js
│ └── README.md
├── with-ant-design
│ ├── .babelrc
│ ├── package.json
│ └── README.md
├── with-prefetching
│ ├── pages
│ │ ├── about.js
│ │ ├── index.js
│ │ ├── contact.js
│ │ └── features.js
│ ├── package.json
│ └── components
│ │ └── Header.js
├── 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-fela
│ ├── layout.js
│ ├── fela-renderer.js
│ ├── package.json
│ └── pages
│ │ └── index.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
├── shared-modules
│ ├── pages
│ │ ├── index.js
│ │ └── about.js
│ ├── package.json
│ └── components
│ │ ├── Header.js
│ │ └── Counter.js
├── with-antd-mobile
│ ├── .babelrc
│ ├── pages
│ │ ├── index.js
│ │ └── _document.js
│ ├── package.json
│ ├── components
│ │ └── Layout.js
│ ├── static
│ │ ├── reload.svg
│ │ └── hd.min.js
│ └── README.md
├── with-apollo-and-redux
│ ├── lib
│ │ └── reducers.js
│ ├── pages
│ │ └── index.js
│ ├── package.json
│ └── components
│ │ └── Header.js
├── basic-css
│ ├── package.json
│ └── pages
│ │ └── index.js
├── with-material-ui
│ ├── next.config.js
│ ├── package.json
│ └── README.md
├── with-pretty-url-routing
│ ├── pages
│ │ └── index.js
│ ├── package.json
│ ├── routes.js
│ ├── server.js
│ └── README.md
├── head-elements
│ ├── package.json
│ └── pages
│ │ └── index.js
├── progressive-render
│ ├── components
│ │ └── Loading.js
│ ├── package.json
│ └── pages
│ │ └── index.js
├── with-material-ui-next
│ ├── package.json
│ └── README.md
├── with-glamor
│ ├── package.json
│ └── pages
│ │ ├── index.js
│ │ └── _document.js
├── with-higher-order-component
│ ├── package.json
│ ├── pages
│ │ └── index.js
│ ├── components
│ │ └── withApp.js
│ └── README.md
├── data-fetch
│ ├── package.json
│ └── pages
│ │ ├── index.js
│ │ └── preact.js
├── with-sw-precache
│ ├── package.json
│ ├── next.config.js
│ ├── pages
│ │ └── index.js
│ └── server.js
├── with-cxs
│ ├── package.json
│ └── pages
│ │ ├── _document.js
│ │ └── index.js
├── with-react-uwp
│ ├── package.json
│ ├── components
│ │ └── ThemeWrapper.js
│ └── README.md
├── with-semantic-ui
│ ├── package.json
│ └── README.md
├── ssr-caching
│ ├── pages
│ │ ├── index.js
│ │ └── blog.js
│ └── package.json
├── with-aphrodite
│ ├── package.json
│ └── pages
│ │ └── index.js
├── parameterized-routing
│ ├── package.json
│ ├── pages
│ │ ├── index.js
│ │ └── blog.js
│ └── server.js
├── with-glamorous
│ ├── package.json
│ └── pages
│ │ └── _document.js
├── with-url-object-routing
│ ├── package.json
│ ├── pages
│ │ ├── index.js
│ │ └── about.js
│ └── server.js
├── with-apollo
│ ├── pages
│ │ └── index.js
│ ├── package.json
│ └── components
│ │ └── Header.js
├── with-react-toolbox
│ └── pages
│ │ └── index.js
├── with-socket.io
│ ├── package.json
│ └── server.js
└── with-redux
│ ├── components
│ ├── Page.js
│ ├── Clock.js
│ └── AddCount.js
│ ├── package.json
│ └── pages
│ └── other.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
├── utils.js
└── router.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
/.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-dotenv/.env:
--------------------------------------------------------------------------------
1 | TEST=it works!
2 |
--------------------------------------------------------------------------------
/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-dotenv/.env.production:
--------------------------------------------------------------------------------
1 | TEST=it works!
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/id/common.json:
--------------------------------------------------------------------------------
1 | {
2 | "hello": "halo"
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/basic/components/hello2.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 | Hello World 2
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-dotenv/pages/index.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 | { process.env.TEST }
3 | )
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-scoped-stylesheets-and-postcss/pages/global.css:
--------------------------------------------------------------------------------
1 | .font-color {
2 | color: blue;
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 |
--------------------------------------------------------------------------------
/test/integration/production/components/hello1.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 | Hello World 1
3 | )
4 |
--------------------------------------------------------------------------------
/test/integration/production/components/hello2.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 | Hello World 2
3 | )
4 |
--------------------------------------------------------------------------------
/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-i18next/static/locales/pt/common.json:
--------------------------------------------------------------------------------
1 | {
2 | "hello": "e ae tche",
3 | "morning": "manha"
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/functions/next.js/v3-beta/examples/with-amp/static/cat.jpg
--------------------------------------------------------------------------------
/examples/with-amp/static/dog.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/functions/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/functions/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-react-md/static/react-md.light_blue-yellow.min.css:
--------------------------------------------------------------------------------
1 | ../node_modules/react-md/dist/react-md.light_blue-yellow.min.css
--------------------------------------------------------------------------------
/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 |
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 |
--------------------------------------------------------------------------------
/examples/with-dynamic-import/components/hello6.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 | Hello World 6 (imported dynamiclly)
3 | )
4 |
--------------------------------------------------------------------------------
/examples/with-dynamic-import/components/hello7.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 | Hello World 7 (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-external-scoped-css/global.sass:
--------------------------------------------------------------------------------
1 | @mixin opacity($opacity)
2 | opacity: $opacity
3 | filter: alpha(opacity=($opacity * 100))
--------------------------------------------------------------------------------
/examples/with-global-stylesheet/example.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/functions/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/functions/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-webpack-bundle-analyzer/pages/contact.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 |
3 | This is the contact page.
4 |
5 | )
6 |
--------------------------------------------------------------------------------
/examples/with-scoped-stylesheets-and-postcss/pages/styles.css:
--------------------------------------------------------------------------------
1 | .paragraph {
2 | composes: font-color from './global.css';
3 | font-size: 20px;
4 | }
5 |
--------------------------------------------------------------------------------
/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 |
4 | )
5 |
--------------------------------------------------------------------------------
/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-external-scoped-css/pages/index.sass:
--------------------------------------------------------------------------------
1 | @import "../global"
2 |
3 | .example
4 | @include opacity(0.5)
5 | font-size: 36px
6 | width: 300px
7 | display: flex
8 |
--------------------------------------------------------------------------------
/examples/with-react-ga/pages/about.js:
--------------------------------------------------------------------------------
1 | import Layout from '../components/Layout'
2 |
3 | export default () => (
4 |
5 | About us
6 |
7 | )
8 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/test/integration/production/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/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 |
--------------------------------------------------------------------------------
/test/integration/basic/pages/hmr/about.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 |
3 |
4 | This is the about page.
5 |
6 |
7 | )
8 |
--------------------------------------------------------------------------------
/examples/with-i18next/components/Title.js:
--------------------------------------------------------------------------------
1 | import { translate } from 'react-i18next'
2 | export default translate(['common'])((props) => ({props.t('hello')}, {props.t('morning')} ))
3 |
--------------------------------------------------------------------------------
/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/hmr/contact.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 |
3 |
4 | This is the contact page.
5 |
6 |
7 | )
8 |
--------------------------------------------------------------------------------
/test/integration/basic/pages/styled-jsx.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 |
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 |
--------------------------------------------------------------------------------
/examples/with-ant-design/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "next/babel"
4 | ],
5 | "plugins": [
6 | ["import", {
7 | "libraryName": "antd"
8 | }]
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/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/dynamic/index.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 |
3 | export default () => (
4 |
7 | )
8 |
--------------------------------------------------------------------------------
/test/integration/basic/pages/link.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Link from 'next/link'
3 | export default () => (
4 |
5 | )
6 |
--------------------------------------------------------------------------------
/test/integration/production/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/using-preact/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Link from 'next/link'
3 |
4 | export default () => (
5 |
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 |
--------------------------------------------------------------------------------
/test/integration/production/pages/dynamic/index.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 |
3 | export default () => (
4 |
7 | )
8 |
--------------------------------------------------------------------------------
/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 |
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 |
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 |
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 |
9 | )
10 |
--------------------------------------------------------------------------------
/test/integration/ondemand/pages/index.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 |
3 | export default () => (
4 |
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-fela/layout.js:
--------------------------------------------------------------------------------
1 | import { Provider } from 'react-fela'
2 | import felaRenderer from './fela-renderer'
3 |
4 | export default ({ children }) =>
5 |
6 | {children}
7 |
8 |
--------------------------------------------------------------------------------
/examples/with-fela/fela-renderer.js:
--------------------------------------------------------------------------------
1 | import { createRenderer } from 'fela'
2 | import webPreset from 'fela-preset-web'
3 |
4 | const felaRenderer = createRenderer({
5 | plugins: [...webPreset]
6 | })
7 |
8 | export default felaRenderer
9 |
--------------------------------------------------------------------------------
/examples/with-react-ga/pages/index.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 | import Layout from '../components/Layout'
3 |
4 | export default () => (
5 |
6 | )
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/test/integration/production/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/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-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-antd-mobile/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "next/babel"
4 | ],
5 | "plugins": [
6 | [
7 | "import",
8 | {
9 | "libraryName": "antd-mobile"
10 | }
11 | ]
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/examples/with-antd-mobile/pages/index.js:
--------------------------------------------------------------------------------
1 | import { Component } from 'react'
2 |
3 | export default class Index extends Component {
4 | static async getInitialProps ({ res }) {
5 | res.setHeader('Location', '/home')
6 | res.statusCode = 302
7 | res.end()
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/examples/with-scoped-stylesheets-and-postcss/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: [
3 | require('postcss-cssnext')(),
4 | require('postcss-modules')({
5 | generateScopedName: '[local]-[hash:base64:5]'
6 | }),
7 | require('cssnano')()
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/examples/with-dotenv/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "next/babel",
4 | ],
5 | "env": {
6 | "development": {
7 | "plugins": ["inline-dotenv"]
8 | },
9 | "production": {
10 | "plugins": ["transform-inline-environment-variables"]
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/test/integration/static/pages/about.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 |
3 | export default () => (
4 |
5 |
10 |
This is the About page
11 |
12 | )
13 |
--------------------------------------------------------------------------------
/test/integration/static/pages/get-initial-props-with-no-query.js:
--------------------------------------------------------------------------------
1 | const Page = ({ query }) => (
2 |
3 | { `Query is: ${query}` }
4 |
5 | )
6 |
7 | Page.getInitialProps = ({ query }) => {
8 | return { query: JSON.stringify(query) }
9 | }
10 |
11 | export default Page
12 |
--------------------------------------------------------------------------------
/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/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/button-link.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 |
--------------------------------------------------------------------------------
/test/integration/static/pages/level1/about.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 |
3 | export default () => (
4 |
5 |
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 |
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/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-refnux/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-refnux",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "next": "next"
6 | },
7 | "license": "ISC",
8 | "dependencies": {
9 | "next": "latest",
10 | "react": "^15.4.2",
11 | "react-dom": "^15.4.2",
12 | "refnux": "^1.3.0"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/test/integration/basic/pages/dynamic/no-chunk.js:
--------------------------------------------------------------------------------
1 | import dynamic from 'next/dynamic'
2 | import Welcome from '../../components/welcome'
3 |
4 | const Welcome2 = dynamic(import('../../components/welcome'))
5 |
6 | export default () => (
7 |
8 |
9 |
10 |
11 | )
12 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/test/integration/production/pages/dynamic/no-chunk.js:
--------------------------------------------------------------------------------
1 | import dynamic from 'next/dynamic'
2 | import Welcome from '../../components/welcome'
3 |
4 | const Welcome2 = dynamic(import('../../components/welcome'))
5 |
6 | export default () => (
7 |
8 |
9 |
10 |
11 | )
12 |
--------------------------------------------------------------------------------
/examples/with-amp/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-amp",
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 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/examples/with-i18next/tools/startI18n.js:
--------------------------------------------------------------------------------
1 | import i18n from 'i18next'
2 |
3 | const startI18n = (file, lang) => i18n.init({
4 | lng: lang, // active language http://i18next.com/translate/
5 | fallbackLng: 'pt',
6 | resources: file,
7 | ns: ['common'],
8 | defaultNS: 'common',
9 | debug: false
10 | })
11 |
12 | export default startI18n
13 |
--------------------------------------------------------------------------------
/.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/basic-css/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "basic-css",
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 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/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 |
11 |
12 | )
13 | }
14 |
--------------------------------------------------------------------------------
/examples/head-elements/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "head-elements",
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 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/examples/hello-world/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hello-world",
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 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/examples/using-router/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "using-router",
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 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/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 |
12 |
--------------------------------------------------------------------------------
/bench/pages/stateless-big.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default () => {
4 | return (
5 |
8 | )
9 | }
10 |
11 | const items = () => {
12 | var out = new Array(10000)
13 | for (let i = 0; i < out.length; i++) {
14 | out[i] = This is row {i + 1}
15 | }
16 | return out
17 | }
18 |
--------------------------------------------------------------------------------
/examples/progressive-render/components/Loading.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default () => (
4 |
5 |
Loading...
6 |
14 |
15 | )
16 |
--------------------------------------------------------------------------------
/examples/shared-modules/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "shared-modules",
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 | "license": "ISC"
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 |
8 | bazinga
9 |
10 | )
11 |
--------------------------------------------------------------------------------
/examples/custom-server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "custom-server",
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 | "next": "latest",
11 | "react": "^15.4.2",
12 | "react-dom": "^15.4.2"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/examples/layout-component/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "layout-component",
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 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/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": "latest",
11 | "react": "^15.4.2",
12 | "react-dom": "^15.4.2"
13 | },
14 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/examples/with-i18next/tools/translationHelpers.js:
--------------------------------------------------------------------------------
1 | /* global fetch */
2 | import 'isomorphic-fetch'
3 |
4 | export async function getTranslation (lang, file, baseUrl) {
5 | const response = await fetch(`${baseUrl}${lang}/${file}.json`)
6 | const json = await response.json()
7 |
8 | return {
9 | [lang]: {
10 | [file]: json
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/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 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/test/integration/basic/pages/nav/as-path.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default class extends React.Component {
4 | static getInitialProps ({ asPath, req }) {
5 | return { asPath }
6 | }
7 |
8 | render () {
9 | return (
10 |
11 | {this.props.asPath}
12 |
13 | )
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/examples/head-elements/pages/index.js:
--------------------------------------------------------------------------------
1 | import Head from 'next/head'
2 |
3 | export default () => (
4 |
5 |
6 |
This page has a title 🤔
7 |
8 |
9 |
10 |
11 | This page has a title 🤔
12 |
13 | )
14 |
--------------------------------------------------------------------------------
/examples/progressive-render/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "progressive-render",
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 | "react-no-ssr": "1.1.0"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/examples/root-static-files/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "root-static-files",
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 | "next": "latest",
11 | "react": "^15.5.4",
12 | "react-dom": "^15.5.4"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/examples/svg-components/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Cat from '../svgs/cat.svg'
3 |
4 | export default () => (
5 |
6 | SVG Cat!
7 |
8 |
14 |
15 | )
16 |
--------------------------------------------------------------------------------
/examples/with-external-scoped-css/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["next/babel"],
3 | "plugins": [
4 | [
5 | "css-modules-transform", {
6 | "extensions": [".css", ".sass"],
7 | "append": [ "postcss-cssnext" ],
8 | "extractCss": "./static/css/bundle.css",
9 | "preprocessCss": "./pre-processor.js"
10 | }
11 | ]
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/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/with-material-ui-next/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-material-ui-next",
3 | "version": "1.0.0",
4 | "dependencies": {
5 | "material-ui": "next",
6 | "next": "latest",
7 | "react": "^15.5.4",
8 | "react-dom": "^15.5.4"
9 | },
10 | "scripts": {
11 | "dev": "next",
12 | "build": "next build",
13 | "start": "next start"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/examples/with-typescript/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-typescript",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "dev": "concurrently \"tsc --watch\" next"
6 | },
7 | "dependencies": {
8 | "next": "latest"
9 | },
10 | "devDependencies": {
11 | "@types/react": "^15.0.1",
12 | "concurrently": "^3.1.0",
13 | "typescript": "^2.1.5"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/test/integration/basic/components/hello-context.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import PropTypes from 'prop-types'
3 |
4 | export default class extends React.Component {
5 | static contextTypes = {
6 | data: PropTypes.object
7 | }
8 |
9 | render () {
10 | const { data } = this.context
11 | return (
12 | {data.title}
13 | )
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 | "license": "ISC"
16 | }
17 |
--------------------------------------------------------------------------------
/examples/with-higher-order-component/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-higher-order-component",
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 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/test/integration/production/components/hello-context.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import PropTypes from 'prop-types'
3 |
4 | export default class extends React.Component {
5 | static contextTypes = {
6 | data: PropTypes.object
7 | }
8 |
9 | render () {
10 | const { data } = this.context
11 | return (
12 | {data.title}
13 | )
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/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 | "license": "ISC"
16 | }
17 |
--------------------------------------------------------------------------------
/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-sw-precache/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-sw-precache",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "build": "next build",
6 | "start": "NODE_ENV=production node server.js"
7 | },
8 | "dependencies": {
9 | "next": "latest",
10 | "react": "^15.4.2",
11 | "react-dom": "^15.4.2",
12 | "sw-precache-webpack-plugin": "^0.11.3"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/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/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/with-react-uwp/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-react-uwp",
3 | "version": "1.0.0",
4 | "dependencies": {
5 | "babel-core": "^6.25.0",
6 | "next": "latest",
7 | "react": "^15.5.4",
8 | "react-dom": "^15.5.4",
9 | "react-uwp": "^1.0.9"
10 | },
11 | "scripts": {
12 | "dev": "next",
13 | "build": "next build",
14 | "start": "next start"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/examples/with-next-routes/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-next-routes",
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 | "next": "latest",
11 | "next-routes": "^1.0.17",
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 | "license": "ISC"
16 | }
17 |
--------------------------------------------------------------------------------
/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-react-ga/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-react-ga",
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 | "react-ga": "2.2.0"
14 | },
15 | "author": "",
16 | "license": "ISC"
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 |
15 | )
16 |
--------------------------------------------------------------------------------
/examples/custom-server-express/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "custom-server-express",
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 | "express": "^4.14.0",
11 | "next": "latest",
12 | "react": "^15.4.2",
13 | "react-dom": "^15.4.2"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/examples/parameterized-routing/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "parameterized-routing",
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 | "next": "latest",
11 | "path-match": "1.2.4",
12 | "react": "^15.4.2",
13 | "react-dom": "^15.4.2"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/examples/parameterized-routing/pages/index.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 |
3 | export default () => (
4 |
9 | )
10 |
--------------------------------------------------------------------------------
/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 | "license": "ISC"
17 | }
18 |
--------------------------------------------------------------------------------
/examples/with-material-ui/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-material-ui",
3 | "version": "1.0.0",
4 | "dependencies": {
5 | "material-ui": "^0.18.0",
6 | "next": "latest",
7 | "react": "^15.5.4",
8 | "react-dom": "^15.5.4",
9 | "react-tap-event-plugin": "^2.0.1"
10 | },
11 | "scripts": {
12 | "dev": "next",
13 | "build": "next build",
14 | "start": "next start"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/examples/with-url-object-routing/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-url-object-routing",
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 | "next": "latest",
11 | "path-match": "1.2.4",
12 | "react": "^15.4.2",
13 | "react-dom": "^15.4.2"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/examples/ssr-caching/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ssr-caching",
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 | "express": "^4.14.0",
11 | "lru-cache": "^4.0.2",
12 | "next": "latest",
13 | "react": "^15.4.2",
14 | "react-dom": "^15.4.2"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/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/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 |
this.add()}>Add
16 |
17 | )
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/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 | "license": "ISC"
16 | }
17 |
--------------------------------------------------------------------------------
/examples/with-ant-design/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-ant-design",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "dev": "next",
6 | "build": "next build",
7 | "start": "next start"
8 | },
9 | "dependencies": {
10 | "antd": "^2.10.2",
11 | "babel-plugin-import": "^1.1.1",
12 | "next": "latest",
13 | "react": "^15.5.4",
14 | "react-dom": "^15.5.4"
15 | },
16 | "license": "ISC"
17 | }
18 |
--------------------------------------------------------------------------------
/examples/custom-server-koa/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "custom-server-koa",
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 | "koa": "^2.0.1",
11 | "koa-router": "^7.1.0",
12 | "next": "latest",
13 | "react": "^15.4.2",
14 | "react-dom": "^15.4.2"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/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 |
this.add()}>Add
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-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": "^5.0.1",
11 | "fela-dom": "5.0.2",
12 | "fela-preset-web": "^5.0.2",
13 | "next": "latest",
14 | "react": "^15.4.2",
15 | "react-dom": "^15.4.2",
16 | "react-fela": "^5.0.2"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/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-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 |
--------------------------------------------------------------------------------
/test/integration/basic/components/welcome.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default class Welcome extends React.Component {
4 | state = { name: null }
5 |
6 | componentDidMount () {
7 | const { name } = this.props
8 | this.setState({ name })
9 | }
10 |
11 | render () {
12 | const { name } = this.state
13 | if (!name) return null
14 |
15 | return (
16 | Welcome, {name}
17 | )
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/test/integration/production/components/welcome.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default class Welcome extends React.Component {
4 | state = { name: null }
5 |
6 | componentDidMount () {
7 | const { name } = this.props
8 | this.setState({ name })
9 | }
10 |
11 | render () {
12 | const { name } = this.state
13 | if (!name) return null
14 |
15 | return (
16 | Welcome, {name}
17 | )
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/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": "latest",
13 | "react": "^15.4.2",
14 | "react-dom": "^15.4.2",
15 | "react-i18next": "^2.2.1"
16 | },
17 | "license": "ISC"
18 | }
19 |
--------------------------------------------------------------------------------
/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 | "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 |
21 | )
22 |
--------------------------------------------------------------------------------
/examples/custom-server-hapi/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "custom-server-hapi",
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 | "hapi": "^16.1.0",
11 | "next": "latest",
12 | "react": "^15.4.2",
13 | "react-dom": "^15.4.2",
14 | "good": "^7.1.0",
15 | "good-console": "^6.2.0"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/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 |
17 | )
18 |
--------------------------------------------------------------------------------
/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 | "license": "MIT"
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.5",
11 | "next": "latest",
12 | "react": "^15.6.1",
13 | "react-dom": "^15.6.1",
14 | "styled-components": "^2.1.0"
15 | },
16 | "license": "ISC"
17 | }
18 |
--------------------------------------------------------------------------------
/examples/with-webpack-bundle-analyzer/next.config.js:
--------------------------------------------------------------------------------
1 | const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
2 | const { ANALYZE } = process.env
3 |
4 | module.exports = {
5 | webpack: function (config) {
6 | if (ANALYZE) {
7 | config.plugins.push(new BundleAnalyzerPlugin({
8 | analyzerMode: 'server',
9 | analyzerPort: 8888,
10 | openAnalyzer: true
11 | }))
12 | }
13 |
14 | return config
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/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-dotenv/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-dotenv",
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 | "babel-plugin-inline-dotenv": "^1.1.1",
14 | "babel-plugin-transform-inline-environment-variables": "^0.1.1"
15 | },
16 | "license": "ISC"
17 | }
18 |
--------------------------------------------------------------------------------
/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-universal-configuration",
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 | "license": "ISC"
18 | }
19 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/test/integration/basic/test/misc.js:
--------------------------------------------------------------------------------
1 | /* global describe, test, expect */
2 |
3 | export default function (context) {
4 | describe('Misc', () => {
5 | test('finishes response', async () => {
6 | const res = {
7 | finished: false,
8 | end () {
9 | this.finished = true
10 | }
11 | }
12 | const html = await context.app.renderToHTML({}, res, '/finish-response', {})
13 | expect(html).toBeFalsy()
14 | })
15 | })
16 | }
17 |
--------------------------------------------------------------------------------
/examples/nested-components/components/post.js:
--------------------------------------------------------------------------------
1 | export default ({ title, children }) => (
2 |
3 |
{ title }
4 | { children }
5 |
18 |
19 | )
20 |
--------------------------------------------------------------------------------
/examples/with-antd-mobile/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-antd-mobile",
3 | "version": "1.1.0",
4 | "dependencies": {
5 | "antd-mobile": "1.4.0",
6 | "babel-plugin-import": "^1.2.1",
7 | "next": "latest",
8 | "react": "^15.6.1",
9 | "react-dom": "^15.6.1",
10 | "require-hacker": "^3.0.0",
11 | "svg-sprite-loader": "0.3.1"
12 | },
13 | "scripts": {
14 | "dev": "next",
15 | "build": "next build",
16 | "start": "next start"
17 | }
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-react-ga/components/Layout.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { initGA, logPageView } from '../utils/analytics'
3 |
4 | export default class Layout extends React.Component {
5 | componentDidMount () {
6 | if (!window.GA_INITIALIZED) {
7 | initGA()
8 | window.GA_INITIALIZED = true
9 | }
10 | logPageView()
11 | }
12 | render () {
13 | return (
14 |
15 | {this.props.children}
16 |
17 | )
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/examples/with-react-uwp/components/ThemeWrapper.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import Theme from 'react-uwp/Theme'
3 |
4 | export class ThemeWrapper extends Component {
5 | render () {
6 | const { children, style, ...props } = this.props
7 | return (
8 |
9 | {children}
10 |
11 | )
12 | }
13 | }
14 |
15 | export default ThemeWrapper
16 |
--------------------------------------------------------------------------------
/examples/with-pretty-url-routing/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-pretty-url-routing",
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 | "express": "^4.15.2",
11 | "next": "latest",
12 | "next-url-prettifier": "^1.0.2",
13 | "prop-types": "^15.5.6",
14 | "react": "^15.4.2",
15 | "react-dom": "^15.4.2"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | "license": "ISC"
18 | }
19 |
--------------------------------------------------------------------------------
/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/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-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-beta13",
14 | "react": "^15.4.2",
15 | "react-dom": "^15.4.2"
16 | },
17 | "author": "",
18 | "license": "ISC"
19 | }
20 |
--------------------------------------------------------------------------------
/examples/with-react-toolbox/pages/index.js:
--------------------------------------------------------------------------------
1 | import ThemeProvider from 'react-toolbox/lib/ThemeProvider'
2 | import theme from '../static/theme'
3 | import Head from 'next/head'
4 |
5 | import Button from 'react-toolbox/lib/button/Button'
6 |
7 | export default () => (
8 |
9 |
10 |
11 |
12 |
13 | Hello
14 |
15 |
16 | )
17 |
--------------------------------------------------------------------------------
/examples/with-socket.io/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-socket.io",
3 | "version": "1.0.0",
4 | "dependencies": {
5 | "express": "^4.15.2",
6 | "isomorphic-fetch": "^2.2.1",
7 | "next": "latest",
8 | "react": "^15.5.4",
9 | "react-dom": "^15.5.4",
10 | "socket.io": "^1.7.3",
11 | "socket.io-client": "^1.7.3"
12 | },
13 | "scripts": {
14 | "dev": "node server.js",
15 | "build": "next build",
16 | "start": "NODE_ENV=production node server.js"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/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-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 |
13 | Navigate
14 |
15 |
16 | )
17 | })
18 |
--------------------------------------------------------------------------------
/examples/with-jest/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-jest",
3 | "version": "1.0.0",
4 | "dependencies": {
5 | "next": "latest",
6 | "react": "^15.5.4",
7 | "react-dom": "^15.5.4"
8 | },
9 | "devDependencies": {
10 | "enzyme": "^2.8.2",
11 | "jest": "^20.0.0",
12 | "react-addons-test-utils": "^15.5.1",
13 | "react-test-renderer": "^15.5.4"
14 | },
15 | "scripts": {
16 | "test": "jest",
17 | "dev": "next",
18 | "build": "next build",
19 | "start": "next start"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/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 | "redux-devtools-extension": "^2.13.2",
14 | "react-dom": "^15.4.2",
15 | "react-redux": "^5.0.1",
16 | "redux": "^3.6.0",
17 | "redux-thunk": "^2.1.0"
18 | },
19 | "license": "ISC"
20 | }
21 |
--------------------------------------------------------------------------------
/examples/with-antd-mobile/components/Layout.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { LocaleProvider } from 'antd-mobile'
3 | import enUS from 'antd-mobile/lib/locale-provider/en_US'
4 |
5 | export default class Layout extends Component {
6 | render () {
7 | const { language, children } = this.props
8 | const locale = language.substr(0, 2) === 'en' ? enUS : undefined
9 |
10 | return (
11 |
12 | {children}
13 |
14 | )
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/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-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 | "license": "ISC",
17 | "devDependencies": {
18 | "babel-plugin-transform-decorators-legacy": "^1.3.4"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/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 | "analyze": "cross-env ANALYZE=1 next build"
9 | },
10 | "dependencies": {
11 | "next": "latest",
12 | "cross-env": "^5.0.1",
13 | "faker": "^4.1.0",
14 | "react": "^15.6.1",
15 | "react-dom": "^15.6.1",
16 | "webpack-bundle-analyzer": "^2.8.2"
17 | },
18 | "license": "ISC"
19 | }
20 |
--------------------------------------------------------------------------------
/examples/with-sw-precache/next.config.js:
--------------------------------------------------------------------------------
1 | const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
2 |
3 | module.exports = {
4 | webpack: (config) => {
5 | config.plugins.push(
6 | new SWPrecacheWebpackPlugin({
7 | verbose: true,
8 | staticFileGlobsIgnorePatterns: [/\.next\//],
9 | runtimeCaching: [
10 | {
11 | handler: 'networkFirst',
12 | urlPattern: /^https?.*/
13 | }
14 | ]
15 | })
16 | )
17 |
18 | return config
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/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-higher-order-component/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import withApp from '../components/withApp'
3 |
4 | class Index extends React.Component {
5 | static getInitialProps (context) {
6 | const { isServer } = context
7 | return { isServer }
8 | }
9 | render () {
10 | const { greeting } = this.props
11 | return (
12 |
13 |
Index page
14 | {greeting}
15 |
16 | )
17 | }
18 | }
19 |
20 | export default withApp(Index)
21 |
--------------------------------------------------------------------------------
/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-antd-mobile/pages/_document.js:
--------------------------------------------------------------------------------
1 | import Document, { Head, Main, NextScript } from 'next/document'
2 |
3 | export default class extends Document {
4 | render () {
5 | return (
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | )
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/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-antd-mobile/static/reload.svg:
--------------------------------------------------------------------------------
1 | Share Icons Copy
--------------------------------------------------------------------------------
/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 | "license": "ISC"
20 | }
21 |
--------------------------------------------------------------------------------
/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 | "postcss": "^5.2.16",
21 | "postcss-cssnext": "^2.10.0"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/with-firebase/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-firebase",
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 | "body-parser": "^1.17.1",
11 | "express": "^4.14.0",
12 | "express-session": "^1.15.2",
13 | "firebase": "^3.7.5",
14 | "firebase-admin": "^4.2.0",
15 | "isomorphic-fetch": "2.2.1",
16 | "next": "latest",
17 | "react": "^15.4.2",
18 | "react-dom": "^15.4.2",
19 | "session-file-store": "^1.0.0"
20 | }
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 |
--------------------------------------------------------------------------------
/server/utils.js:
--------------------------------------------------------------------------------
1 | import { join } from 'path'
2 | import { readdirSync, existsSync } from 'fs'
3 |
4 | export const IS_BUNDLED_PAGE = /^bundles[/\\]pages.*\.js$/
5 | export const MATCH_ROUTE_NAME = /^bundles[/\\]pages[/\\](.*)\.js$/
6 |
7 | export function getAvailableChunks (dir, dist) {
8 | const chunksDir = join(dir, dist, 'chunks')
9 | if (!existsSync(chunksDir)) return {}
10 |
11 | const chunksMap = {}
12 | const chunkFiles = readdirSync(chunksDir)
13 |
14 | chunkFiles.forEach(filename => {
15 | if (/\.js$/.test(filename)) {
16 | chunksMap[filename] = true
17 | }
18 | })
19 |
20 | return chunksMap
21 | }
22 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 --ignore-checksums 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-styled-jsx-postcss/pages/index.js:
--------------------------------------------------------------------------------
1 | export default () => (
2 |
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 |
--------------------------------------------------------------------------------
/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 |
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 | [](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/with-sw-precache/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default class extends React.PureComponent {
4 | componentDidMount () {
5 | if ('serviceWorker' in navigator) {
6 | navigator.serviceWorker
7 | .register('/service-worker.js')
8 | .then(registration => {
9 | console.log('service worker registration successful')
10 | })
11 | .catch(err => {
12 | console.warn('service worker registration failed', err.message)
13 | })
14 | }
15 | }
16 | render () {
17 | return (
18 | Check the console for the Service Worker registration status.
19 | )
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/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 |
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 |
--------------------------------------------------------------------------------
/examples/with-higher-order-component/components/withApp.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | function withApp (Child) {
4 | return class WrappedComponent extends React.Component {
5 | static getInitialProps (context) {
6 | return Child.getInitialProps(context)
7 | }
8 | render () {
9 | return (
10 |
11 |
14 |
15 |
16 |
17 |
20 |
21 | )
22 | }
23 | }
24 | }
25 |
26 | export default withApp
27 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/test/integration/static/next.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | exportPathMap: function () {
3 | return {
4 | '/': { page: '/' },
5 | '/about': { page: '/about' },
6 | '/button-link': { page: '/button-link' },
7 | '/get-initial-props-with-no-query': { page: '/get-initial-props-with-no-query' },
8 | '/counter': { page: '/counter' },
9 | '/dynamic-imports': { page: '/dynamic-imports' },
10 | '/dynamic': { page: '/dynamic', query: { text: 'cool dynamic text' } },
11 | '/dynamic/one': { page: '/dynamic', query: { text: 'next export is nice' } },
12 | '/dynamic/two': { page: '/dynamic', query: { text: 'zeit is awesome' } }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/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 |
Go to /about/zeit
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 |
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 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
27 |
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-scoped-stylesheets-and-postcss/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-scoped-stylesheets-and-postcss",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "dev": "next dev",
6 | "build": "next build",
7 | "start": "next start"
8 | },
9 | "author": "Thomas Lindstrøm ",
10 | "license": "ISC",
11 | "dependencies": {
12 | "cssnano": "^3.10.0",
13 | "next": "latest",
14 | "postcss-cssnext": "^2.9.0",
15 | "postcss-loader": "^1.3.0",
16 | "postcss-modules": "^0.6.4",
17 | "react": "^15.4.2",
18 | "react-dom": "^15.4.2",
19 | "skeleton-loader": "^1.1.2",
20 | "trash": "^4.0.1"
21 | },
22 | "devDependencies": {
23 | "now": "^4.10.3"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/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 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | )
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/test/integration/basic/pages/nav/querystring.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Link from 'next/link'
3 |
4 | export default class AsyncProps extends React.Component {
5 | static async getInitialProps ({ query: { id = 0 } }) {
6 | return { id }
7 | }
8 |
9 | render () {
10 | return (
11 |
20 | )
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/with-styled-components/pages/_document.js:
--------------------------------------------------------------------------------
1 | import Document, { Head, Main, NextScript } from 'next/document'
2 | import { ServerStyleSheet } from 'styled-components'
3 |
4 | export default class MyDocument extends Document {
5 | render () {
6 | const sheet = new ServerStyleSheet()
7 | const main = sheet.collectStyles( )
8 | const styleTags = sheet.getStyleElement()
9 | return (
10 |
11 |
12 | My page
13 | {styleTags}
14 |
15 |
16 |
17 | {main}
18 |
19 |
20 |
21 |
22 | )
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing to Next.js
2 |
3 | Our Commitment to Open Source can be found [here](https://zeit.co/blog/oss)
4 |
5 | 1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device.
6 | 2. Install the dependencies: `npm install`
7 | 3. Run `npm link` to link the local repo to NPM
8 | 4. Run `npm run build` to build and watch for code changes
9 | 5. Then npm link this repo inside any example app with `npm link next`
10 | 6. Then you can run your example app with the local version of Next.js (You may need to re-run the example app as you change server side code in the Next.js repository)
11 |
--------------------------------------------------------------------------------
/examples/layout-component/components/layout.js:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 | import Head from 'next/head'
3 |
4 | export default ({ children, title = 'This is the default title' }) => (
5 |
6 |
7 |
{ title }
8 |
9 |
10 |
11 |
18 |
19 | { children }
20 |
21 |
22 | {'I`m here to stay'}
23 |
24 |
25 | )
26 |
--------------------------------------------------------------------------------
/test/integration/static/pages/counter.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Link from 'next/link'
3 |
4 | let counter = 0
5 |
6 | export default class Counter extends React.Component {
7 | increaseCounter () {
8 | counter++
9 | this.forceUpdate()
10 | }
11 |
12 | render () {
13 | return (
14 |
15 |
20 |
Counter: {counter}
21 |
this.increaseCounter()}
24 | >
25 | Increase
26 |
27 |
28 | )
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/examples/with-mobx/pages/other.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Provider } from 'mobx-react'
3 | import { initStore } from '../store'
4 | import Page from '../components/Page'
5 |
6 | export default class Counter extends React.Component {
7 | static getInitialProps ({ req }) {
8 | const isServer = !!req
9 | const store = initStore(isServer)
10 | return { lastUpdate: store.lastUpdate, isServer }
11 | }
12 |
13 | constructor (props) {
14 | super(props)
15 | this.store = initStore(props.isServer, props.lastUpdate)
16 | }
17 |
18 | render () {
19 | return (
20 |
21 |
22 |
23 | )
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/examples/with-react-ga/utils/analytics.js:
--------------------------------------------------------------------------------
1 | import ReactGA from 'react-ga'
2 |
3 | export const initGA = () => {
4 | console.log('GA init')
5 | ReactGA.initialize('UA-xxxxxxxxx-1')
6 | }
7 |
8 | export const logPageView = () => {
9 | console.log(`Logging pageview for ${window.location.pathname}`)
10 | ReactGA.set({ page: window.location.pathname })
11 | ReactGA.pageview(window.location.pathname)
12 | }
13 |
14 | export const logEvent = (category = '', action = '') => {
15 | if (category && action) {
16 | ReactGA.event({ category, action })
17 | }
18 | }
19 |
20 | export const logException = (description = '', fatal = false) => {
21 | if (description) {
22 | ReactGA.exception({ description, fatal })
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/with-mobx/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Provider } from 'mobx-react'
3 | import { initStore } from '../store'
4 | import Page from '../components/Page'
5 |
6 | export default class Counter extends React.Component {
7 | static getInitialProps ({ req }) {
8 | const isServer = !!req
9 | const store = initStore(isServer)
10 | return { lastUpdate: store.lastUpdate, isServer }
11 | }
12 |
13 | constructor (props) {
14 | super(props)
15 | this.store = initStore(props.isServer, props.lastUpdate)
16 | }
17 |
18 | render () {
19 | return (
20 |
21 |
22 |
23 | )
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/examples/progressive-render/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import NoSSR from 'react-no-ssr'
3 | import Loading from '../components/Loading'
4 |
5 | export default () => (
6 |
7 |
8 |
9 | This section is server-side rendered.
10 |
11 |
12 |
13 | }>
14 |
15 |
16 | This section is only client-side rendered.
17 |
18 |
19 |
20 |
21 |
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/v3-beta | tar -xz --strip=2 next.js-3-beta/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 |
22 | Navigate
23 |
24 |
25 | )
26 | }
27 | }
28 |
29 | export default Page
30 |
--------------------------------------------------------------------------------
/examples/with-webpack-bundle-analyzer/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Link from 'next/link'
3 |
4 | export default class Index extends React.Component {
5 | static getInitialProps ({ req }) {
6 | if (req) {
7 | // Runs only in the server
8 | const faker = require('faker')
9 | const name = faker.name.findName()
10 | return { name }
11 | }
12 |
13 | // Runs only in the client
14 | return { name: 'Arunoda' }
15 | }
16 |
17 | render () {
18 | const { name } = this.props
19 | return (
20 |
21 |
Home Page
22 |
Welcome, {name}
23 |
26 |
27 | )
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/examples/with-higher-order-component/README.md:
--------------------------------------------------------------------------------
1 | [](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-higher-order-component)
2 |
3 | # Higher Order Component example
4 |
5 | ## How to use
6 |
7 | Download the example [or clone the repo](https://github.com/zeit/next.js):
8 |
9 | Install it and run:
10 |
11 | **npm**
12 | ```bash
13 | npm install
14 | npm run dev
15 | ```
16 |
17 | **yarn**
18 | ```bash
19 | npm install
20 | npm run dev
21 | ```
22 |
23 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
24 |
25 | ```bash
26 | now
27 | ```
28 |
29 | ## About example
30 |
31 | This example show you how to create Higher Order Component in next.js
32 |
--------------------------------------------------------------------------------
/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-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 |
30 | )
31 |
--------------------------------------------------------------------------------
/test/integration/static/pages/dynamic.js:
--------------------------------------------------------------------------------
1 | /* global location */
2 | import React from 'react'
3 | import Link from 'next/link'
4 |
5 | export default class DynamicPage extends React.Component {
6 | state = {}
7 |
8 | static getInitialProps ({ query }) {
9 | return { text: query.text }
10 | }
11 |
12 | componentDidMount () {
13 | const [, hash] = location.href.split('#')
14 | this.setState({ hash })
15 | }
16 |
17 | render () {
18 | const { text } = this.props
19 | const { hash } = this.state
20 |
21 | return (
22 |
23 |
28 |
{ text }
29 |
Hash: {hash}
30 |
31 | )
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/examples/with-fela/pages/index.js:
--------------------------------------------------------------------------------
1 | import { createComponent } from 'react-fela'
2 | import Page from '../layout'
3 |
4 | const Container = createComponent(() => ({
5 | maxWidth: 700,
6 | marginLeft: 'auto',
7 | marginRight: 'auto',
8 | lineHeight: 1.5
9 | }))
10 |
11 | const Text = createComponent(({ size = 16 }) => ({
12 | fontFamily:
13 | '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
14 | fontSize: size,
15 | color: '#333'
16 | }))
17 |
18 | const Title = createComponent(
19 | ({ size = 24 }) => ({
20 | fontSize: size,
21 | color: '#555'
22 | }),
23 | Text,
24 | )
25 |
26 | export default () =>
27 |
28 |
29 | My Title
30 | Hi, I am Fela.
31 |
32 |
33 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | ))
27 |
--------------------------------------------------------------------------------
/examples/with-global-stylesheet/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "with-global-stylesheet",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "dev": "next dev",
6 | "build": "next build",
7 | "start": "next start"
8 | },
9 | "author": "Davide Bertola ",
10 | "license": "ISC",
11 | "dependencies": {
12 | "autoprefixer": "6.7.6",
13 | "babel-plugin-module-resolver": "2.5.0",
14 | "babel-plugin-wrap-in-js": "^1.1.0",
15 | "glob": "7.1.1",
16 | "next": "latest",
17 | "node-sass": "^4.4.0",
18 | "normalize.css": "5.0.0",
19 | "postcss-easy-import": "2.0.0",
20 | "postcss-loader": "1.3.3",
21 | "raw-loader": "^0.5.1",
22 | "react": "^15.4.2",
23 | "react-dom": "^15.4.2",
24 | "sass-loader": "^4.1.1"
25 | },
26 | "devDependencies": {
27 | "now": "^3.1.0"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/examples/with-sw-precache/server.js:
--------------------------------------------------------------------------------
1 | const { createServer } = require('http')
2 | const { join } = require('path')
3 | const { parse } = require('url')
4 | const next = require('next')
5 |
6 | const dev = process.env.NODE_ENV !== 'production'
7 | const app = next({ dev })
8 | const handle = app.getRequestHandler()
9 |
10 | app.prepare()
11 | .then(() => {
12 | createServer((req, res) => {
13 | const parsedUrl = parse(req.url, true)
14 | const { pathname } = parsedUrl
15 |
16 | if (pathname === '/service-worker.js') {
17 | const filePath = join(__dirname, '.next', pathname)
18 | app.serveStatic(req, res, filePath)
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-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,
9 | title?: string
10 | }
11 |
12 | export default ({children, title = 'This is the default title'}: Props) => (
13 |
14 |
15 |
{title}
16 |
17 |
18 |
19 |
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/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 | [](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-refnux/pages/page2.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 Page2 = connect(
12 | (state, dispatch) =>
13 |
14 |
{state.title}
15 |
Current state: {JSON.stringify(state, null, 2)}
16 |
dispatch(counterIncrement)} >Increment
17 |
go to page 2
18 |
19 | )
20 |
21 | Page2.getInitialProps = async function (context) {
22 | const {store} = context
23 | store.dispatch(setTitle('Page 2'))
24 | return {}
25 | }
26 |
27 | export default withRefnux(getInitialState, Page2)
28 |
--------------------------------------------------------------------------------
/examples/with-amp/README.md:
--------------------------------------------------------------------------------
1 | [](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-amp)
2 |
3 | # Google AMP
4 |
5 | ## How to use
6 |
7 | Download the example [or clone the repo](https://github.com/zeit/next.js.git):
8 |
9 | ```bash
10 | curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-amp
11 | cd with-amp
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 the construction of custom Documents. This feature enable the usage of custom attributes and elements. In this case, AMP tags and attributes.
30 |
--------------------------------------------------------------------------------
/examples/with-i18next/README.md:
--------------------------------------------------------------------------------
1 |
2 | # with-i18next example
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-i18next
10 | cd with-i18next
11 | ```
12 |
13 | Install it and run:
14 |
15 | ```bash
16 | npm install
17 | npm run dev
18 | ```
19 |
20 | alternatively
21 | ```bash
22 | yarn && yarn dev
23 | ```
24 |
25 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
26 |
27 | ```bash
28 | now
29 | ```
30 |
31 | ## The idea behind the example
32 |
33 | This example shows how to add internationalisation through [i18next](https://github.com/i18next/i18next) to your NextJS app. The possibilities and features are documented in the [i18next project](http://i18next.com/translate/)
34 |
--------------------------------------------------------------------------------
/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 | // get language from query parameter or url path
8 | const lang = 'id'
9 |
10 | export default class Homepage extends Component {
11 | static async getInitialProps () {
12 | const translations = await getTranslation(lang, 'common', 'http://localhost:3000/static/locales/')
13 |
14 | return { translations }
15 | }
16 |
17 | constructor (props) {
18 | super(props)
19 |
20 | this.i18n = startI18n(props.translations, lang)
21 | }
22 |
23 | render (props) {
24 | return (
25 |
26 |
27 |
28 | )
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/examples/with-pretty-url-routing/README.md:
--------------------------------------------------------------------------------
1 | [](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-pretty-url-routing)
2 |
3 | # Example app with pretty url 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/with-pretty-url-routing
11 | cd with-pretty-url-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 | This example features:
30 | - route customisation and parameterization
31 | - reverse routing
32 |
--------------------------------------------------------------------------------
/examples/with-antd-mobile/README.md:
--------------------------------------------------------------------------------
1 | [](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-material-ui)
2 | # Ant Design Mobile example
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-antd-mobile
10 | cd with-antd-mobile
11 | ```
12 |
13 | Install it and run:
14 |
15 | ```bash
16 | npm install
17 | npm run dev
18 | ```
19 |
20 | Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
21 |
22 | ```bash
23 | now
24 | ```
25 |
26 | ## The idea behind the example
27 |
28 | This example features how you use [antd-mobile](https://github.com/ant-design/ant-design-mobile) (Ant Design Mobile FrontEnd Framwork) with Next.js.
29 |
--------------------------------------------------------------------------------
/examples/with-aphrodite/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { StyleSheet, css } from 'aphrodite'
3 |
4 | if (typeof window !== 'undefined') {
5 | /* StyleSheet.rehydrate takes an array of rendered classnames,
6 | and ensures that the client side render doesn't generate
7 | duplicate style definitions in the
20 | AddCount: {count}
21 | Add To Count
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 | [](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 | [](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-antd-mobile/static/hd.min.js:
--------------------------------------------------------------------------------
1 | !function(e){function t(a){if(i[a])return i[a].exports;var n=i[a]={exports:{},id:a,loaded:!1};return e[a].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=window;t["default"]=i.flex=function(e,t){var a=e||100,n=t||1,r=i.document,o=navigator.userAgent,d=o.match(/Android[\S\s]+AppleWebkit\/(\d{3})/i),l=o.match(/U3\/((\d+|\.){5,})/i),c=l&&parseInt(l[1].split(".").join(""),10)>=80,p=navigator.appVersion.match(/(iphone|ipad|ipod)/gi),s=i.devicePixelRatio||1;p||d&&d[1]>534||c||(s=1);var u=1/s,m=r.querySelector('meta[name="viewport"]');m||(m=r.createElement("meta"),m.setAttribute("name","viewport"),r.head.appendChild(m)),m.setAttribute("content","width=device-width,user-scalable=no,initial-scale="+u+",maximum-scale="+u+",minimum-scale="+u),r.documentElement.style.fontSize=a/2*s*n+"px"},e.exports=t["default"]}]);
2 | flex(100, 1);
3 |
--------------------------------------------------------------------------------
/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 | [](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-material-ui-next/README.md:
--------------------------------------------------------------------------------
1 | [](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-material-ui-next)
2 | # Material-UI example
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-material-ui-next
10 | cd with-material-ui-next
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 | [material-ui](https://github.com/callemall/material-ui) is being rewritten from scratch on the [next branch](https://material-ui-1dab0.firebaseapp.com/). This example shows how you use it with Next.js.
29 |
30 |
--------------------------------------------------------------------------------
/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 |
dispatch(counterIncrement)} >Increment
17 |
go to page 2
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 |
24 | ))}
25 |
26 |
27 |
28 |
29 |
30 |
31 | )
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/examples/hello-world/README.md:
--------------------------------------------------------------------------------
1 | [](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/hello-world)
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/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 | This example shows the most basic idea behind Next. We have 2 pages: `pages/index.js` and `pages/about.js`. The former responds to `/` requests and the latter to `/about`. Using `next/link` you can add hyperlinks between them with universal routing capabilities.
30 |
--------------------------------------------------------------------------------
/lib/prefetch.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Link from './link'
3 | import Router from './router'
4 | import { warn, execOnce } from './utils'
5 |
6 | const warnImperativePrefetch = execOnce(() => {
7 | const message = '> You are using deprecated "next/prefetch". It will be removed with Next.js 2.0.\n' +
8 | '> Use "Router.prefetch(href)" instead.'
9 | warn(message)
10 | })
11 |
12 | const wantLinkPrefetch = execOnce(() => {
13 | const message = '> You are using deprecated "next/prefetch". It will be removed with Next.js 2.0.\n' +
14 | '> Use " " instead.'
15 | warn(message)
16 | })
17 |
18 | export function prefetch (href) {
19 | warnImperativePrefetch()
20 | return Router.prefetch(href)
21 | }
22 |
23 | export default class LinkPrefetch extends React.Component {
24 | render () {
25 | wantLinkPrefetch()
26 | const props = {
27 | ...this.props,
28 | prefetch: this.props.prefetch !== false
29 | }
30 |
31 | return ( )
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/examples/parameterized-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('/blog/:id')
11 |
12 | app.prepare()
13 | .then(() => {
14 | createServer((req, res) => {
15 | const { pathname, query } = parse(req.url, true)
16 | const params = match(pathname)
17 | if (params === false) {
18 | handle(req, res)
19 | return
20 | }
21 | // assigning `query` into the params means that we still
22 | // get the query string passed to our application
23 | // i.e. /blog/foo?show-comments=true
24 | app.render(req, res, '/blog', Object.assign(params, query))
25 | })
26 | .listen(3000, (err) => {
27 | if (err) throw err
28 | console.log('> Ready on http://localhost:3000')
29 | })
30 | })
31 |
--------------------------------------------------------------------------------
/examples/svg-components/README.md:
--------------------------------------------------------------------------------
1 | [](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/svg-components)
2 |
3 | # SVG components 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/svg-components
11 | cd svg-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 | This example uses a custom `.babelrc` to add support for importing `.svg` files and rendering them as React components. [babel-plugin-inline-react-svg](https://www.npmjs.com/package/babel-plugin-inline-react-svg) is used to handle transpiling the SVGs.
30 |
--------------------------------------------------------------------------------
/examples/with-external-scoped-css/README.md:
--------------------------------------------------------------------------------
1 | [](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-external-scoped-css)
2 | ## Scoped Style with external CSS file
3 | The motivation for this example is using scoped css from external files and in the end generate a compiled static `.css` file to use in production..
4 |
5 | #### Running That
6 |
7 | ```
8 | yarn install
9 | yarn start
10 | ```
11 |
12 | #### Supported Langs
13 | The plugin supports the `less`, `scss` and `css` file extensions. It is possible to add support for another pre-processor by creating a function to compile the code. In the example we use `sass` as our css pre-processor
14 |
15 | To edit the types you need to go to `.babelrc`
16 |
17 |
18 | #### Attention Points
19 | - Next.js doesn't have support for watching `*.css files. So you will have to edit a Javascript file to re-compile the css. In the future this will be fixed by [#823](https://github.com/zeit/next.js/pull/823).
--------------------------------------------------------------------------------
/examples/with-global-stylesheet/next.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const glob = require('glob')
3 |
4 | module.exports = {
5 | webpack: (config, { dev }) => {
6 | config.module.rules.push(
7 | {
8 | test: /\.(css|scss)/,
9 | loader: 'emit-file-loader',
10 | options: {
11 | name: 'dist/[path][name].[ext]'
12 | }
13 | }
14 | ,
15 | {
16 | test: /\.css$/,
17 | use: ['babel-loader', 'raw-loader', 'postcss-loader']
18 | }
19 | ,
20 | {
21 | test: /\.s(a|c)ss$/,
22 | use: ['babel-loader', 'raw-loader', 'postcss-loader',
23 | { loader: 'sass-loader',
24 | options: {
25 | includePaths: ['styles', 'node_modules']
26 | .map((d) => path.join(__dirname, d))
27 | .map((g) => glob.sync(g))
28 | .reduce((a, c) => a.concat(c), [])
29 | }
30 | }
31 | ]
32 | }
33 | )
34 | return config
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/examples/with-loading/components/Header.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Head from 'next/head'
3 | import Link from 'next/link'
4 | import NProgress from 'nprogress'
5 | import Router from 'next/router'
6 |
7 | Router.onRouteChangeStart = (url) => {
8 | console.log(`Loading: ${url}`)
9 | NProgress.start()
10 | }
11 | Router.onRouteChangeComplete = () => NProgress.done()
12 | Router.onRouteChangeError = () => NProgress.done()
13 |
14 | const linkStyle = {
15 | margin: '0 10px 0 0'
16 | }
17 |
18 | export default () => (
19 |
30 | )
31 |
--------------------------------------------------------------------------------