mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Try caching inline assets with js Map
This commit is contained in:
parent
4ffc7bf404
commit
4b29c210ba
1 changed files with 17 additions and 1 deletions
18
.eleventy.js
18
.eleventy.js
|
|
@ -14,6 +14,8 @@ function getAssetFilePath(componentName) {
|
||||||
return `./${componentName}`
|
return `./${componentName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const inlineAssetCache = new Map()
|
||||||
|
|
||||||
module.exports = function ( eleventyConfig ) {
|
module.exports = function ( eleventyConfig ) {
|
||||||
// console.log('eleventyConfig', eleventyConfig)
|
// console.log('eleventyConfig', eleventyConfig)
|
||||||
|
|
||||||
|
|
@ -31,13 +33,25 @@ module.exports = function ( eleventyConfig ) {
|
||||||
|
|
||||||
const assetFileName = getAssetFilePath( componentName )
|
const assetFileName = getAssetFilePath( componentName )
|
||||||
|
|
||||||
|
// console.log('Cache size', inlineAssetCache)
|
||||||
|
|
||||||
if ( componentName.includes('.js') ) {
|
if ( componentName.includes('.js') ) {
|
||||||
|
|
||||||
// If a never before seen component, add the JS code
|
// If a never before seen component, add the JS code
|
||||||
if(!jsManager.hasComponentCode(componentName)) {
|
if( !inlineAssetCache.has( assetFileName ) ) {
|
||||||
|
|
||||||
let contents = ''
|
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)
|
console.log('Reading component file', componentName)
|
||||||
const javascriptCode = fs.readFileSync( assetFileName, { encoding: "UTF-8" })
|
const javascriptCode = fs.readFileSync( assetFileName, { encoding: "UTF-8" })
|
||||||
|
|
||||||
|
|
@ -46,6 +60,8 @@ module.exports = function ( eleventyConfig ) {
|
||||||
|
|
||||||
contents = minified.code
|
contents = minified.code
|
||||||
|
|
||||||
|
inlineAssetCache.set( assetFileName, contents )
|
||||||
|
|
||||||
// console.log('Got component', componentName, componentCss)
|
// console.log('Got component', componentName, componentCss)
|
||||||
|
|
||||||
jsManager.addComponentCode(componentName, contents)
|
jsManager.addComponentCode(componentName, contents)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue