sysgears / webpack-virtual-modules

Webpack Virtual Modules is a webpack plugin that lets you create, modify, and delete in-memory files in a way that webpack treats them as if they were physically presented in the file system.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to reset files

fringd opened this issue · comments

I'm using this to overlay my files on a filesystem. I'd like to be able to "reset" a file to its original contents. I can do this with writeModule and readFileSync right now, but it would be nice if writeModules('filename', contents) had a resetModule('filename') to undo the machinations for subsequent runs.

@fringd I would rather name it deleteVirtualModule(filePath), or unlinkModule(filePath). Would you be willing to submit Pull Request for this feature. Preferably with adding tests, but I will accept it without tests too if the code will be reliable.

That sounds good to me. Do you know if there's a way to do this without just reading the file and re-writing it like i said? is there a way to just remove it from the virtual file system or cache or whatever?

@fringd Yes, I am certain that there is a way, but to make good implementation - you will have to delve into internals of webpack and its companion packages.

I notice in your implementation you're overriding a method called "purge" do you think this does what I want?

so compiler.inputFileSystem.purge(fileName) does exactly what I want it seems. maybe we don't need this feature.

@fringd Yes, if it is working, then we are done :)