stylePostLoader.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  5. }) : (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. o[k2] = m[k];
  8. }));
  9. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  10. Object.defineProperty(o, "default", { enumerable: true, value: v });
  11. }) : function(o, v) {
  12. o["default"] = v;
  13. });
  14. var __importStar = (this && this.__importStar) || function (mod) {
  15. if (mod && mod.__esModule) return mod;
  16. var result = {};
  17. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  18. __setModuleDefault(result, mod);
  19. return result;
  20. };
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. const qs = __importStar(require("querystring"));
  23. const compiler_1 = require("./compiler");
  24. const { compileStyle } = compiler_1.compiler;
  25. // This is a post loader that handles scoped CSS transforms.
  26. // Injected right before css-loader by the global pitcher (../pitch.js)
  27. // for any <style scoped> selection requests initiated from within vue files.
  28. const StylePostLoader = function (source, inMap) {
  29. const query = qs.parse(this.resourceQuery.slice(1));
  30. // skip normal CSS files without scoped flag
  31. if (!('vue' in query) ||
  32. query.type !== 'style' ||
  33. !query.id ||
  34. !query.scoped) {
  35. this.callback(null, source, inMap);
  36. return;
  37. }
  38. const { code, map, errors } = compileStyle({
  39. source: source,
  40. filename: this.resourcePath,
  41. id: `data-v-${query.id}`,
  42. map: inMap,
  43. scoped: !!query.scoped,
  44. trim: true,
  45. isProd: this.mode === 'production' || process.env.NODE_ENV === 'production',
  46. });
  47. if (errors.length) {
  48. this.callback(errors[0]);
  49. }
  50. else {
  51. this.callback(null, code, map);
  52. }
  53. };
  54. exports.default = StylePostLoader;