webpack-inject-manifest.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. /*
  3. Copyright 2019 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. const joi = require('@hapi/joi');
  9. const upath = require('upath');
  10. const basePartial = require('../partials/base');
  11. const defaults = require('../defaults');
  12. const injectPartial = require('../partials/inject');
  13. const webpackPartial = require('../partials/webpack'); // See https://github.com/hapijs/joi/blob/v16.0.0-rc2/API.md#anydefaultvalue-description
  14. const swSrcBasename = context => {
  15. const {
  16. name
  17. } = upath.parse(context.swSrc); // Always use the .js extension when generating a default filename.
  18. return name + '.js';
  19. };
  20. swSrcBasename.description = 'derived from the swSrc file name';
  21. const supportedOptions = Object.assign({
  22. compileSrc: joi.boolean().default(defaults.compileSrc),
  23. webpackCompilationPlugins: joi.array().items(joi.object()).when('compileSrc', {
  24. is: false,
  25. then: joi.forbidden()
  26. })
  27. }, basePartial, injectPartial, webpackPartial);
  28. module.exports = joi.object().keys(supportedOptions).keys({
  29. // List this separately, so that the swSrc validation happens first.
  30. swDest: joi.string().default(swSrcBasename)
  31. });