Skip to content

Commit a4fe796

Browse files
committed
simple caching to prevent duplicate styles
1 parent dc1d80e commit a4fe796

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/file-system-loader.js

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default class FileSystemLoader {
2525
this.sources = {}
2626
this.importNr = 0
2727
this.core = new Core(plugins)
28+
this.tokensByFile = {};
2829
}
2930

3031
fetch( _newPath, relativeTo, _trace ) {
@@ -35,11 +36,15 @@ export default class FileSystemLoader {
3536
rootRelativePath = path.resolve( relativeDir, newPath ),
3637
fileRelativePath = path.resolve( path.join( this.root, relativeDir ), newPath )
3738

39+
const tokens = this.tokensByFile[fileRelativePath]
40+
if (tokens) { return resolve(tokens) }
41+
3842
fs.readFile( fileRelativePath, "utf-8", ( err, source ) => {
3943
if ( err ) reject( err )
4044
this.core.load( source, rootRelativePath, trace, this.fetch.bind( this ) )
4145
.then( ( { injectableSource, exportTokens } ) => {
4246
this.sources[trace] = injectableSource
47+
this.tokensByFile[fileRelativePath] = exportTokens
4348
resolve( exportTokens )
4449
}, reject )
4550
} )

0 commit comments

Comments
 (0)