You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
At my recent talk at React London I mentioned that we use MemoryFS as the input filesystem for webpack in our bundling service - https://www.youtube.com/watch?v=mkUK2SZ8moY . One issue we came across when making this system scale was that as soon as we swapped out the input filesystem, rebuild times went through the roof. After digging into the webpack core I discovered that the compiler was trying to use the last modified timestamp (mtime) in order to work out whether it needed to rebuild each file. Since MemoryFS does not support mtime, webpack is unable to use its module cache and ends up rebuilding every file on every compilation.
We ended up monkey-patching support for timestamps into the methods we needed. It's not pretty, but here is the code extracted from our project:
const_=require('lodash')constMemoryFS=require('memory-fs')constmfs=newMemoryFS()mfs.lastModified={}// memory-fs doens't support stats by default, so we wrap all relevant methods// to make it work.wrap('writeFileSync',writeFile)wrap('unlinkSync',unlink)wrap('rmdirSync',rmdir)wrap('statSync',stat)wrap('mkdir',mkdir)functionmkdir(fn,args){// mfs doesn't support supplying the mode!if(typeofargs[2]==='function'){returnfn.apply(mfs,[args[0],args[2]])}else{returnfn.apply(mfs,args)}}functionwriteFile(fn,args){constfilePath=args[0]constresult=fn.apply(mfs,args)mfs.lastModified[filePath]=newDate()returnresult}functionunlink(fn,args){constfilePath=args[0]constresult=fn.apply(mfs,args)deletemfs.lastModified[filePath]returnresult}functionrmdir(fn,args){constdir=args[0]constresult=fn.apply(mfs,args)mfs.lastModified=_.reduce(mfs.lastModified,(memo,mtime,filePath)=>{if(filePath.indexOf(dir)!==0){memo[filePath]=mtime}returnmemo},{})returnresult}functionstat(fn,args){constfilePath=args[0]conststats=fn.apply(mfs,args)stats.mtime=mfs.lastModified[filePath]returnstats}functionwrap(method,fn){constoldFn=mfs[method]mfs[method]=()=>fn(oldFn,arguments)}
Continuing discussions from here - https://twitter.com/TheLarkInn/status/855369900914855937
At my recent talk at React London I mentioned that we use MemoryFS as the input filesystem for webpack in our bundling service - https://www.youtube.com/watch?v=mkUK2SZ8moY . One issue we came across when making this system scale was that as soon as we swapped out the input filesystem, rebuild times went through the roof. After digging into the webpack core I discovered that the compiler was trying to use the last modified timestamp (
mtime
) in order to work out whether it needed to rebuild each file. Since MemoryFS does not supportmtime
, webpack is unable to use its module cache and ends up rebuilding every file on every compilation.We ended up monkey-patching support for timestamps into the methods we needed. It's not pretty, but here is the code extracted from our project:
@sokra @TheLarkInn
The text was updated successfully, but these errors were encountered: