Skip to content

Commit

Permalink
Webpack next caching (#162)
Browse files Browse the repository at this point in the history
* use webpack@next

* disable minification

* webpack test upgrades

* implement webpack cache

* cli and api cache handling

* try bumping js memory

* disable ci cache, run gc

* update test args

* increase timeout

* better errors on integration execution failures

* saslprep.js cache fix

* separate src and dist unit cases

* clear memory cache on completion

* add cacheable to loaders

* always reemit assets for cache support

* reenable path-platform case

* add watcher

* readme updates

* watcher api refinements

* polish up watcher errors

* close compiler on done
  • Loading branch information
guybedford authored and rauchg committed Dec 20, 2018
1 parent 484b415 commit c2fb87e
Show file tree
Hide file tree
Showing 46 changed files with 2,203 additions and 1,735 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"build": "node scripts/build",
"build-test-binary": "cd test/binary && node-gyp rebuild && cp build/Release/hello.node ../integration/hello.node",
"codecov": "codecov",
"test": "npm run build-test-binary && npm run build && jest",
"test-coverage": "jest --coverage --globals \"{\\\"coverage\\\":true}\" && codecov",
"test": "npm run build-test-binary && npm run build && node --expose-gc --max_old_space_size=3072 node_modules/.bin/jest",
"test-coverage": "node --expose-gc --max_old_space_size=3072 node_modules/.bin/jest --coverage --globals \"{\\\"coverage\\\":true}\" && codecov",
"prepublish": "in-publish && npm test || not-in-publish"
},
"devDependencies": {
Expand Down Expand Up @@ -42,6 +42,7 @@
"firebase": "^5.5.8",
"firebase-admin": "^6.3.0",
"fontkit": "^1.7.7",
"get-folder-size": "^2.0.0",
"glob": "^7.1.3",
"got": "^9.3.2",
"graceful-fs": "^4.1.15",
Expand Down Expand Up @@ -93,7 +94,7 @@
"typescript": "^3.2.2",
"vue": "^2.5.17",
"vue-server-renderer": "^2.5.17",
"webpack": "^4.26.0",
"webpack": "github:webpack/webpack#next",
"when": "^3.7.8"
}
}
29 changes: 26 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ npm i -g @zeit/ncc
$ ncc build input.js -o dist
```

For fast rebuilds the watcher can be run with:

```bash
$ ncc build input.js -o dist -w
```

Outputs the build of `input.js` into `dist/index.js`.

```bash
Expand All @@ -60,17 +66,34 @@ file is necessary. Most likely you want to indicate `es2015` support:

```js
require('@zeit/ncc')('/path/to/input', {
minify: true, // default
// provide a custom cache path or disable caching
cache: "./custom/cache/path" | false,
// externals to leave as requires of the build
externals: ["externalpackage"],
sourceMap: true // default
}).then(({ code, assets }) => {
minify: false, // default
sourceMap: false, // default
watch: false // default
}).then(({ code, map, assets }) => {
console.log(code);
// assets is an object of asset file names to sources
// expected relative to the output code (if any)
})
```

When `watch: true` is set, the build object is not a promise, but has the following signature:

```js
{
// handler re-run on each build completion
// watch errors are reported on "err"
handler (({ err, code, map, assets }) => { ... })
// handler re-run on each rebuild start
rebuild (() => {})
// close the watcher
void close ();
}
```

## Caveats

- Files / assets are relocated based on a static evaluator. Dynamic non-statically analyzable asset loads may not work out correctly
23 changes: 16 additions & 7 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ async function main() {
const { code: cli, assets: cliAssets } = await ncc(
__dirname + "/../src/cli",
{
externals: ["./index.js"]
externals: ["./index.js"],
minify: true
}
);
const { code: index, assets: indexAssets } = await ncc(
Expand All @@ -20,28 +21,36 @@ async function main() {
// to bundle it. even if we did want watching and a bigger
// bundle, webpack (and therefore ncc) cannot currently bundle
// chokidar, which is quite convenient
externals: ["chokidar"]
externals: ["chokidar"],
minify: true
}
);

const { code: nodeLoader, assets: nodeLoaderAssets } = await ncc(
__dirname + "/../src/loaders/node-loader"
__dirname + "/../src/loaders/node-loader",
{
minify: true
}
);

const { code: relocateLoader, assets: relocateLoaderAssets } = await ncc(
__dirname + "/../src/loaders/relocate-loader"
__dirname + "/../src/loaders/relocate-loader",
{ minify: true }
);

const { code: shebangLoader, assets: shebangLoaderAssets } = await ncc(
__dirname + "/../src/loaders/shebang-loader"
__dirname + "/../src/loaders/shebang-loader",
{ minify: true }
);

const { code: tsLoader, assets: tsLoaderAssets } = await ncc(
__dirname + "/../src/loaders/ts-loader"
__dirname + "/../src/loaders/ts-loader",
{ minify: true }
);

const { code: sourcemapSupport, assets: sourcemapAssets } = await ncc(
require.resolve("source-map-support/register")
require.resolve("source-map-support/register"),
{ minfiy: true }
);

// detect unexpected asset emissions from core build
Expand Down
Loading

0 comments on commit c2fb87e

Please sign in to comment.