From 3564ee52cdf3a65a751993435386cff430d1a755 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 12 Sep 2020 22:05:51 +0200 Subject: [PATCH] Allow omitting options to plugin-webpack (#1047) It makes the developer experience slightly better, since if you don't provide an empty object, you'll get the `TypeError: Cannot read property 'mode' of undefined`. --- plugins/plugin-webpack/README.md | 23 +++++++++++++++++++---- plugins/plugin-webpack/plugin.js | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/plugin-webpack/README.md b/plugins/plugin-webpack/README.md index 015847ef61..731f44ac88 100644 --- a/plugins/plugin-webpack/README.md +++ b/plugins/plugin-webpack/README.md @@ -2,20 +2,35 @@ Use Webpack to bundle your application for production. +### Install + ``` npm install --save-dev @snowpack/plugin-webpack ``` -```js -// snowpack.config.json +### Usage + +Add `@snowpack/plugin-webpack` to `snowpack.config.json`: + +```json { - "plugins": [["@snowpack/plugin-webpack", { /* see "Plugin Options" below */}]] + "plugins": [["@snowpack/plugin-webpack", { /* see "Plugin Options" below */ }]] } ``` -#### Default Build Script +or to `snowpack.config.js`: ```js +module.exports = { + plugins: [["@snowpack/plugin-webpack", { /* see "Plugin Options" below */ }]] +} +``` + +The options object is optional. + +### Default Build Script + +```json { "scripts": {"bundle:*": "@snowpack/plugin-webpack"} } diff --git a/plugins/plugin-webpack/plugin.js b/plugins/plugin-webpack/plugin.js index 08565a5908..5072c3ed27 100644 --- a/plugins/plugin-webpack/plugin.js +++ b/plugins/plugin-webpack/plugin.js @@ -154,7 +154,7 @@ function getSplitChunksConfig({ numEntries }) { }; } -module.exports = function plugin(config, args) { +module.exports = function plugin(config, args = {}) { // Deprecated: args.mode if (args.mode && args.mode !== "production") { throw new Error("args.mode support has been removed.");