UNPKG

6.93 kBMarkdownView Raw
1[tests]: https://img.shields.io/circleci/project/github/shellscape/webpack-plugin-ramdisk.svg
2[tests-url]: https://circleci.com/gh/shellscape/webpack-plugin-ramdisk
3
4[cover]: https://codecov.io/gh/shellscape/webpack-plugin-ramdisk/branch/master/graph/badge.svg
5[cover-url]: https://codecov.io/gh/shellscape/webpack-plugin-ramdisk
6
7[size]: https://packagephobia.now.sh/badge?p=webpack-plugin-ramdisk
8[size-url]: https://packagephobia.now.sh/result?p=webpack-plugin-ramdisk
9
10[https]: https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
11[http2]: https://nodejs.org/api/http2.html#http2_http2_createserver_options_onrequesthandler
12[http2tls]: https://nodejs.org/api/http2.html#http2_http2_createsecureserver_options_onrequesthandler
13
14<div align="center">
15 <img width="256" src="https://raw.githubusercontent.com/shellscape/webpack-plugin-ramdisk/master/assets/ramdisk.svg?sanitize=true" alt="webpack-plugin-ramdisk"><br/><br/>
16</div>
17
18[![tests][tests]][tests-url]
19[![cover][cover]][cover-url]
20[![size][size]][size-url]
21[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
22
23# webpack-plugin-ramdisk
24
25🐏 A webpack plugin for blazing fast builds on a RAM disk / drive
26
27<a href="https://www.patreon.com/shellscape">
28 <img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
29</a>
30
31_Please consider donating if you find this project useful._
32
33### What It Does
34
35This plugin will initialize and mount a [RAM disk / drive](https://en.wikipedia.org/wiki/RAM_drive) to enable faster build emitting times. This has advantages over third-party in-memory filesystems in that it uses Node's `fs` module in conjunction with the local system's native capabilities. It's especially useful for projects which need to perform many successive builds, such as during development with Hot Module Reloading enabled. In an HMR scenario, this will also _prevent excessive writes_ to Solid State Drives, preventing the shortening of the drive's lifespan.
36
37## Requirements
38
39`webpack-plugin-ramdisk` is an [evergreen 🌲](./.github/FAQ.md#what-does-evergreen-mean) module.
40
41This module requires an [Active LTS](https://github.com/nodejs/Release) Node version (v10.0.0+).
42
43## Install
44
45Using npm:
46
47```console
48npm install webpack-nano webpack-plugin-ramdisk --save-dev
49```
50
51_Note: We recommend using [webpack-nano](https://github.com/shellscape/webpack-nano), a very tiny, very clean webpack CLI._
52
53## Usage
54
55When the plugin is applied during a webpack build, the `output` path specified for a compiler configuration is _appended to the RAMdisk path_. Be sure to choose an appropriate output path!
56
57Create a `webpack.config.js` file:
58
59```js
60const { WebpackPluginRamdisk } = require('webpack-plugin-ramdisk');
61const options = { ... };
62
63module.exports = {
64 // an example entry definition
65 output: {
66 path: '/myapp/dist' // ← important: this must be an absolute path!
67 }
68 ...
69 plugins: [
70 new WebpackPluginRamdisk(options)
71 ]
72};
73
74```
75
76And run `webpack`:
77
78```console
79$ npx wp
80```
81
82You'll then see that build output has been written to the RAMdisk. In our example above on a MacOS computer, the output path would be `/Volumes/wpr/myapp/dist`.
83
84## Options
85
86### `blockSize`
87Type: `Number`<br>
88Default: `512`
89
90Sets the [block size](https://en.wikipedia.org/wiki/Block_(data_storage)) used when allocating space for the RAMdisk.
91
92### `bytes`
93Type: `Number`<br>
94Default: `2.56e8`
95
96Sets the physical size of the RAMdisk, in bytes. The default value is 256mb. Most builds won't require nearly that amount, and the value can be lowered. For extremely large builds, this value may be increased as needed.
97
98### `name`
99Type: `String`<br>
100Default: `wpr`
101
102Sets the name of the disk/drive/mount point for the RAMdisk. e.g. A value of `batman` would result in a disk root of `/Volumes/batman` on MacOS and `/mnt/batman` on Linux variants.
103
104## API
105
106### `WebpackPluginRamdisk.cleanup(diskPath)`
107Parameters: `diskPath``String` The mounted path of the RAMdisk to unmount and remove
108
109`Static`. Provides a convenience method to unmount and remove a RAMdisk created with the plugin.
110
111To remove the RAMdisk that the plugin created, first obtain the `diskPath` from the plugin:
112
113```js
114const { WebpackPluginRamdisk } = require('webpack-plugin-ramdisk');
115const plugin = new WebpackPluginRamdisk(options)
116const { diskPath } = plugin;
117
118WebpackPluginRamdisk.cleanup(diskPath);
119```
120
121_**Use Caution** as specifying the wrong `diskPath` can have unintended consequences and cause a loss of data. The commands this method utilize can remove other drives as well._
122
123### Linux Users
124
125Automatic creation of a RAMdisk requires administrative permissions. During the build process you'll be prompted by `sudo` to enter your credentials.
126
127### Windows Users
128
129Windows users that have installed [Windows Subsystem for Linux v2](https://devblogs.microsoft.com/commandline/announcing-wsl-2/) can use the module without issue.
130
131However, Windows users without WSL2 are in a pickle. Unfortunately Windows does not ship with any capabilities that allow for creation of RAM disks / drives programmatically, without user interaction. This is an OS limitation and we cannot work around it. However, there is a solution for Windows users - tools like [ImDisk](https://sourceforge.net/projects/imdisk-toolkit/) will allow you to create a RAMdisk and assign it a drive letter, to which one can point a webpack configuration's `output` property.
132
133## Performance
134
135Average savings for a bundle's total build time ranges from 25-32% according to tests we've run on a variety of platforms and bundle sizes. The largest gains were during frequently Hot Module Reloading operations, where one or more files were changed and the bundle(s) were rebuilt during watch mode.
136
137For example, the following stats were generated for a 13mb bundle:
138
139Without `webpack-plugin-ramdisk`:
140 - initial build and emit: 19.88s
141 - initial file change, save, and rebuild: 0.6s
142 - subsequent changes and rebuilds: 1.15s 0.864s 1.68s
143
144Average build and emit time: 1.23s
145
146With `webpack-plugin-ramdisk`:
147 - initial build and emit: 16.8s
148 - initial file change, save, and rebuild: 0.9s
149 - subsequent changes and rebuilds: 1.23s, 0.951s, 0.48s
150
151Average build and emit time: 0.887s
152
153Result = 28% time savings. This may seem inconsequential, but consider the number of times a single developer will save and rebuild for HMR during the course of a workday. When aggregated, that's a considerable savings throughout a session.
154
155## Removing the RAMdisk
156
157_These commands use `wpr` as the RAMdisk name. If the `name` option has been modified, swap `wpr` for the value specified in the options._
158
159On MacOS:
160
161```console
162$ umount /Volumes/wpr
163$ hdiutil detach /Volumes/wpr
164```
165
166On Linux:
167
168```console
169$ sudo umount /mnt/wpr
170```
171
172## Meta
173
174[CONTRIBUTING](./.github/CONTRIBUTING.md)
175
176[LICENSE (Mozilla Public License)](./LICENSE)