Commit graph

140 commits

Author SHA1 Message Date
Joe Haddad
8cd21a6368 Server file inclusive Flying Shuttle (#7128)
* Add Flying Shuttle plugin to server compilation

* Ignore build artifacts in flying shuttle manifest

* Add comments explaining what's going on

* Emit Shuttle manifest after both compilations
2019-04-24 11:04:36 +02:00
JJ Kasper
a320dc10f6 Add AMP label to AMP only pages in build tree (#7123) 2019-04-24 10:48:43 +02:00
JJ Kasper
80210bc31a Update removing AMP pages to not require during build (#7081)
* Update to use babel plugin with webpack plugin to
remove AMP client bundles since they are not used

* Remove acorn dependency since it isn't used
2019-04-22 06:25:17 +09:00
JJ Kasper
59b328b5c3 Remove client bundles for AMP only pages (#7034)
* Remove client bundles for AMP pages
after build since they are not used

* Remove trailing white space

* Use async-sema to limit removing AMP client bundles

* Bring AMP client bundle removing
semaphore concurrency down to 20

* Don't check blocked pages when
deleting AMP client bundles

* Update client bundle removing for AMP pages

* Add error handling for removing client AMP pages

* rethrow error unless ENOENT during
deleting AMP client pages

* Handle error during removing AMP client
pages the same during dev

* Fix throwing instead of rejecting

* Make sure next/config is set before requiring page

* Update error check

* return on reject

* Fix next/config
2019-04-16 22:56:34 +09:00
Joe Haddad
74cb4f4b7b
Switch to using .next/cache for flying shuttle and terser (#7013) 2019-04-11 17:09:12 -04:00
JJ Kasper
711d45b698 Use next.config env and packages to calculate hashes (#7001)
* Use next.config env and packages to calculate
hashes for chunk-graph

* Remove example from testing

* remove left over import

* Tweak behavior
2019-04-10 15:19:50 -04:00
Joe Haddad
c2d0a4ef0e
Add Flying Shuttle v1 (#6991)
* Add Flying Shuttle v1

* Add serverless file restoration

* Add another message

* Update test

* Resolve page version last

* Print number of changed pages

* Remove old tests

* Re-add head build ID writing

* Change syntax appearance

* Start adding test components

* Fix react loadable manifest

* Complicate dynamic testing

* Fix first build missing head build id

* Remove flying shuttle tests
2019-04-10 12:41:59 -04:00
Joe Haddad
a44788fb26
Disable flying shuttle when building for now dev (#6998) 2019-04-10 12:37:13 -04:00
Joe Haddad
94b8bf75e2
Move build utils to their own file (#6990)
* Move build utils to their own file

* Tweak feature detection
2019-04-09 23:15:35 -04:00
Joe Haddad
b543071440
Remove CLI and negative page building (#6986)
* Remove CLI and negative page building

* Remove select all tests

* Update test of getSpecifiedPages

* Prune old tests from snapshot

* Remove old flying shuttle tests
2019-04-09 22:57:46 -04:00
Joe Haddad
1810cf5abe
Add an experimental mode for flyingShuttle (#6985) 2019-04-09 22:05:40 -04:00
JJ Kasper
f04bd8bf33 Fix getSpecifiedPages on Windows (#6977)
weren't using the right separator
2019-04-09 15:10:08 -04:00
Joe Haddad
33d32eab5a
Make chunk graph more accurate (#6923)
* Make chunk graph more accurate

* Include shared files in every page
2019-04-06 21:07:32 -04:00
Joe Haddad
a67b6ee117 Fix page resolution (#6920)
Previously this didn't work properly with nested pages.
2019-04-06 20:47:54 +02:00
Joe Haddad
e89c22a3d3
Add a build all but specified pages mode (#6916)
* Add a build all but specified pages mode

* Always include reserved pages in build

* Add tests for ignore pages
2019-04-06 13:11:38 -04:00
Joe Haddad
1603b202e8
Better debug build message (#6915)
* Output a more correct message for debug builds

* Adjust wording
2019-04-05 22:46:35 -04:00
Joe Haddad
cd9a108551
Add ** experimental page globbing support (#6899)
* Add ** page globbing support

* Update check
2019-04-04 20:19:58 -04:00
Joe Haddad
19c635175b
Make Client request BUILD_ID from the Server (#6891)
* Generate two versions of pages

* Add code VSCode deleted

* Add dynamicBuildId option to __NEXT_DATA__

* Reduce amount of diff

* Make getPageFile code easier to read

* Minimize diff

* minimize diff

* Fix default value for dynamicBuildId

* Fix weird bug

* Fetch the head build id on client

* Move __selectivePageBuilding

* Add tests

* Remove _this

* Add console warning
2019-04-04 17:54:01 -04:00
Joe Haddad
ba09c5948e
Set buildId to a fixed value during debug build (#6886)
* Set buildId to a fixed value during debug build

* __debug => debug
2019-04-03 19:43:48 -04:00
Joe Haddad
d653216208
Add an experimental debug mode to builds (#6870)
* Add a debug mode to webpack configuration

* Undo debug change for dist dir
2019-04-02 21:19:08 -04:00
Joe Haddad
a63a493346
Refine selective page building (#6866) 2019-04-02 20:22:04 -04:00
Joe Haddad
b871e43601
Add a leading slash to passed pages (#6808) 2019-03-27 15:21:30 -04:00
Joe Haddad
b835e2589d
Specified page builds (#6796)
* [wip] individual page builds

* Make flag experimental and remove from main bin

* Do not split chunks when using shared runtime
2019-03-27 11:51:05 -04:00
Tim Neutkens
a8d08d3920
ncc nanoid (#6768) 2019-03-24 14:21:30 +01:00
JJ Kasper
11a161f296 Add possible explanation for webpack resolve error (#6682)
When overriding `config.resolve.alias` incorrectly webpack will throw an error because private-next-pages is not defined. This adds a more descriptive error explaining the error better.

Fixes: #6681
2019-03-17 13:13:29 +01:00
Tim Neutkens
557fc95910
Don't use webpack multiCompiler for single configuration (#6598)
When compiling the serverless target there is no need for having an array of configs.
2019-03-10 15:46:50 +01:00
Tim Neutkens
8eb813a640
await config (#6488)
* await config

* update config-promise-error test

* Actually update test
2019-03-01 01:09:07 +01:00
Connor Davis
5514949df0 Remove glob package (#6415)
We don't use a lot of the features of `glob`, so let's remove it in favor of a leaner approach using regex.

It's failing on windows and I have no idea why and don't own a windows machine 🤦🏼‍♂️

(Ignore some of the commits in here, I forgot to create the new branch before I started working)
2019-02-24 22:08:35 +01:00
Connor Davis
61de215e04
Move webpack config to TypeScript (#6348) 2019-02-20 13:24:02 -06:00
wtgtybhertgeghgtwtg
ddd01df4ec Make getBaseWebpackConfig synchronous. (#6356)
Currently, `getBaseWebpackConfig` is marked async, but it doesn't await anything or otherwise return a Promise.  Please correct me if I am wrong, but it looks like it can be made synchronous.
2019-02-20 00:05:46 +01:00
Joe Haddad
7078f6567d Make build output friendlier (#6320)
Success:
![image](https://user-images.githubusercontent.com/616428/52907314-5e636480-322d-11e9-9420-b348663a3a7a.png)

Error:
![image](https://user-images.githubusercontent.com/616428/52907318-6c18ea00-322d-11e9-848d-e615d6af747d.png)

Warnings:
![image](https://user-images.githubusercontent.com/616428/52907353-2d376400-322e-11e9-9778-370f36912491.png)

---

We can still make build error output friendlier, but this is a good start.
2019-02-17 12:56:48 +01:00
Connor Davis
6f162b94e1 Add Error when using publicRuntimeConfig with target serverless and add buildVars (#6212)
Introduce env to next.config.js for build-time configuration
2019-02-08 14:38:18 +01:00
Tim Neutkens
b4ade0a3cd Revert "Move phases back to next/constants (#6104)"
This reverts commit 9112f63eba.
2019-01-26 02:01:49 +01:00
Luc
14604450cb Print list of pages when building (#6125)
* show pages created when building

* fix types
2019-01-25 18:36:29 +01:00
Tim Neutkens
9112f63eba
Move phases back to next/constants (#6104)
* Move phases back to next/constants

* Fix typescript error
2019-01-23 14:10:12 +01:00
Tim Neutkens
b547d300d9
Show clear error when client build fails in serverless target (#6027) 2019-01-10 22:10:50 +01:00
Tim Neutkens
9ffd23eeef
Replace pages-plugin with loader (#5994)
* Remove unused argument

* Replace pages-plugin with loader

* Add loader-utils types

* Remove logs

* Bring back previous deposal behavior

* Remove console.log

* Remove webpack/utils as it’s no longer in use

* Remove hot-self-accept-loader

* Error Recovery tests

* Make hotSelfAccept a noop default loader

* Fix windows deleted/added

* Remove logging

* Remove unused variables

* Remove log

* Simplify entrypoint generation

* Don’t return the function

* Fix _app test

* Remove code that’s always true

* Move aliases to constants

* Use alias

* Join pages alias in reduce

* Default pages differently

* Loop over pages instead of manually defining

* Move entry generation into common function

* Update packages/next/build/webpack/loaders/next-client-pages-loader.ts

Co-Authored-By: timneutkens <tim@timneutkens.nl>

* Update packages/next/build/webpack/loaders/next-client-pages-loader.ts
2019-01-08 23:10:32 +01:00
Tim Neutkens
0f23faf81f
Serverless Next.js (#5927)
**This does not change existing behavior.**

building to serverless is completely opt-in.

- Implements `target: 'serverless'` in `next.config.js`
- Removes `next build --lambdas` (was only available on next@canary so far)

This implements the concept of build targets. Currently there will be 2 build targets:

- server (This is the target that already existed / the default, no changes here)
- serverless (New target aimed at compiling pages to serverless handlers)

The serverless target will output a single file per `page` in the `pages` directory:

- `pages/index.js` => `.next/serverless/index.js`
- `pages/about.js` => `.next/serverless/about.js`

So what is inside `.next/serverless/about.js`? All the code needed to render that specific page. It has the Node.js `http.Server` request handler function signature:

```ts
(req: http.IncomingMessage, res: http.ServerResponse) => void
```

So how do you use it? Generally you **don't** want to use the below example, but for illustration purposes it's shown how the handler is called using a plain `http.Server`:

```js
const http = require('http')
// Note that `.default` is needed because the exported module is an esmodule
const handler = require('./.next/serverless/about.js').default
const server = new http.Server((req, res) => handler(req, res))
server.listen(3000, () => console.log('Listening on http://localhost:3000'))
```

Generally you'll upload this handler function to an external service like [Now v2](https://zeit.co/now-2), the `@now/next` builder will be updated to reflect these changes. This means that it'll be no longer neccesary for `@now/next` to do some of the guesswork in creating smaller handler functions. As Next.js will output the smallest possible serverless handler function automatically.

The function has 0 dependencies so no node_modules are required to run it, and is generally very small. 45Kb zipped is the baseline, but I'm sure we can make it even smaller in the future.

One important thing to note is that the function won't try to load `next.config.js`, so `publicRuntimeConfig` / `serverRuntimeConfig` are not supported. Reasons are outlined here: #5846

So to summarize:

- every page becomes a serverless function
- the serverless function has 0 dependencies (they're all inlined)
- "just" uses the `req` and `res` coming from Node.js
- opt-in using `target: 'serverless'` in `next.config.js`
- Does not load next.config.js when executing the function

TODO:

- [x] Compile next/dynamic / `import()` into the function file, so that no extra files have to be uploaded.
- [x] Setting `assetPrefix` at build time for serverless target
- [x] Support custom /_app
- [x] Support custom /_document
- [x] Support custom /_error
- [x] Add `next.config.js` property for `target`

Need discussion:
- [ ] Since the serverless target won't support `publicRuntimeConfig` / `serverRuntimeConfig` as they're runtime values. I think we should support build-time env var replacement with webpack.DefinePlugin or similar.
- [ ] Serving static files with the correct cache-control, as there is no static file serving in the serverless target
2018-12-28 11:39:12 +01:00
Tim Neutkens
5708e99eca
Run compilers sequentially when in lambdas mode (#5862) 2018-12-11 21:46:23 +01:00
Tim Neutkens
58f5dd297a
Add Typescript types for builds functions (#5791) 2018-12-03 14:18:52 +01:00