index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. var _compose = require("./compose");
  3. var _optional = require("./optional");
  4. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  5. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  6. /**
  7. * Composes all plugins together.
  8. *
  9. * @param {array} plugins - all plugins to load and initialize
  10. * @param {object} nextConfig - direct configuration for next.js (optional)
  11. */
  12. const _withPlugins = ([...plugins], nextConfig = {}) => (phase, {
  13. defaultConfig
  14. }) => {
  15. const config = _objectSpread({}, defaultConfig, nextConfig);
  16. return (0, _compose.composePlugins)(phase, plugins, config);
  17. };
  18. /**
  19. * Extends a base next config.
  20. *
  21. * @param {function} baseConfig - basic configuration
  22. */
  23. const extend = baseConfig => ({
  24. withPlugins: (...params) => (phase, nextOptions) => {
  25. const processedBaseConfig = baseConfig(phase, nextOptions);
  26. return _withPlugins(...params)(phase, _objectSpread({}, nextOptions, {
  27. defaultConfig: processedBaseConfig
  28. }));
  29. }
  30. }); // define exports
  31. const _exports = _withPlugins;
  32. _exports.withPlugins = _withPlugins;
  33. _exports.optional = _optional.markOptional;
  34. _exports.extend = extend;
  35. module.exports = _exports;