Skip to content

Commit

Permalink
Update README docs for cacheDirectory's actual behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
sohkai authored and danez committed Nov 7, 2016
1 parent 0425535 commit 8fa7946
Showing 1 changed file with 2 additions and 56 deletions.
58 changes: 2 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module: {
}
```

or by using the query property:
or by using the [query property](https://webpack.github.io/docs/using-loaders.html#query-parameters):

```javascript
module: {
Expand All @@ -73,7 +73,7 @@ module: {

This loader also supports the following loader-specific option:

* `cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (`loader: 'babel-loader?cacheDirectory'`) the loader will use the default cache directory in `node_modules/.cache/babel-loader`.
* `cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (`loader: 'babel-loader?cacheDirectory'`) or `true` (`loader: babel-loader?cacheDirectory=true`) the loader will use the default cache directory in `node_modules/.cache/babel-loader` or fallback to the default OS temporary file directory if no `node_modules` folder could be found in any root directory.

* `cacheIdentifier`: Default is a string composed by the babel-core's version, the babel-loader's version, the contents of .babelrc file if it exists and the value of the environment variable `BABEL_ENV` with a fallback to the `NODE_ENV` environment variable. This can be set to a custom value to force cache busting if the identifier changes.

Expand Down Expand Up @@ -144,60 +144,6 @@ In the case one of your dependencies is installing `babel` and you cannot uninst
}
```


### using `cacheDirectory` fails with ENOENT Error

If using cacheDirectory results in an error similar to the following:

```bash
ERROR in ./frontend/src/main.js
Module build failed: Error: ENOENT, open 'true/350c59cae6b7bce3bb58c8240147581bfdc9cccc.json.gzip'
@ multi app
```
(notice the `true/` in the filepath)

That means that most likely, you're not setting the options correctly, and you're doing something similar to:

```javascript
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel?cacheDirectory=true'
}
]
```

That's not the correct way of setting boolean values. You should do instead:

```javascript
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel?cacheDirectory'
}
]
```

or use the [query](https://webpack.github.io/docs/using-loaders.html#query-parameters) property:

```javascript
loaders: [
// the optional 'runtime' transformer tells babel to require the runtime
// instead of inlining it.
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
cacheDirectory: true
}
}
]
```


### custom polyfills (e.g. Promise library)

Since Babel includes a polyfill that includes a custom [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and [core.js](https://github.com/zloirock/core-js), the following usual shimming method using `webpack.ProvidePlugin` will not work:
Expand Down

0 comments on commit 8fa7946

Please sign in to comment.