Commit graph

165 commits

Author SHA1 Message Date
Tim Neutkens
1016b71011
Don’t prefetch on slow network / when datasaver is enabled (#5876)
Inspired by https://twitter.com/addyosmani/status/1073118564423356416

I've made the checking function slightly smaller (including both conditions on one line makes Terser optimize the condition).

cc @addyosmani
2018-12-13 19:08:23 +01:00
Tim Neutkens
620b426903
Remove baseurl/paths option (#5878)
For some reason the canary branch is failing on Typescript while the PR was not.
2018-12-13 16:56:48 +01:00
Connor Davis
419bec0b9b Fix #5674 Append crossOrigin on the client side too, add config option for crossOrigin (#5873)
# Fixes https://github.com/zeit/next.js/issues/5674

This adds config option
```js
// next.config.js
module.exports = {
  crossOrigin: 'anonymous'
}
```
This config option is defined in the webpack Define Plugin at build.
`Head` and `NextScript` now use the config option, if it's not explicitly set on the element.
This value is now passed to Webpack so it can add it to scripts that it loads.
The value is now used in `PageLoader` (on the client) so it can add it to the scripts and links that it loads.
Using `<Head crossOrigin>` or `<NextScript crossOrigin>` is now deprecated.
2018-12-13 01:05:21 +01:00
Tim Neutkens
5e3bf6e537
Convert render.js to typescript (#5869)
* Convert render.js to typescript

* Compile tsx files too

* Remove internal renderErrorToHTML function

* Interopt component result

* requirePage doesn’t need async

* Move out enhancing logic into it’s own function

* Remove buildManifest from renderPage

* Move render into it’s own function

* Change let to const

* Move renderDocument into it’s own function
2018-12-13 01:00:46 +01:00
Benjamin Kniffler
e6c3686629 multi-threaded export with nice progress indication (#5870)
This PR will

- allow nextjs export to use all available CPU cores for rendering & writing pages by using child_process
- make use of async-sema to allow each thread to concurrently write multiple paths
- show a fancy progress bar while processing pages (with non-TTY fallback for CI web consoles)

The performance gain for my MacBook with 4 CPU cores went from ~25 pages per second to ~75 pages per second. Beefy CI machines with lots of cores should profit even more.
2018-12-12 13:59:11 +01:00
Tim Neutkens
2dec1fcd63 v7.0.2-canary.42 2018-12-11 21:59:30 +01:00
Tim Neutkens
5708e99eca
Run compilers sequentially when in lambdas mode (#5862) 2018-12-11 21:46:23 +01:00
Tim Neutkens
1c8b09d7ea
Make <Head> children render first, then next/head children, then script preloads/styles (#5852) 2018-12-10 23:40:42 +01:00
Tim Neutkens
93424b64a9
Use correct default for query (#5851) 2018-12-10 23:40:26 +01:00
Kenneth Luján Rosas
616c3d7ac8 docs(readme): add documentation for renderPage customization on _document.js (#5723)
Per @timneutkens suggestion [here](https://github.com/zeit/next.js/pull/5631#issuecomment-440588455) I went ahead and gave a shot at trying to document `renderPage` usage.

This PR:
- Documents `renderPage` legacy and current usage.
2018-12-10 17:01:59 +01:00
Oscar Busk
27c0b199d0 Fix paths when built on windows (#5795)
This PR Fixes #4920

So the problem is that when a next.js application is built on windows, the `pages-manifest.json` file is created with backslashes. If this built application is deployed to a linux hosting enviroment, the server will fail when trying to load the modules.

```
Error: Cannot find module '/user_code/next/server/bundles\pages\index.js
```

My simple solution is to modify the `pages-manifest.json` to always use linux separator (`/`), then also
modify `server/require.js` to, when requiring page, replace any separator (`\` or `/`) with current platform-specific file separator (`require('path').sep`).

The fix in `server/require.js` would be sufficient, but my opinion is that having some cross-platform consistency is nice.

This change was tested by bulding an application in windows and running it in linux and windows, aswell as building an application in linux and running it in linux and windows. The related tests was also run.
# Conflicts:
#	test/integration/production/test/index.test.js
2018-12-10 14:48:06 +01:00
Tim Neutkens
8b6173917a
Convert next-server.js to typescript (#5844) 2018-12-09 22:46:45 +01:00
Tim Neutkens
61894816ba
Remove app variable as it’s only used once (#5842)
* Remove app variable as it’s only used once

* Remove double spread
2018-12-08 13:14:44 +01:00
Tim Neutkens
0e6d190706
Move sendHTML and rewrite in ts (#5839)
* Move send-html function and rewrite in typescript

* Move getPageFiles and convert to ts

* Move getPageFiles and convert to ts (#5841)

* Move getPageFiles and convert to ts

# Conflicts:
#	packages/next-server/server/render.js

* Fix unit tests
2018-12-07 15:52:29 +01:00
Tim Neutkens
8873242b0b
Move getPageFiles and convert to ts (#5841)
* Move getPageFiles and convert to ts

# Conflicts:
#	packages/next-server/server/render.js

* Fix unit tests
2018-12-07 13:35:01 +01:00
Tim Neutkens
8ca5749ff9
Remove unused properties (#5837) 2018-12-07 00:57:39 +01:00
Tim Neutkens
ffe1a12f2e
Move getDynamicImportBundles into own ts file (#5836) 2018-12-06 22:34:53 +01:00
Tim Neutkens
3c62b07593
Move serve-static to typescript (#5833) 2018-12-06 16:54:33 +01:00
Tim Neutkens
5d2250ac27
Remove unused functions (#5832)
Couldn't find a reference to these functions as next-server uses the renderToHTML directly.
2018-12-06 16:47:10 +01:00
Tim Neutkens
261eb16308
Only check if BUILD_ID exists when reading throws error (#5834)
We don't have to check if the file already exists here, since it's always in production mode (dev overrides the readBuildId method to always be `development`) If the file is not found (error is thrown) we check if the file exists. If not we throw a helpful error. In other cases we throw the original error.
2018-12-06 16:46:53 +01:00
Tim Neutkens
902c5244f3 v7.0.2-canary.41 2018-12-05 22:41:26 +01:00
Tim Neutkens
6729fa4580 Mark react/react-dom as external when in lambdas mode (#5828) 2018-12-05 13:40:17 -08:00
Tim Neutkens
dd556bf90b
Add tsc type checking (#5826)
* Add tsc type checking

* Add linting on circle

* Add node-fetch types

* Use strict mode
2018-12-05 21:45:50 +01:00
Tim Neutkens
7098501547 v7.0.2-canary.40 2018-12-05 15:05:59 +01:00
Tim Neutkens
1a5fc941ce Remove console.log after verifying the correct files are ignored 2018-12-05 15:05:14 +01:00
Tim Neutkens
a62a6276c7 v7.0.2-canary.39 2018-12-05 14:45:14 +01:00
Tim Neutkens
6542750e12
Fix edge case where file had module.export in the content (#5823)
We ran into this eg on hyper-site, which has `module.exports` in the content.
2018-12-05 14:37:26 +01:00
Tim Neutkens
84223d39e7 v7.0.2-canary.38 2018-12-04 20:10:53 +01:00
Tim Neutkens
2d5b56a181 Disable usage of esmodules when commonjs is enabled on the preset 2018-12-04 20:10:22 +01:00
Tim Neutkens
29ed67b020
Add test for generateBuildId (#5816)
* Add docs for returning `null` from generateBuildId

* Add test for setting custom buildid

* Fix linting
2018-12-04 16:42:25 +01:00
Tim Neutkens
dada692bd6 v7.0.2-canary.37 2018-12-04 15:28:36 +01:00
Tim Neutkens
bd2ad412d3
Bring back module.exports because of backwards compat (#5815) 2018-12-04 15:26:20 +01:00
Tim Neutkens
dd3b5bf81d v7.0.2-canary.36 2018-12-04 11:04:21 +01:00
Tim Neutkens
d11a3aa34e
Add tests for isomorphic-unfetch bundling issue (#5805)
* Add tests for isomorphic-unfetch bundling issue

* Remove unneeded extra option

* Remove isomorphic-fetch
2018-12-04 10:59:12 +01:00
Matheus Fernandes
977bf8d9eb Zeit -> ZEIT (#5804) 2018-12-03 23:01:23 +01:00
Tim Neutkens
082db2877d v7.0.2-canary.35 2018-12-03 19:50:59 +01:00
Tim Neutkens
f79230db33
Change module resolution extensions (#5801)
Same as https://github.com/zeit/ncc/pull/80
2018-12-03 19:36:24 +01:00
Tim Neutkens
9890e06907
Dedupe only items with unique key (#5800)
Fixes #3705
Fixes #4656

- No longer automatically dedupe certain tags. Only the ones we know are *never* going to be duplicate like charSet, title etc.
- Fix `key=""` behavior, making sure that if a unique key is provided tags are deduped based on that.

For example:

```jsx
<meta property='fb:pages' content='one'>
<meta property='fb:pages' content='two'>
```

Would currently cause

```jsx
<meta property='fb:pages' content='two'>
```

### After this change:

```jsx
<meta property='fb:pages' content='one'>
<meta property='fb:pages' content='two'>
```

Then if you use next/head multiple times / want to be able to override:

```jsx
<meta property='fb:pages' content='one' key="not-unique-key">
<meta property='fb:pages' content='two' key="not-unique-key">
```

Would cause:

```jsx
<meta property='fb:pages' content='two'>
```

As `key` gets deduped correctly after this PR, similar to how React itself works.
2018-12-03 17:28:42 +01:00
Tim Neutkens
58f5dd297a
Add Typescript types for builds functions (#5791) 2018-12-03 14:18:52 +01:00
Tim Neutkens
a9cf735f50
Convert babel plugins to typescript (#5789)
Slowly moving files over 💯
2018-12-02 18:30:00 +01:00
Luc
e43d21fdf0 remove occurence of deprecated url prop in readme (#5786) 2018-12-01 21:11:06 +01:00
Tim Neutkens
a66e1c0d7c v7.0.2-canary.34 2018-11-30 19:51:54 +01:00
Tim Neutkens
e5002234d0
Transpile imports if module has module.exports (#5780)
Fixes #5778
Fixes #3650
2018-11-30 17:56:07 +01:00
Tim Neutkens
633dd87b18
Handle 404 thrown from send (#5779) 2018-11-30 17:09:23 +01:00
Tim Neutkens
4322bb13dd
Build / watch .ts core files (#5776) 2018-11-30 13:10:30 +01:00
Tim Neutkens
f1fe237ba8 v7.0.2-canary.33 2018-11-29 19:33:20 +01:00
Tim Neutkens
1c64e59564 v7.0.2-canary.32 2018-11-29 12:36:48 +01:00
Tim Neutkens
55e89e759a
Fix polyfill for ie11 (#5763)
* Fix polyfill for ie11

* Use esmodules only when using webpack
2018-11-29 12:36:03 +01:00
Tim Neutkens
c1037949fd v7.0.2-canary.31 2018-11-28 17:55:37 +01:00
Tim Neutkens
fb92fdef54
Make sure const/async is transpiled (#5760)
* Make sure const/async is transpiled

* Use babel common compilation instead
2018-11-28 17:53:49 +01:00