Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty object when adding runtimeCaching custom plugins with workbox-webpack-plugin #1598

Merged
merged 8 commits into from
Aug 9, 2018
218 changes: 191 additions & 27 deletions packages/workbox-build/package-lock.json

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

2 changes: 2 additions & 0 deletions packages/workbox-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"joi": "^11.1.1",
"lodash.template": "^4.4.0",
"pretty-bytes": "^4.0.2",
"stringify-object": "^3.2.2",
"strip-comments": "^1.0.2",
"workbox-background-sync": "^3.4.1",
"workbox-broadcast-cache-update": "^3.4.1",
"workbox-cache-expiration": "^3.4.1",
Expand Down
12 changes: 10 additions & 2 deletions packages/workbox-build/src/lib/runtime-caching-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/

const ol = require('common-tags').oneLine;

const objectStringify = require('stringify-object');
const stripComments = require('strip-comments');
const errors = require('./errors');


/**
* Given a set of options that configures `sw-toolbox`'s behavior, convert it
* into a string that would configure equivalent `workbox-sw` behavior.
Expand All @@ -31,7 +33,13 @@ const errors = require('./errors');
function getOptionsString(options = {}) {
let plugins = [];
if (options.plugins) {
plugins = options.plugins.map((plugin) => JSON.stringify(plugin));
// Using libs because JSON.stringify won't handle functions
plugins = options.plugins.map((plugin) =>
objectStringify(plugin, {
transform: (_obj, _prop, str) => stripComments(str),
})
);

delete options.plugins;
}

Expand Down
Loading