Commit graph

1550 commits

Author SHA1 Message Date
JJ Kasper
aac50e4501
Add error message for AMP bind syntax (#6865)
* Add error message for AMP bind syntax

* Fix custom AMP scripts getting dropped

* Add data.js to package.json to include it
in releases
2019-04-02 17:32:07 -05:00
Joe Haddad
4201fb957d
Emit manifest of all page files (#6853)
* Get all modules included in build

* Add tests

* Get all modules contained per entry chunk

* Sort files

* Add specialized page entry to manifest

* Split manifest into pages and chunks key

* Update test

* Use relative paths to build directory

* Update test
2019-04-02 15:48:05 -04:00
JJ Kasper
6344c5f0c1
Add optimizing AMP pages (#6835)
* Added amp-toolbox-optimizer and added
optimizing AMP pages as dirty and clean

* Fix amp-optimizer breaking serverless build

* Exclude amp-toolbox-optimizer from serverless build

* Added check to make sure hybrid AMP pages
optimize cleanly during export

* Add check to make sure noDirtyAmp is applied
2019-04-02 13:01:34 -05:00
Tim Neutkens
b1fdffec75
amp-bind data injection (#6840) 2019-04-02 16:09:34 +02:00
Dylan Brookes
035890f9cd Fix adblock comment (#6859) 2019-04-02 04:37:04 -04:00
Shahzeb K
25deefbba7 Avoid "ad" anywhere in the buildId (#6854)
* Added a check for ad_ in the buildId

* ad_ > ad

Co-Authored-By: lfades <luis@zeit.co>

* Update the `ad` comment

Co-Authored-By: lfades <luis@zeit.co>

* Avoid all buildId's that contain "ad"

Looking through the uBlock Origin filter list, it uses regex wildcards to avoid various things with "ad" anywhere in the string. It's a safe bet to just avoid "ad" all together (as opposed to just at the start).

* Use regex (case incensitive) to check for "ad" 

The following cases will set this regex to true:

```
/ad/i.test("somead")
/ad/i.test("someADlksdjf")
/ad/i.test("adlksdjf")
/ad/i.test("ADlksdjf")
```
2019-04-01 20:40:43 -04:00
Luis Fernando Alvarez D
742f29fba5 buildId is not an ad (#6851)
* Added a check for ad_ in the buildId

* ad_ > ad

Co-Authored-By: lfades <luis@zeit.co>

* Update the `ad` comment

Co-Authored-By: lfades <luis@zeit.co>
2019-04-01 15:22:21 -04:00
Luis Fernando Alvarez D
c864ab9324 Added useBuiltIns to babel object-rest-spread (#6805)
Use `Object.assign` for the rest-spread transform.
2019-03-31 17:30:25 +02:00
Luis Fernando Alvarez D
6bb83272a3 Exclude transform-typeof-symbol (#6812)
Related to [create-react-app#5278](https://github.com/facebook/create-react-app/pull/5278#issue-220142150)
2019-03-30 01:54:05 +01:00
Luis Fernando Alvarez D
f81e5f4cad Added babel-plugin-dynamic-import-node (#6811)
Replaces `import()` with `require` only for the testing environment.
2019-03-30 01:50:24 +01: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
Luis Fernando Alvarez D
da9472246c Remove prop-types import in the build (#6798)
Tests don't catch this change because `isProduction &&` is always false so I tested it with a local build
2019-03-27 12:26:01 +01:00
JJ Kasper
244b0e700e
Add AMP validation on export (#6794)
* Add err.sh link and pool validation results
to wait to show error until export is finished

* Fix wording in amp-export-validation err.sh

* Update validation error message

Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>

* Update ways to fix text

Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>

* Update why the error occurred wording

Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>

* Update wording some more

Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
2019-03-26 16:21:27 -05:00
Joe Haddad
0249b331c2
Use a shared module cache (#6791)
* [WIP] Use a shared module cache

* ID modules in development

* Revert "ID modules in development"

This reverts commit 0613d92fa2c8c7fa11a5ff5b7770d784af1cec63.

* Remove context replacement

* Only enable shared runtime in prod

* Sort settings

* Add shared runtime experimental setting

* only enable shared runtime in serverless
2019-03-26 12:30:31 -04:00
Joe Haddad
8c175e5daa Replace buildId well known string during output (#6782)
* Replace buildId well known string during output

* Fix linting
2019-03-25 17:06:00 +01:00
Tim Neutkens
907dd27a88
Make main.js override work correctly (#6781) 2019-03-25 15:08:02 +01:00
Connor Davis
a79c004de0 Remove magic-string (#6772)
* Remove magic-string

* Add back input

* change if statement back

* Fix typo

* remomve useless import
2019-03-24 23:50:58 -04:00
Tim Neutkens
3e7b932b2b
ncc resolve and arg (#6771)
More modules to follow.
2019-03-24 23:38:03 +01:00
Tim Neutkens
f639becf88
Don't use array for main chunk (#6767)
* Simplify getDisplayName

* Don’t use array for single file

* Add aliases, drop htmlescape as it’s not longer in the codebase

* Add correct path

* Use the correct router

* Remove dynamic for now

* Mark as external as the modules are directly called

* Add comment explaining what this does
2019-03-24 14:33:10 +01:00
Tim Neutkens
a8d08d3920
ncc nanoid (#6768) 2019-03-24 14:21:30 +01:00
Tim Neutkens
eb28d4cdcf
Remove hoist-non-react-statics from with-router (#6765)
* Remove hoist-non-react-statics from with-router

* Drop hoist-non-react-statics from package.json
2019-03-23 21:31:44 +01:00
Tim Neutkens
6716bcbf87
Remove error-debug.js checks as the chunk is removed (#6761)
This code is obsolete as the chunk was removed.
2019-03-23 16:55:44 +01:00
Tim Neutkens
d24af62140
Make pages-manifest-plugin compatible with webpack 5 (#6760)
Apparently `entries` is removed in webpack 5, using `chunks` instead which holds the same result.
2019-03-23 15:33:13 +01:00
Joe Haddad
78bcfa07b2 Skip console clearing when not in a TTY (#6726) 2019-03-19 23:16:02 +01:00
Joe Haddad
ff5c8465de
First pass of runtime amp validator (#6708) 2019-03-18 19:21:18 -04:00
Tim Neutkens
6104a71afb Make react-loadable-manifest only have modules that are part of dynamic chunks (#6622)
* Make react-loadable-manifest only have modules that are part of dynamic chunks

* Add manifest sorting
2019-03-17 14:19:26 -04: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
JJ Kasper
a6ddaefe22 Add experimental exportTrailingSlash config (#6664)
By default when `next export`ing a Next.js application we will automatically append a `/` to all urls to be fully compatible with the directory structure being output.

However since most platforms support directory indexes it makes sense to change this default in the future.

This PR adds `exportTrailingSlash` as experimental flag. We'll try this out for a bit on nextjs.org / zeit.co/docs before introducing it as new option.

The default value is `true` as this is the current behavior in stable Next.js.

```
{
  experimental: {
    exportTrailingSlash: false
  }
}
```

⚠️ as with all experimental flags being added this is subject to breaking between canary/stable versions.
2019-03-17 00:54:58 +01:00
JJ Kasper
c81bd27587 Fix relative next path not working in webpack config (#6667)
* Fix relative next path not working in
webpack config

* Also add relative fix to amp path
2019-03-15 00:09:00 -04:00
Joe Haddad
d7ab018f31
Hash module IDs to save on bundle size (#6660) 2019-03-15 00:08:22 -04:00
Joe Haddad
0ae34c9a9d
Use relative instead of absolute for entry paths (#6659) 2019-03-14 21:45:50 -04:00
Joe Haddad
6902afbd3f
Stabilize Chunk ID generation (#6663)
* Add a new field to webpack types

* Revert "Add a new field to webpack types"

This reverts commit d35fa02207fbfd0085da0fc56aac42c4ff7c34c9.

* Add HashedChunkIdsPlugin to make consistent chunk ids

* Revert "Revert "Add a new field to webpack types""

This reverts commit 338219049e1432038f90c91928b010bbb1267999.

* Make it optional

* Remove record ids

* Revert "Remove record ids"

This reverts commit 15c22dbcda72466c382397c91d02295620f62326.
2019-03-14 21:38:57 -04:00
Connor Davis
b73abc0a4b Delete using realpath in HMR cache (#6635)
This will allow symlinked assets to be removed from the cache as well

Fixes: #5620
2019-03-15 00:22:57 +01:00
Joe Haddad
1fb1b75216
Ensure all modules are identified (#6656)
* Ensure all modules are identified

* Extend a webpack Plugin

Co-Authored-By: Timer <timer150@gmail.com>
2019-03-14 11:04:08 -04:00
Joe Haddad
e5636dcdb0
Inject the build ID after webpack runs (#6618)
* Inject the build ID after webpack runs

* add webpack sources types

* use webpack plugin instead

* reset file

* Skip source maps if none were provided

Co-Authored-By: Timer <timer150@gmail.com>
2019-03-12 16:39:44 -04:00
Tim Neutkens
8cf6ef58f0
Remove unused dev option from babel-loader (#6624) 2019-03-12 15:19:08 +01:00
Joe Haddad
2e32aa8630
Ensure correct key order (#6616)
* Ensure correct key order

* Fix bug

* Format this document while we're at it
2019-03-12 00:01:50 -04:00
JJ Kasper
179d09e8e0
Remove cacheKeys in favor of simply a cacheKey (#6613) 2019-03-11 22:32:26 -05:00
Joe Haddad
f6b7503e55
Sort pages between bundles (#6612) 2019-03-11 17:34:41 -04:00
JJ Kasper
995460d7dd
Replace md4 hashing with murmurhash (#6611) 2019-03-11 16:23:04 -05:00
JJ Kasper
eb0e83cea3 Remove cacache (#6610) 2019-03-11 16:24:07 -04:00
Tim Neutkens
b32e65a830 Add experimental profiling flag (#6594)
* Add experimental profiling flag

* Update config.js
2019-03-11 13:53:24 -04:00
JJ Kasper
852a62bf56 Add experimental cpus config and use CircleCI env var (#6604)
* Add using CircleCI env var for max workers
and expose webpack to config

* Expose experimental cpu config

* Fix typo

* Remove log
2019-03-11 17:33:30 +01:00
Joe Haddad
041be6f4aa Disable webpack minifier (#6603)
When the webpack `mode` is set to `production`, `minimizer: undefined` means "use the default webpack minifier."

We need to explicitly disable the webpack minifier via `minimize: false`. This should speed up non-serverless builds. 😄 

This doesn't affect dev, but I added the toggle there for consistency.
2019-03-11 15:51:23 +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
8ffcb3f3e7 Don’t load dev plugins for production bootup (#6589)
* Don’t load autodll-webpack-plugin for production bootup

* Only require autodll when client-side compilation is ran

* Try to fix build
2019-03-09 23:27:33 -05:00
Tim Neutkens
e8095c0e2e Remove cjs file (#6590) 2019-03-09 22:34:27 -05:00
Tim Neutkens
dd60199cec
Remove case-sensitive-paths-plugin (#6587)
While this is a nice feature it does filesystem operations to check if the resolved file matches the filesystem.
2019-03-10 01:44:51 +01:00
Connor Davis
f8be040c79 Next minifier cache (#6582)
Changes the name of the cache folder so we can predictably cache on Now
2019-03-09 09:09:44 +01:00
Tim Neutkens
d3e92cceec
Remove more terser-webpack-plugin code (#6575) 2019-03-08 16:26:20 +01:00
Tim Neutkens
3f9a44996a
Remove more terser code (#6564)
* Remove chunkfilter and extractcomments options as they’re unused

* Remove unused variable

* Remove cacheKeys option, improve filter

* Remove more terser code

* Remove unused variable
2019-03-07 19:45:49 +01:00
k-kawakami
d9060f5abd Remove trailing spaces (#6547)
### changes
#### remove trailing spaces

When I was using example I noticed trailing spaces.
So, this PR removes the trailing spaces of json file, README, and others.

`examples/with-jest-typescript/src/modules/cars/Overview.tsx` also has it, but this time it did not change as tslint error occurs at commit.
2019-03-07 17:40:08 +01:00
Tim Neutkens
9b62f208bb
Remove cacheKeys option and improve filtering (#6559)
More cleanup of terser-plugin.
2019-03-07 14:28:32 +01:00
Tim Neutkens
abad29b413
Remove chunkfilter and extractcomments options as they’re unused (#6549)
Remove some obsolete code paths.
2019-03-06 21:28:42 +01:00
Tim Neutkens
0088083f52
Check if esmodules is supported before enabling useESModules (#6534)
* Check if esmodules is supported before enabling useESModules

* Remove console.log
2019-03-05 16:57:07 +01:00
JJ Kasper
c3b1f31ed5 Fix /index/index.js route not emitting the right route in production (#6516)
Also added integration test in production for this

Fixes: #6285
2019-03-03 19:36:32 +01:00
JJ Kasper
5034e4e1de
Updated entries to not output _app and _document in serverless (#6512)
* Updated entries to not output _app and _document in serverless

* Add test
2019-03-02 13:53:13 -06:00
JJ Kasper
a9c398854a
Add console.error before exit on uncaughtException (#6504) 2019-03-01 13:18:33 -06: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
Joe Haddad
330bedacc7 Add Babel plugin that fixes className for Amp elements (#6486)
This is a simple Babel plugin that overwrites certain attributes for `amp-` elements.
2019-02-28 23:04:29 +01:00
JJ Kasper
8ae1cd35bd Fix dynamic require breaking after updating to v8 (#6475)
* Fix dynamic require breaking after updating to v8

* Add test for dynamic require
2019-02-28 14:41:54 +01:00
JJ Kasper
1c1d5d01f8 Throw error when Promise is returned in next.config (#6476)
After discussion, it was decided we should throw an error when a promise is returned in `next.config.js` as this isn't supported

Fixes: #6416
2019-02-28 14:39:51 +01:00
Joe Haddad
41eaa9cf5a
Run ncc on unistore to fix install warning (#6459)
ncc unistore to fix install warning
2019-02-27 09:12:40 -05:00
JJ Kasper
256970ac75 Remove next-to-next-server babel plugin (#6458)
After discussion it was decided instead of rewriting `next/config` and `next/head` imports to `next-server/config` and `next-server/head` we should just allow importing them as `next/config` and `next/head`
 
Fixes: #6187
2019-02-27 11:00:02 +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
b146eb5200
Replace del with rimraf package (#6411) 2019-02-22 13:49:30 -06:00
Tim Neutkens
bfb5224ce4
Remove schema-utils dependency (#6413) 2019-02-22 20:05:34 +01:00
Tim Neutkens
9247c90177
Remove http-status dependency (#6405) 2019-02-22 16:25:11 +01:00
Tim Neutkens
d14d1704cb
Remove ansi-html dep (#6394)
It's not needed since we use react-error-overlay for webpack errors.
2019-02-22 00:12:47 +01:00
Joe Haddad
1757ad022c Drop cli-cursor dependency (#6387) 2019-02-21 15:34:35 +01:00
Joe Haddad
8b784766f1 Remove alternate screen usage (#6377)
* Make console output well behaved

* Fix bad rebase
2019-02-21 00:42:27 +01:00
Connor Davis
61de215e04
Move webpack config to TypeScript (#6348) 2019-02-20 13:24:02 -06:00
Joe Haddad
90f9c64b74
Use alternate screen buffer if terminal supports it (#6364) 2019-02-20 07:20:09 -05: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
Connor Davis
fcf1167cd4 Upgrade standard and fix files (#6358)
Upgrades `standard` to major version 12
2019-02-19 22:45:07 +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
Joe Haddad
56b1f81ace Fix development mode output (#6312)
* Remove usage of WebpackBar and Friendly Errors

* Add new clearConsole helper

* Add new simplified output for development mode

* Add an explicit bootstrapping mode

* Add missing returns

* Use existing output style

* Adjust first output to say Waiting on

* Only print URL if present
2019-02-16 17:09:49 +01:00
Connor Davis
1e5d0908d0 Block Certain Env Keys That Are Used Internally (#6260)
Closes: #6244 

This will block the following keys:
```
NODE_.+
__.+
```

There doesn't seem to be a way to simulate a failed build or else I'd add tests for it.
2019-02-15 17:49:40 +01:00
Joe Haddad
33b9ebc783 Add module as server fallback main field (#6256)
* Add `module` as server fallback main field

* Test that a module only package can be imported
2019-02-12 01:39:57 +01:00
Jason Miller
734513b9be Apply babel to .mjs files (#6253) 2019-02-11 18:59:24 +01:00
Akram
63c25a9c60 update preset.ts to use isProduction variable (#6234) 2019-02-10 18:45:51 +01:00
Tim Neutkens
45f5663558
Bring in terser-webpack-plugin (#6231)
* Bring in terser-webpack-plugin

* Ignore terser from linting
2019-02-10 04:55:09 +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
59280f7747
Compile all next module files (#6155) 2019-01-27 21:56:02 +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
7ecf675834
Remove resolve rule (#6133)
Fixes #6117

I'm not entirely sure why we had this rule in the first place. I think for some tests related things when we didn't have a monorepo yet. However it could also be related to bundle sizes. I'll compare that when the build finishes.

The reason for #6117 is that we added `react-is` to the dependency tree of Next.js to check valid elements. react-redux uses hoist-non-react-statics which ships a different version of react-is in this case, one that has `ReactIs.isMemo`
2019-01-25 18:33:58 +01:00
Tim Neutkens
243cd65c1d
Drop assetSizePlugin (#6122)
Fixes #6121
2019-01-24 23:04:20 +01:00
Connor Davis
f28833c594 Upgrade Webpack to 4.29.0 with FutureEmitAssets for Massive Memory Optimizations (#6114)
We want our new memory optimizations (https://github.com/webpack/webpack/pull/8609)
2019-01-24 10:25:58 +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
Connor Davis
8065130343 Use webpack IgnorePlugin to exclude 'react-is' from production build (#6084)
`react-is` isn't used in production, so we shouldn't bundle it.

Note: most of those plugins are using the `dev` variable, but in case someone runs `NODE_ENV=development next build`, they would need a copy of `react-is` because the conditional use of `react-is` checks `NODE_ENV` — not whether or not HMR is being used (what what the `dev` variable is based on).
2019-01-18 12:12:29 +01:00
Telegin Evgeniy
aa474017d7 Add iOS 10 support for TerserPlugin (#6067)
Resolves #5630
2019-01-16 10:32:47 +01:00
Tim Neutkens
da3c3aded1
Use Object.assign instead of object spread for serverless loader (#6056)
Fixes https://github.com/zeit/now-builders/issues/168

For some reason with a certain mix of deps `...` is not supported in webpack's parsing.
By default it is supported as all our tests passed before and we have deployed Next.js apps on v2 already.
2019-01-15 02:20:20 +01:00
Tim Neutkens
02ab732096
Remove next/asset (#6046)
* Remove next/asset

Reasoning described in #5970

* Remove next/asset tests

* Bring back asset-page
2019-01-14 01:32:20 +01:00
Connor Davis
1edd872f54
Only Minify Whitespace on Serverless Builds (#6037) 2019-01-11 17:15:12 -06:00
Tim Neutkens
2e9ff91372
Compile next/client and next/pages (#6019)
Because next-routes requires APIs outside of compilation we have to compile these

Fixes https://github.com/fridays/next-routes/issues/274
Fixes #6017
2019-01-11 22:26:27 +01:00
Tim Neutkens
ce3d1914fa
Disable assetSizePlugin in serverless target (#6028) 2019-01-10 23:01:30 +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
Luc
ba95f7541c Improve assets size (#5999)
It looks like :

```
Pages sizes after gzip:

┌ / (196 B)
├ /_app (11.5 kB)
├ /_error (4.44 kB)
├ /blog (196 B)
└ /blog/page (195 B)
```

(style inspired from now-cli : https://github.com/zeit/now-cli/blob/canary/src/util/output/builds.js)

I'll add dynamic chunks in a separate PR.

@timneutkens Do you want to keep `_app` and `_error` or filter them out ? I think it's a good idea to keep them, because `_app` can get pretty large and it would encourage code splitting in that case.
2019-01-06 16:42:09 +01:00
Tim Neutkens
07c6e2852f
Export render instead of default for serverless target (#5979)
Extends on #5927, instead of `.default` we'll expose `.render` which is semantically more correct / mirrors the naming of the custom server API.

I've updated the spec in #5927 to reflect this change.

(copied from #5927):

```js
const http = require('http')
const page = require('./.next/serverless/about.js')
const server = new http.Server((req, res) => page.render(req, res))
server.listen(3000, () => console.log('Listening on http://localhost:3000'))
```
2019-01-02 14:59:28 +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
059dd309c5
Make browser side resolve prefer mjs files (#5898) 2018-12-16 16:26:45 +01:00
Tim Neutkens
1464d932eb
Disable webpack cache option in prod (#5877)
* Disable webpack cache option in prod

* Remove cache option as it’s added by mode === ‘development’
2018-12-14 11:34:05 +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
5708e99eca
Run compilers sequentially when in lambdas mode (#5862) 2018-12-11 21:46:23 +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
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
1a5fc941ce Remove console.log after verifying the correct files are ignored 2018-12-05 15:05: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
2d5b56a181 Disable usage of esmodules when commonjs is enabled on the preset 2018-12-04 20:10:22 +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
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
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
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
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
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
Tim Neutkens
15bb1c5e79
Use Typescript to transpile Next.js core files instead of Babel (#5747)
- Replaces taskr-babel with taskr-typescript for the `next` package
- Makes sure Node 8+ is used, no unneeded transpilation
- Compile Next.js client side files through babel the same way pages are
- Compile Next.js client side files to esmodules, not commonjs, so that tree shaking works.
- Move error-debug.js out of next-server as it's only used/require in development
- Drop ansi-html as dependency from next-server
- Make next/link esmodule (for tree-shaking)
- Make next/router esmodule (for tree-shaking)
- add typescript compilation to next-server
- Remove last remains of Flow
- Move hoist-non-react-statics to next, out of next-server
- Move htmlescape to next, out of next-server
- Remove runtime-corejs2 from next-server
2018-11-28 15:03:02 +01:00
Tim Neutkens
08e3396574
Fix graphql issue with lambdas flag (#5755)
Fixes https://spectrum.chat/?t=604f6aa6-23f2-4358-8b0b-14e5810178dc
2018-11-27 22:20:13 +01:00
Richard Park
44d661af67 Upgrade to webpack@4.26 (#5729)
* Upgrade terser-webpack-plugin

* Upgrade webpack

* Extract common terserPluginConfig
2018-11-22 10:14:14 +01:00
Tim Neutkens
c2eaf26ea9
Remove flow types (#5704)
* Remove flow-typed

* Remove flow types

* Remove the last types

* Bring back taskr dependency

* Revert "Bring back taskr dependency"

This reverts commit 38cb95d7274d63fe63c6ac3c95ca358a28c17895.

* Bring back preset-flow as it’s used for tests

* Revert "Revert "Bring back taskr dependency""

This reverts commit b4c933ef133f4039f544fb10bf31d5c95d3b27a2.
2018-11-21 16:04:37 +01:00
Tim Neutkens
70cae4b2ea
Disable mjs support when in lambdas mode (#5712) 2018-11-20 12:13:31 +01:00
Tim Neutkens
7d78c3b641 Add node_modules bundling under the --lambdas flag for next build (#5690)
* Add node_modules bundling under the —lambdas flag for next build

* Run minifier when lambdas mode is enabled

* Add lambdas option to next.config.js

* Add test for lambdas option
2018-11-17 11:15:33 -08:00
Luc
add5879cc2 Print assets sizes after build (#5664)
It looks like this : 

![capture d ecran 2018-11-13 a 00 47 12](https://user-images.githubusercontent.com/6616955/48361936-7cc13d80-e6dd-11e8-8aa8-c5a73beae966.png)

I'm not sure about the License part, can you check @timneutkens ?
2018-11-13 10:46:26 +01:00
Tim Neutkens
d0dd1bc28d
Trim buildId returned from generateBuildId (#5634)
* Trim buildId returned from generateBuildId

* Pass dir to function
2018-11-12 15:57:48 +01:00
Tim Neutkens
a0137d4fd8 Rename class to NextJsRequireCacheHotReloader 2018-11-07 18:56:53 +01:00
Tim Neutkens
d6284f171b
Don’t fail build on webpack warning (#5622) 2018-11-07 18:38:37 +01:00
Tim Neutkens
2e14b4491b
Bundle @babel/runtime into server bundle (#5619) 2018-11-07 15:38:35 +01:00
Tim Neutkens
f01457e8fc
Take full advantage of caching between builds (#5597)
Takes advantage of caching between builds for Terser, also makes writing caches for babel-loader faster by disabling compression.

Results for zeit.co (350 pages):

Without cache:
[4:16:22 PM] Compiled server in 1m
[4:16:57 PM] Compiled client in 2m
  Done in 125.83s.

With cache:
[4:19:38 PM] Compiled client in 17s
[4:19:50 PM] Compiled server in 29s
  Done in 31.79s.

Note: these results are from my multi-core Macbook Pro 2017, exact specs:
MacBook Pro (13-inch, 2017, Four Thunderbolt 3 Ports)
- 3,3 GHz Intel Core i5
- 16 GB 2133 MHz LPDDR3
- Intel Iris Plus Graphics 650 1536 MB

The `without cache` build runs uglify in parallel, so without cache is likely to take longer on environments where you have only 1 core available.

The `with cache` build however runs in a single thread, so the results should be similar.
2018-11-05 17:51:56 +01:00
Tim Neutkens
1aaa288759 Remove console.log 2018-11-05 01:49:12 +01:00
Tim Neutkens
4945740ac7 Add dir and distDir to resolve log 2018-11-05 00:02:21 +01:00
Tim Neutkens
1388c6897e Add resolve_config log 2018-11-04 23:42:46 +01:00
Tim Neutkens
d5caafb86e Log original error 2018-11-04 23:04:54 +01:00
Tim Neutkens
771e494a88 Log out stats.errors and err object when build fails 2018-11-04 22:16:24 +01:00
Tim Neutkens
b04923775b Add string-hash to compilation for styled-jsx 2018-11-04 03:26:52 +01:00
Tim Neutkens
15854f515b
Transpile styled-jsx into server bundle (#5588)
Drops an additional 6MB from the next-server node_modules size as there's no lodash
2018-11-04 01:11:40 +01:00
Tim Neutkens
a2553bb46e
Remove registration code from initial markup (#5583)
Clears the way a bit for #4943, also makes _document.js less complex, and will allow us to move `__NEXT_DATA__` to a `application/json` script tag.

Also this causes a slightly smaller bundle size 😌
2018-11-03 01:59:54 +01:00
Robert Sköld
123b46634a Moved nanoid use from next-server to next/build (#5441) 2018-11-02 23:19:48 +01:00
Radovan Šmitala
bf157015fb Remove WriteFilePlugin (#5541)
It is native by webpack-dev-middleware 3.1.0 up
2018-11-02 19:47:56 +01:00
Timmy Willison
1b8f56556b Output warnings and errors from webpack individually (#5442)
- Shows warnings even when resolving, to facilitate hints set to 'warning'
- Fixes #876 : Set performance.hints to 'warning' or 'error' in next.config.js
2018-10-20 17:02:20 +02:00
Vasyl Berezovyy
9a09de2feb Remove ignore plugin from webpack build flow (#5394) 2018-10-20 16:59:43 +02:00
Shu Ding
409cf71a4d Move styled-jsx to external modules (#5403) 2018-10-08 16:26:05 +02:00
Tim Neutkens
0f6cff88bc Add next-to-next-server 2018-10-05 23:40:36 +02:00
Tim Neutkens
785377d3c3
Add missing dependencies to server (#5369)
- compile default pages correctly into `.next`
- add missing runtime dependencies
2018-10-03 00:08:57 +02:00
Andy
b041fa4782 Support for wasm (#5316)
* Set a default path for wasm modules

* Added the mimetype "application/wasm" for wasm files

* Upgrade write-file-webpack-plugin to 4.4.1

* Made dynamic(import()) in test to dynamic(() => import())
2018-10-02 13:10:07 +02:00
Tim Neutkens
82d56e063a
next-server (#5357) 2018-10-02 00:55:31 +02:00
Tim Neutkens
b1c4f3aec4
Monorepo (#5341)
- Implements Lerna
- Moves all source code into `packages/next`
- Keeps integration tests in the root directory
2018-10-01 01:02:10 +02:00