Skip to content

noCache #105

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 11 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const debugSetup = require('debug')('css-modules:setup');
module.exports = function setupHook({
camelCase,
devMode,
noCache,
extensions = '.css',
ignore,
preprocessCss = identity,
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const rules = {
hashPrefix: 'string',
mode: 'string',
rootDir: 'string',
noCache: 'boolean',
};

const tests = {
Expand Down