Skip to content

Commit

Permalink
Merge branch 'canary' into polyfill-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer authored Oct 30, 2019
2 parents d9a6414 + d3293f7 commit c1e6544
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 94 deletions.
15 changes: 0 additions & 15 deletions examples/with-next-sass/pages/_document.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/with-static-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ yarn dev

## The idea behind the example

This example show how to export to static HTML files your Next.js application fetching data from an API to generate a dynamic list of pages. This use a custom Express server in development to configure custom routing and then generate a map of pages to export for production.
This example show how to export to static HTML files your Next.js application fetching data from an API to generate a dynamic list of pages.

When trying to run `npm start` it will build and export your pages into the `out` folder and serve them on `localhost:5000`.
12 changes: 4 additions & 8 deletions examples/with-static-export/components/post.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import Link from 'next/link'

export default props => (
export default ({ title, body, id }) => (
<article>
<h2>{props.title}</h2>
<p>{props.body}</p>
{/* render the URL as /post/:id */}
<Link
href={{ pathname: '/post', query: { id: props.id } }}
as={`/post/${props.id}`}
>
<h2>{title}</h2>
<p>{body}</p>
<Link href='/post/[id]' as={`/post/${id}`}>
<a>Read more...</a>
</Link>
</article>
Expand Down
5 changes: 1 addition & 4 deletions examples/with-static-export/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ module.exports = {
const pages = postList.reduce(
(pages, post) =>
Object.assign({}, pages, {
[`/post/${post.id}`]: {
page: '/post',
query: { id: post.id }
}
[`/post/${post.id}`]: { page: '/post/[id]' }
}),
{}
)
Expand Down
12 changes: 5 additions & 7 deletions examples/with-static-export/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"name": "with-static-export",
"main": "server.js",
"dependencies": {
"express": "^4.15.3",
"isomorphic-unfetch": "^2.0.0",
"isomorphic-unfetch": "^3.0.0",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"serve": "9.4.0"
"react": "^16.11.0",
"react-dom": "^16.11.0",
"serve": "11.2.0"
},
"scripts": {
"dev": "node .",
"dev": "next",
"build": "next build",
"preexport": "npm run build",
"export": "next export",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export default class extends Component {
}

render () {
const { title, body } = this.props

return (
<main>
<Head>
<title>{this.props.title}</title>
<title>{title}</title>
</Head>

<h1>{this.props.title}</h1>
<h1>{title}</h1>

<p>{this.props.body}</p>
<p>{body}</p>

<Link href='/'>
<a>Go back to home</a>
Expand Down
27 changes: 0 additions & 27 deletions examples/with-static-export/server.js

This file was deleted.

2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.1.2-canary.9"
"version": "9.1.2"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "9.1.2-canary.9",
"version": "9.1.2",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "9.1.2-canary.9",
"version": "9.1.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "9.1.2-canary.9",
"version": "9.1.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
20 changes: 20 additions & 0 deletions packages/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,26 @@ To learn more about TypeScript checkout its [documentation](https://www.typescri
> module.exports = {
> typescript: {
> ignoreDevErrors: true,
> },
> }
> ```
>
> Next.js will still fail your **production build** (`next build`) when TypeScript errors are present in your project.
>
> If you'd like Next.js to dangerously produce production code even when your application is broken, you can set the following option in your `next.config.js`.
> Be sure you are running type checks as part of your build or deploy process!
>
> ```js
> // next.config.js
> module.exports = {
> typescript: {
> // !! WARN !!
> // Dangerously allow production builds to successfully complete even if
> // your project has type errors.
> //
> // This option is rarely needed, and should be reserved for advanced
> // setups. You may be looking for `ignoreDevErrors` instead.
> // !! WARN !!
> ignoreBuildErrors: true,
> },
> }
Expand Down
4 changes: 1 addition & 3 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,11 @@ export default async function getBaseWebpackConfig(
},
},
prodGranular: {
chunks: 'initial',
chunks: 'all',
cacheGroups: {
default: false,
vendors: false,
framework: {
// Framework chunk applies to modules in dynamic chunks, unlike shared chunks
// TODO(atcastle): Analyze if other cache groups should be set to 'all' as well
chunks: 'all',
name: 'framework',
// This regex ignores nested copies of framework libraries so they're
Expand Down
31 changes: 13 additions & 18 deletions packages/next/build/webpack/plugins/build-manifest-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,24 @@ export default class BuildManifestPlugin {
}

const filesForEntry: string[] = []
for (const chunk of entrypoint.chunks) {
// If there's no name or no files
if (!chunk.name || !chunk.files) {

// getFiles() - helper function to read the files for an entrypoint from stats object
for (const file of entrypoint.getFiles()) {
if (/\.map$/.test(file) || /\.hot-update\.js$/.test(file)) {
continue
}

for (const file of chunk.files) {
if (/\.map$/.test(file) || /\.hot-update\.js$/.test(file)) {
continue
}

// Only `.js` and `.css` files are added for now. In the future we can also handle other file types.
if (!/\.js$/.test(file) && !/\.css$/.test(file)) {
continue
}

// The page bundles are manually added to _document.js as they need extra properties
if (IS_BUNDLED_PAGE_REGEX.exec(file)) {
continue
}
// Only `.js` and `.css` files are added for now. In the future we can also handle other file types.
if (!/\.js$/.test(file) && !/\.css$/.test(file)) {
continue
}

filesForEntry.push(file.replace(/\\/g, '/'))
// The page bundles are manually added to _document.js as they need extra properties
if (IS_BUNDLED_PAGE_REGEX.exec(file)) {
continue
}

filesForEntry.push(file.replace(/\\/g, '/'))
}

assetMap.pages[`/${pagePath.replace(/\\/g, '/')}`] = [
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.1.2-canary.9",
"version": "9.1.2",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down
11 changes: 10 additions & 1 deletion test/integration/chunking/pages/page2.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import * as _ from 'lodash'
import { useState, useEffect } from 'react'
import _ from 'lodash'
import dynamic from 'next/dynamic'
import Link from 'next/link'

const One = dynamic(() => import('../components/one'))

const Page = () => {
const [str, setStr] = useState('rad')
useEffect(() => {
setStr(_.pad(str, 7, '_'))
}, [])

console.log(_)
return (
<div>
page2
<p id='padded-str'>{str}</p>
<One />
<Link href='/page3'>Page3</Link>
</div>
)
}
Expand Down
13 changes: 13 additions & 0 deletions test/integration/chunking/pages/page3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Link from 'next/link'
import('lodash').then(_ => console.log(_.chunk(['a', 'b', 'c', 'd'], 2)))

const Page = () => {
return (
<div>
<h2>Page3</h2>
<Link href='/page2'>Page2</Link>
</div>
)
}

export default Page
31 changes: 29 additions & 2 deletions test/integration/chunking/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import { nextBuild } from 'next-test-utils'
import {
nextBuild,
findPort,
waitFor,
nextStart,
killApp
} from 'next-test-utils'
import { readdir, readFile, unlink, access } from 'fs-extra'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1

Expand All @@ -30,7 +37,12 @@ describe('Chunking', () => {
} catch (e) {
// Error here means old chunks don't exist, so we don't need to do anything
}
await nextBuild(appDir)
const { stdout, stderr } = await nextBuild(appDir, [], {
stdout: true,
stderr: true
})
console.log(stdout)
console.error(stderr)
stats = (await readFile(join(appDir, '.next', 'stats.json'), 'utf8'))
// fixes backslashes in keyNames not being escaped on windows
.replace(/"static\\(.*?":)/g, '"static\\\\$1')
Expand Down Expand Up @@ -95,4 +107,19 @@ describe('Chunking', () => {
})
expect(misplacedReactDom).toBe(false)
})

it('should hydrate with granularChunks config', async () => {
const appPort = await findPort()
const app = await nextStart(appDir, appPort)

const browser = await webdriver(appPort, '/page2')
await waitFor(1000)
const text = await browser.elementByCss('#padded-str').text()

expect(text).toBe('__rad__')

await browser.close()

await killApp(app)
})
})

0 comments on commit c1e6544

Please sign in to comment.