diff --git a/README.md b/README.md index 2f75372..e25fb32 100644 --- a/README.md +++ b/README.md @@ -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`
+Type: `boolean | Object`
Default: `false`
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. diff --git a/lib/index.js b/lib/index.js index 7c77962..85d88f7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) { diff --git a/lib/plugins/ramdisk.js b/lib/plugins/ramdisk.js index 90a078a..9bd4472 100644 --- a/lib/plugins/ramdisk.js +++ b/lib/plugins/ramdisk.js @@ -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 ); @@ -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); diff --git a/lib/validate.js b/lib/validate.js index 5fb1016..2fe1003 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -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: [ diff --git a/package-lock.json b/package-lock.json index 1fab283..372cdb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2463,6 +2463,12 @@ "is-data-descriptor": "^1.0.0", "kind-of": "^6.0.2" } + }, + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true } } }, @@ -2648,6 +2654,12 @@ "requires": { "is-extendable": "^0.1.0" } + }, + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true } } }, @@ -2832,6 +2844,14 @@ "to-object-path": "^0.3.0", "union-value": "^1.0.0", "unset-value": "^1.0.0" + }, + "dependencies": { + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true + } } }, "cache-content-type": { @@ -3109,6 +3129,12 @@ "requires": { "is-descriptor": "^0.1.0" } + }, + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true } } }, @@ -4025,6 +4051,12 @@ "is-data-descriptor": "^1.0.0", "kind-of": "^6.0.2" } + }, + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true } } }, @@ -6516,6 +6548,14 @@ "get-value": "^2.0.6", "has-values": "^1.0.0", "isobject": "^3.0.0" + }, + "dependencies": { + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true + } } }, "has-values": { @@ -7307,6 +7347,14 @@ "dev": true, "requires": { "isobject": "^3.0.1" + }, + "dependencies": { + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true + } } }, "is-promise": { @@ -7400,12 +7448,6 @@ "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" }, - "isobject": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", - "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", - "dev": true - }, "istanbul-lib-coverage": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.0.0.tgz", @@ -9567,6 +9609,14 @@ "dev": true, "requires": { "isobject": "^3.0.0" + }, + "dependencies": { + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true + } } }, "object.assign": { @@ -9588,6 +9638,14 @@ "dev": true, "requires": { "isobject": "^3.0.1" + }, + "dependencies": { + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true + } } }, "object.values": { @@ -11159,6 +11217,12 @@ "is-data-descriptor": "^1.0.0", "kind-of": "^6.0.2" } + }, + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true } } }, @@ -12060,6 +12124,12 @@ "resolved": "https://registry.npmjs.org/has-values/-/has-values-0.1.4.tgz", "integrity": "sha1-bWHeldkd/Km5oCCJrThL/49it3E=", "dev": true + }, + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true } } }, diff --git a/test/fixtures/ramdisk/custom-options.js b/test/fixtures/ramdisk/custom-options.js new file mode 100644 index 0000000..0961acf --- /dev/null +++ b/test/fixtures/ramdisk/custom-options.js @@ -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 +}; diff --git a/test/ramdisk.test.js b/test/ramdisk.test.js index 386bf5c..8bfd5eb 100644 --- a/test/ramdisk.test.js +++ b/test/ramdisk.test.js @@ -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'], {