Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard cache dir as default cacheDirectory #301

Merged
merged 1 commit into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 OS temporary file directory.
* `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`.

* `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
3 changes: 2 additions & 1 deletion lib/fs-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
var crypto = require('crypto');
var mkdirp = require('mkdirp');
var findCacheDir = require('find-cache-dir');
var fs = require('fs');
var os = require('os');
var path = require('path');
Expand Down Expand Up @@ -126,7 +127,7 @@ var cache = module.exports = function(params, callback) {
var identifier = params.identifier;
var directory = (typeof params.directory === 'string') ?
params.directory :
os.tmpdir();
findCacheDir({ name: 'babel-loader' });
var file = path.join(directory, filename(source, identifier, options));

// Make sure the directory exists.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"lib"
],
"dependencies": {
"find-cache-dir": "^0.1.1",
"loader-utils": "^0.2.11",
"mkdirp": "^0.5.1",
"object-assign": "^4.0.1"
Expand Down
9 changes: 7 additions & 2 deletions test/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var webpack = require('webpack');
describe('Filesystem Cache', function() {
this.timeout(15000);

var defaultCacheDir = path.resolve(__dirname,
'../node_modules/.cache/babel-loader');
var cacheDir = path.resolve(__dirname, 'output/cache/cachefiles');
var outputDir = path.resolve(__dirname, './output/cache/');
var babelLoader = path.resolve(__dirname, '../');
Expand Down Expand Up @@ -43,6 +45,9 @@ describe('Filesystem Cache', function() {
mkdirp(cacheDir, done);
});
});
beforeEach(function(done) {
rimraf(defaultCacheDir, done);
});

it('should output files to cache directory', function(done) {

Expand Down Expand Up @@ -73,7 +78,7 @@ describe('Filesystem Cache', function() {
});
});

it('should output files to OS\'s tmp dir', function(done) {
it('should output files to standard cache dir by default', function(done) {
var config = assign({}, globalConfig, {
module: {
loaders: [
Expand All @@ -93,7 +98,7 @@ describe('Filesystem Cache', function() {
webpack(config, function(err, stats) {
expect(err).to.be(null);

fs.readdir(os.tmpdir(), function(err, files) {
fs.readdir(defaultCacheDir, function(err, files) {
files = files.filter(function(file) {
return /\b[0-9a-f]{5,40}\.json\.gzip\b/.test(file);
});
Expand Down