Hard drive i/o is slow and writing to your ssd reduces its lifespan. This gulp plugin provides an in-memory destination for development builds without having to make a ramdisk or symlink your build folder into one.
Installation
# npm install -D gulp-mem yarn add -D gulp-mem
Usage
Import the module and set up your instance:
// Import the module.const GulpMem = // Create your instance.const gulpMem = // Set the base path to match your build destination.// "/" or "./" corresponds to the mock filesystem root.// If you build to "%PROJECT_PATH%/build" set your base path to "./build".gulpMemserveBasePath = './build'
Pipe stuff into gulpMem.dest
instead of gulp.dest
to write it to the in-memory filesystem:
// You may want to use separate gulp sequences for dev and production builds,// but you could also do some other inline check or conditionally patch the method. gulp gulp
Now you can serve the memory contents through your dev server using the middleware at gulpMem.middleware
. Most likely you'll want to use something like BrowserSync:
gulp
If you already have a server running in another process you can start a minimal http
server in your gulp process and proxy to/from it.
You can also use the filesystem api on gulpMem.fs
or patch in a different implementation.
Optional Configuration
// Specify logging functions.gulpMemlogFn = consoleloggulpMemerrorFn = consoleerror