Skip to content

Commit 022aace

Browse files
committed
fix css-modules#32: ensure caches are persisted
Previously, the caches were re-initialized on every plugin initialization. This caused an incompatibility with other tools like rebundler or persistify. This change keeps the original intent of creating caches when the plugin is initialized, but ensures the process keeps the caches instead of the plugin instance itself. It’s not really possible to have a cache conflict since they’re keyed by file.
1 parent e85143e commit 022aace

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

index.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ function normalizeManifestPaths (tokensByFile, rootDir) {
3737
}
3838

3939
var cssExt = /\.css$/;
40+
41+
// caches
42+
//
43+
// persist these for as long as the process is running. #32
44+
45+
// keep track of css files visited
46+
var filenames = [];
47+
48+
// keep track of all tokens so we can avoid duplicates
49+
var tokensByFile = {};
50+
51+
// keep track of all source files for later builds: when
52+
// using watchify, not all files will be caught on subsequent
53+
// bundles
54+
var sourceByFile = {};
55+
4056
module.exports = function (browserify, options) {
4157
options = options || {};
4258

@@ -91,17 +107,6 @@ module.exports = function (browserify, options) {
91107
return plugin;
92108
});
93109

94-
// keep track of css files visited
95-
var filenames = [];
96-
97-
// keep track of all tokens so we can avoid duplicates
98-
var tokensByFile = {};
99-
100-
// keep track of all source files for later builds: when
101-
// using watchify, not all files will be caught on subsequent
102-
// bundles
103-
var sourceByFile = {};
104-
105110
function transform (filename) {
106111
// only handle .css files
107112
if (!cssExt.test(filename)) {

0 commit comments

Comments
 (0)