Skip to content

Commit 6c25293

Browse files
morulusVladimir Kalmykov
authored andcommitted
noCache
1 parent c89b4fb commit 6c25293

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ Short alias for the [postcss-modules-local-by-default](https://github.com/css-mo
268268

269269
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.
270270

271+
### `noCache` boolean
272+
273+
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.
274+
271275

272276
## Debugging
273277

src/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const debugSetup = require('debug')('css-modules:setup');
2323
module.exports = function setupHook({
2424
camelCase,
2525
devMode,
26+
noCache,
2627
extensions = '.css',
2728
ignore,
2829
preprocessCss = identity,
@@ -87,11 +88,14 @@ module.exports = function setupHook({
8788
: resolve(dirname(from), _to);
8889

8990
// checking cache
90-
let tokens = tokensByFile[filename];
91-
if (tokens) {
92-
debugFetch(`${filename} → cache`);
93-
debugFetch(tokens);
94-
return tokens;
91+
let tokens;
92+
if (!noCache) {
93+
tokens = tokensByFile[filename];
94+
if (tokens) {
95+
debugFetch(`${filename} → cache`);
96+
debugFetch(tokens);
97+
return tokens;
98+
}
9599
}
96100

97101
const source = preprocessCss(readFileSync(filename, 'utf8'), filename);
@@ -103,11 +107,11 @@ module.exports = function setupHook({
103107

104108
tokens = lazyResult.root.exports || {};
105109

106-
if (!debugMode)
110+
if (!debugMode && !noCache)
107111
// updating cache
108112
tokensByFile[filename] = tokens;
109113
else
110-
// clearing cache in development mode
114+
// clearing cache in development mode or with noCache option
111115
delete require.cache[filename];
112116

113117
if (processCss)

src/validate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const rules = {
3030
hashPrefix: 'string',
3131
mode: 'string',
3232
rootDir: 'string',
33+
noCache: 'boolean',
3334
};
3435

3536
const tests = {

0 commit comments

Comments
 (0)