From 6c252933e28f8a3c0dfcd7e2c100fb60112e3adf Mon Sep 17 00:00:00 2001 From: Vladimir Morulus Date: Tue, 21 Nov 2017 05:09:41 +0300 Subject: [PATCH] noCache --- README.md | 4 ++++ src/index.js | 18 +++++++++++------- src/validate.js | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 505ec8e..3096578 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,10 @@ Short alias for the [postcss-modules-local-by-default](https://github.com/css-mo Provides absolute path to the project directory. Providing this will result in better generated class names. It can be obligatory, if you run require hook and build tools (like [css-modulesify](https://github.com/css-modules/css-modulesify)) from different working directories. +### `noCache` boolean + +Do not cache module. You may need this option if you want to watch files. But expect the performance degradation when you call require for same file multiple times. + ## Debugging diff --git a/src/index.js b/src/index.js index b015092..055c6fe 100644 --- a/src/index.js +++ b/src/index.js @@ -23,6 +23,7 @@ const debugSetup = require('debug')('css-modules:setup'); module.exports = function setupHook({ camelCase, devMode, + noCache, extensions = '.css', ignore, preprocessCss = identity, @@ -87,11 +88,14 @@ module.exports = function setupHook({ : resolve(dirname(from), _to); // checking cache - let tokens = tokensByFile[filename]; - if (tokens) { - debugFetch(`${filename} → cache`); - debugFetch(tokens); - return tokens; + let tokens; + if (!noCache) { + tokens = tokensByFile[filename]; + if (tokens) { + debugFetch(`${filename} → cache`); + debugFetch(tokens); + return tokens; + } } const source = preprocessCss(readFileSync(filename, 'utf8'), filename); @@ -103,11 +107,11 @@ module.exports = function setupHook({ tokens = lazyResult.root.exports || {}; - if (!debugMode) + if (!debugMode && !noCache) // updating cache tokensByFile[filename] = tokens; else - // clearing cache in development mode + // clearing cache in development mode or with noCache option delete require.cache[filename]; if (processCss) diff --git a/src/validate.js b/src/validate.js index 7b76c95..08706bf 100644 --- a/src/validate.js +++ b/src/validate.js @@ -30,6 +30,7 @@ const rules = { hashPrefix: 'string', mode: 'string', rootDir: 'string', + noCache: 'boolean', }; const tests = {