web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

237 lines
7.7 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _path = _interopRequireDefault(require("path"));
  7. var _loaderUtils = _interopRequireDefault(require("loader-utils"));
  8. var _schemaUtils = _interopRequireDefault(require("schema-utils"));
  9. var _isEqualLocals = _interopRequireDefault(require("./runtime/isEqualLocals"));
  10. var _options = _interopRequireDefault(require("./options.json"));
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. const loaderApi = () => {};
  13. loaderApi.pitch = function loader(request) {
  14. const options = _loaderUtils.default.getOptions(this);
  15. (0, _schemaUtils.default)(_options.default, options, {
  16. name: 'Style Loader',
  17. baseDataPath: 'options'
  18. });
  19. const insert = typeof options.insert === 'undefined' ? '"head"' : typeof options.insert === 'string' ? JSON.stringify(options.insert) : options.insert.toString();
  20. const injectType = options.injectType || 'styleTag';
  21. const esModule = typeof options.esModule !== 'undefined' ? options.esModule : false;
  22. const namedExport = esModule && options.modules && options.modules.namedExport;
  23. const runtimeOptions = {
  24. injectType: options.injectType,
  25. attributes: options.attributes,
  26. insert: options.insert,
  27. base: options.base
  28. };
  29. switch (injectType) {
  30. case 'linkTag':
  31. {
  32. const hmrCode = this.hot ? `
  33. if (module.hot) {
  34. module.hot.accept(
  35. ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)},
  36. function() {
  37. ${esModule ? 'update(content);' : `content = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)});
  38. content = content.__esModule ? content.default : content;
  39. update(content);`}
  40. }
  41. );
  42. module.hot.dispose(function() {
  43. update();
  44. });
  45. }` : '';
  46. return `${esModule ? `import api from ${_loaderUtils.default.stringifyRequest(this, `!${_path.default.join(__dirname, 'runtime/injectStylesIntoLinkTag.js')}`)};
  47. import content from ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)};` : `var api = require(${_loaderUtils.default.stringifyRequest(this, `!${_path.default.join(__dirname, 'runtime/injectStylesIntoLinkTag.js')}`)});
  48. var content = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)});
  49. content = content.__esModule ? content.default : content;`}
  50. var options = ${JSON.stringify(runtimeOptions)};
  51. options.insert = ${insert};
  52. var update = api(content, options);
  53. ${hmrCode}
  54. ${esModule ? 'export default {}' : ''}`;
  55. }
  56. case 'lazyStyleTag':
  57. case 'lazySingletonStyleTag':
  58. {
  59. const isSingleton = injectType === 'lazySingletonStyleTag';
  60. const hmrCode = this.hot ? `
  61. if (module.hot) {
  62. if (!content.locals || module.hot.invalidate) {
  63. var isEqualLocals = ${_isEqualLocals.default.toString()};
  64. var oldLocals = ${namedExport ? 'locals' : 'content.locals'};
  65. module.hot.accept(
  66. ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)},
  67. function () {
  68. ${esModule ? `if (!isEqualLocals(oldLocals, ${namedExport ? 'locals' : 'content.locals'}, ${namedExport})) {
  69. module.hot.invalidate();
  70. return;
  71. }
  72. oldLocals = ${namedExport ? 'locals' : 'content.locals'};
  73. if (update && refs > 0) {
  74. update(content);
  75. }` : `content = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)});
  76. content = content.__esModule ? content.default : content;
  77. if (!isEqualLocals(oldLocals, content.locals)) {
  78. module.hot.invalidate();
  79. return;
  80. }
  81. oldLocals = content.locals;
  82. if (update && refs > 0) {
  83. update(content);
  84. }`}
  85. }
  86. )
  87. }
  88. module.hot.dispose(function() {
  89. if (update) {
  90. update();
  91. }
  92. });
  93. }` : '';
  94. return `${esModule ? `import api from ${_loaderUtils.default.stringifyRequest(this, `!${_path.default.join(__dirname, 'runtime/injectStylesIntoStyleTag.js')}`)};
  95. import content${namedExport ? ', * as locals' : ''} from ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)};` : `var api = require(${_loaderUtils.default.stringifyRequest(this, `!${_path.default.join(__dirname, 'runtime/injectStylesIntoStyleTag.js')}`)});
  96. var content = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)});
  97. content = content.__esModule ? content.default : content;
  98. if (typeof content === 'string') {
  99. content = [[module.id, content, '']];
  100. }`}
  101. var refs = 0;
  102. var update;
  103. var options = ${JSON.stringify(runtimeOptions)};
  104. options.insert = ${insert};
  105. options.singleton = ${isSingleton};
  106. var exported = {};
  107. ${namedExport ? '' : 'exported.locals = content.locals || {};'}
  108. exported.use = function() {
  109. if (!(refs++)) {
  110. update = api(content, options);
  111. }
  112. return exported;
  113. };
  114. exported.unuse = function() {
  115. if (refs > 0 && !--refs) {
  116. update();
  117. update = null;
  118. }
  119. };
  120. ${hmrCode}
  121. ${esModule ? `${namedExport ? `export * from ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)};` : ''};
  122. export default exported;` : 'module.exports = exported;'}
  123. `;
  124. }
  125. case 'styleTag':
  126. case 'singletonStyleTag':
  127. default:
  128. {
  129. const isSingleton = injectType === 'singletonStyleTag';
  130. const hmrCode = this.hot ? `
  131. if (module.hot) {
  132. if (!content.locals || module.hot.invalidate) {
  133. var isEqualLocals = ${_isEqualLocals.default.toString()};
  134. var oldLocals = ${namedExport ? 'locals' : 'content.locals'};
  135. module.hot.accept(
  136. ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)},
  137. function () {
  138. ${esModule ? `if (!isEqualLocals(oldLocals, ${namedExport ? 'locals' : 'content.locals'}, ${namedExport})) {
  139. module.hot.invalidate();
  140. return;
  141. }
  142. oldLocals = ${namedExport ? 'locals' : 'content.locals'};
  143. update(content);` : `content = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)});
  144. content = content.__esModule ? content.default : content;
  145. if (typeof content === 'string') {
  146. content = [[module.id, content, '']];
  147. }
  148. if (!isEqualLocals(oldLocals, content.locals)) {
  149. module.hot.invalidate();
  150. return;
  151. }
  152. oldLocals = content.locals;
  153. update(content);`}
  154. }
  155. )
  156. }
  157. module.hot.dispose(function() {
  158. update();
  159. });
  160. }` : '';
  161. return `${esModule ? `import api from ${_loaderUtils.default.stringifyRequest(this, `!${_path.default.join(__dirname, 'runtime/injectStylesIntoStyleTag.js')}`)};
  162. import content${namedExport ? ', * as locals' : ''} from ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)};` : `var api = require(${_loaderUtils.default.stringifyRequest(this, `!${_path.default.join(__dirname, 'runtime/injectStylesIntoStyleTag.js')}`)});
  163. var content = require(${_loaderUtils.default.stringifyRequest(this, `!!${request}`)});
  164. content = content.__esModule ? content.default : content;
  165. if (typeof content === 'string') {
  166. content = [[module.id, content, '']];
  167. }`}
  168. var options = ${JSON.stringify(runtimeOptions)};
  169. options.insert = ${insert};
  170. options.singleton = ${isSingleton};
  171. var update = api(content, options);
  172. ${hmrCode}
  173. ${esModule ? namedExport ? `export * from ${_loaderUtils.default.stringifyRequest(this, `!!${request}`)};` : 'export default content.locals || {};' : 'module.exports = content.locals || {};'}`;
  174. }
  175. }
  176. };
  177. var _default = loaderApi;
  178. exports.default = _default;