Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ If [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), the modul
If a value of `'minimal'` is set, the progress indicator will render as a small, colored bar at the top of the window. This can be useful when the default fancy progress indicator interferes with elements in the page.

### `ramdisk`
Type: `boolean`<br>
Type: `boolean | Object`<br>
Default: `false`<br>
Support: MacOS and Linux, Windows with WSL 2.0.

If `true`, will apply [`webpack-plugin-ramdisk`](https://www.npmjs.com/package/webpack-plugin-ramdisk) to the build. `output` configuration does not have to be modified, a symlink will be created from the original output path to the output path on the ramdisk. _**Note:** This will remove an existing directory at the defined output path._
If `true` or `Object` (options), will apply [`webpack-plugin-ramdisk`](https://www.npmjs.com/package/webpack-plugin-ramdisk) to the build. `output` configuration does not have to be modified, a symlink will be created from the original output path to the output path on the ramdisk. _**Note:** This will remove an existing directory at the defined output path._

Leveraging this option can result in significant reduction of build time, which is especially useful when using `hmr: true` or `liveReload: true`. Typical build times can be cut by 25-32% or more depending on hardware and webpack configuration. This is also recommended for users with SSD, as it reduces hard disk thrashing.

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class WebpackPluginServe extends EventEmitter {
}

if (this.options.ramdisk) {
initRamdiskPlugin.call(this, compiler);
initRamdiskPlugin.call(this, compiler, this.options.ramdisk);
}

if (!this.options.static.length) {
Expand Down
7 changes: 5 additions & 2 deletions lib/plugins/ramdisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { WebpackPluginRamdisk } = require('webpack-plugin-ramdisk');
const { PluginExistsError, RamdiskPathError } = require('../errors');

module.exports = {
init(compiler) {
init(compiler, options) {
const hasPlugin = compiler.options.plugins.some(
(plugin) => plugin instanceof WebpackPluginRamdisk
);
Expand Down Expand Up @@ -75,7 +75,10 @@ module.exports = {

this.log.info(`Ramdisk enabled`);

const plugin = new WebpackPluginRamdisk({ name: 'wps' });
const defaultOptions = { name: 'wps' };
const plugin = new WebpackPluginRamdisk(
typeof options === 'object' ? { ...options, ...defaultOptions } : defaultOptions
);
plugin.apply(compiler);

rm.sync(path);
Expand Down
2 changes: 1 addition & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {
// prettier-ignore
port: [number().integer().max(65535), any().promise()],
progress: [boolean(), string().valid('minimal')],
ramdisk: [boolean()],
ramdisk: [boolean(), object()],
secure: any().forbidden(),
// prettier-ignore
static: [
Expand Down
82 changes: 76 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions test/fixtures/ramdisk/custom-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { resolve } = require('path');

const getPort = require('get-port');

const { WebpackPluginServe: Serve } = require('../../../lib/');

module.exports = {
context: __dirname,
entry: ['./app.js', 'webpack-plugin-serve/client'],
mode: 'development',
output: {
filename: './output.js',
path: resolve(__dirname, './output'),
publicPath: 'output/'
},
plugins: [
new Serve({
host: 'localhost',
port: getPort({ port: 55555 }),
ramdisk: {
bytes: 1024 * 1024
}
})
],
resolve: {
alias: {
'webpack-plugin-serve/client': resolve(__dirname, '../../../client')
}
},
watch: true
};
21 changes: 21 additions & 0 deletions test/ramdisk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ test('ramdisk', async (t) => {
proc.kill('SIGTERM');
});

test('ramdisk with options', async (t) => {
const proc = execa('wp', ['--config', 'ramdisk/custom-options.js'], {
cwd: resolve(fixturePath, '..')
});
const { stderr, stdout } = proc;
const pathTest = 'Build being written to ';
const doneTest = '[emitted]';

const path = await waitFor(pathTest, stdout);

t.regex(path, /(volumes|mnt)\/wps\/[a-f0-9]{32}\/output/i);

await waitFor(doneTest, stderr);

const exists = existsSync(join(fixturePath, 'output/output.js'));

t.truthy(exists);

proc.kill('SIGTERM');
});

test('context error', async (t) => {
try {
await execa('wp', ['--config', 'ramdisk/config-context-error.js'], {
Expand Down