index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = loader;
  6. exports.raw = void 0;
  7. var _path = _interopRequireDefault(require("path"));
  8. var _loaderUtils = _interopRequireDefault(require("loader-utils"));
  9. var _schemaUtils = _interopRequireDefault(require("schema-utils"));
  10. var _options = _interopRequireDefault(require("./options.json"));
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. function loader(content) {
  13. const options = _loaderUtils.default.getOptions(this) || {};
  14. (0, _schemaUtils.default)(_options.default, options, 'File Loader');
  15. const context = options.context || this.rootContext;
  16. const url = _loaderUtils.default.interpolateName(this, options.name, {
  17. context,
  18. content,
  19. regExp: options.regExp
  20. });
  21. let outputPath = url;
  22. if (options.outputPath) {
  23. if (typeof options.outputPath === 'function') {
  24. outputPath = options.outputPath(url, this.resourcePath, context);
  25. } else {
  26. outputPath = _path.default.posix.join(options.outputPath, url);
  27. }
  28. }
  29. let publicPath = `__webpack_public_path__ + ${JSON.stringify(outputPath)}`;
  30. if (options.publicPath) {
  31. if (typeof options.publicPath === 'function') {
  32. publicPath = options.publicPath(url, this.resourcePath, context);
  33. } else {
  34. publicPath = `${options.publicPath.endsWith('/') ? options.publicPath : `${options.publicPath}/`}${url}`;
  35. }
  36. publicPath = JSON.stringify(publicPath);
  37. }
  38. if (typeof options.emitFile === 'undefined' || options.emitFile) {
  39. this.emitFile(outputPath, content);
  40. } // TODO revert to ES2015 Module export, when new CSS Pipeline is in place
  41. return `module.exports = ${publicPath};`;
  42. }
  43. const raw = true;
  44. exports.raw = raw;