Adds persistent on-disk caching to webpack loaders
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
fixtures/test-module
support
test
.eslintignore
.eslintrc.js
.gitignore
.npmignore
.travis.yml
CONTRIBUTING.md
README.md
caching.js
dump.js
index.js
package.json

README.md

cached-loader

Adds persistent on-disk caching to webpack loaders

deprecated. use webpack-contrib/cache-loader instead.

Example

var path = require('path');
var combineLoaders = require('webpack-combine-loaders');

// some external config
var sassConfig = require('./sassConfig');

// some environmental config
var opts = {
  rootDir: process.cwd(),
  cssSourcemaps: Boolean(process.env.NODE_ENV !== 'production'),
};

module.exports = {
  module: {
    loaders: [
     {
        test: /\.scss$/,
        loader: combineLoaders([
          {
            loader: 'cached-loader',
            query: {
              cacheDirectory: path.join(opts.rootDir, 'tmp/cache/cached-loader'),
              cacheIdentifier: JSON.stringify(opts) + JSON.stringify(sassConfig),
            },
          },
          {
            loader: 'style-loader',
          },
          {
            loader: 'css-loader',
            query: {
              sourceMap: opts.cssSourcemaps,
            },
          },
          {
            loader: 'postcss-loader',
          },
          {
            loader: 'sass-loader',
            query: Object.assign({}, sassConfig, {
              sourceMap: opts.cssSourcemaps,
            }),
          },
        ]),
      },
    ],
  },
};

Now webpack should be faster from a cold start.

See also