Try caching inline assets with js Map

This commit is contained in:
Sam Carlton 2021-05-08 18:05:35 -05:00
parent 4ffc7bf404
commit 4b29c210ba

View file

@ -14,6 +14,8 @@ function getAssetFilePath(componentName) {
return `./${componentName}`
}
const inlineAssetCache = new Map()
module.exports = function ( eleventyConfig ) {
// console.log('eleventyConfig', eleventyConfig)
@ -31,13 +33,25 @@ module.exports = function ( eleventyConfig ) {
const assetFileName = getAssetFilePath( componentName )
// console.log('Cache size', inlineAssetCache)
if ( componentName.includes('.js') ) {
// If a never before seen component, add the JS code
if(!jsManager.hasComponentCode(componentName)) {
if( !inlineAssetCache.has( assetFileName ) ) {
let contents = ''
// if ( inlineAssetCache.has( assetFileName ) ) {
// console.log('Reading component from cache', componentName)
// console.log('Cache size', inlineAssetCache.size)
// contents = inlineAssetCache.get( assetFileName )
// } else {
// }
console.log('Reading component file', componentName)
const javascriptCode = fs.readFileSync( assetFileName, { encoding: "UTF-8" })
@ -46,6 +60,8 @@ module.exports = function ( eleventyConfig ) {
contents = minified.code
inlineAssetCache.set( assetFileName, contents )
// console.log('Got component', componentName, componentCss)
jsManager.addComponentCode(componentName, contents)