getOptions.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. 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; }
  3. 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; }
  4. const loaderUtils = require('loader-utils');
  5. const clone = require('clone');
  6. const createWebpackLessPlugin = require('./createWebpackLessPlugin');
  7. /**
  8. * Retrieves the options from the loaderContext, makes a deep copy of it and normalizes it for further consumption.
  9. *
  10. * @param {LoaderContext} loaderContext
  11. */
  12. function getOptions(loaderContext) {
  13. const options = _objectSpread({
  14. plugins: [],
  15. relativeUrls: true
  16. }, clone(loaderUtils.getOptions(loaderContext))); // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
  17. options.filename = loaderContext.resource; // When no paths are given, we use the webpack resolver
  18. if ('paths' in options === false) {
  19. // It's safe to mutate the array now because it has already been cloned
  20. options.plugins.push(createWebpackLessPlugin(loaderContext));
  21. }
  22. if (options.sourceMap) {
  23. if (typeof options.sourceMap === 'boolean') {
  24. options.sourceMap = {};
  25. }
  26. if ('outputSourceFiles' in options.sourceMap === false) {
  27. // Include source files as `sourceContents` as sane default since this makes source maps "just work" in most cases
  28. options.sourceMap.outputSourceFiles = true;
  29. }
  30. }
  31. return options;
  32. }
  33. module.exports = getOptions;