webpack-plugin-ramdisk
raw JSON → 0.2.0 verified Sat Apr 25 auth: no javascript
A Webpack plugin that creates and mounts a RAM disk for blazing fast build output, using the OS native filesystem instead of in-memory JS filesystems. v0.2.0 is the latest stable release (infrequent updates). Key differentiators: prevents excessive SSD writes during HMR, supports both macOS and Linux, integrates as a standard Webpack plugin. Unlike webpack-virtual-modules or memfs, this leverages real OS-level RAM drives for true I/O speed. Requires Node >=10 and Webpack 4 or 5.
Common errors
error Error: ENOENT: no such file or directory, mkdir '/Volumes/wpr/myapp/dist' ↓
cause The RAM disk mount point does not exist or could not be created.
fix
Ensure the plugin is configured correctly and the system supports RAM disks. On macOS, run 'diskutil info /Volumes/wpr' to check. On Linux, ensure /mnt exists and is writable.
error Error: ENOSPC: no space left on device, write ↓
cause The RAM disk size (default 256 MB) is too small for the build output.
fix
Increase the
bytes option in plugin configuration. Calculate required size: output size (e.g., webpack-bundle-analyzer) + 20% margin. error Error: WebpackPluginRamdisk is not a constructor ↓
cause Incorrect import: using default import instead of named import, or requiring without destructuring.
fix
Use: const { WebpackPluginRamdisk } = require('webpack-plugin-ramdisk'); or import { WebpackPluginRamdisk } from 'webpack-plugin-ramdisk';
Warnings
gotcha The plugin modifies the output path: the disk root is prepended to the configured output path (e.g., output.path '/myapp/dist' becomes '/Volumes/wpr/myapp/dist' on macOS). Ensure your output path does not already include the disk root. ↓
fix Set output.path to a path relative to the RAM disk root (e.g., '/myapp/dist'). Do not prefix '/Volumes/wpr' or '/mnt/wpr' manually.
gotcha The plugin requires Node's 'fs' module and OS-native RAM disk creation. This does NOT on Windows — only macOS and Linux are supported. Configuration may fail silently on Windows. ↓
fix Use alternative in-memory filesystem like memfs or webpack-virtual-modules for cross-platform builds.
gotcha The RAM disk is mounted at a system-specific path: macOS: /Volumes/<name>, Linux: /mnt/<name>. The code assumes the mount path exists and is writable. If the path is already occupied, the plugin may fail. ↓
fix Ensure the mount point directory does not exist before running the plugin (e.g., remove /Volumes/wpr or /mnt/wpr). The plugin will create it.
gotcha Large builds may exceed the default 256 MB RAM disk size (bytes: 2.56e8). If the build output is larger, the plugin will fail with a disk full error. ↓
fix Increase the `bytes` option to accommodate your build output size. Use process.memoryUsage() or estimate output size.
gotcha The plugin does NOT clean up the RAM disk when the process exits. The disk remains mounted and consumes RAM until manually unmounted (diskutil unmount /Volumes/wpr or umount /mnt/wpr). ↓
fix Call WebpackPluginRamdisk.cleanup(diskPath) manually in your script's exit handler (e.g., process.on('exit', ...)).
Install
npm install webpack-plugin-ramdisk yarn add webpack-plugin-ramdisk pnpm add webpack-plugin-ramdisk Imports
- WebpackPluginRamdisk wrong
const WebpackPluginRamdisk = require('webpack-plugin-ramdisk')correctconst { WebpackPluginRamdisk } = require('webpack-plugin-ramdisk') - WebpackPluginRamdisk wrong
import WebpackPluginRamdisk from 'webpack-plugin-ramdisk'correctimport { WebpackPluginRamdisk } from 'webpack-plugin-ramdisk' - WebpackPluginRamdisk.cleanup wrong
const { cleanup } = require('webpack-plugin-ramdisk')correctconst { cleanup } = require('webpack-plugin-ramdisk').WebpackPluginRamdisk
Quickstart
const path = require('path');
const { WebpackPluginRamdisk } = require('webpack-plugin-ramdisk');
module.exports = {
output: {
path: '/myapp/dist'
},
plugins: [
new WebpackPluginRamdisk({
blockSize: 512,
bytes: 2.56e8,
name: 'wpr'
})
]
};