HarmonyModulesHelpers.js 933 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. class HarmonyModulesHelpers {
  7. static getModuleVar(state, request) {
  8. if(!state.harmonyModules) state.harmonyModules = [];
  9. let idx = state.harmonyModules.indexOf(request);
  10. if(idx < 0) {
  11. idx = state.harmonyModules.length;
  12. state.harmonyModules.push(request);
  13. }
  14. return `__WEBPACK_IMPORTED_MODULE_${idx}_${request.replace(/[^A-Za-z0-9_]/g, "_").replace(/__+/g, "_")}__`;
  15. }
  16. static getNewModuleVar(state, request) {
  17. if(state.harmonyModules && state.harmonyModules.indexOf(request) >= 0)
  18. return null;
  19. return this.getModuleVar(state, request);
  20. }
  21. static checkModuleVar(state, request) {
  22. if(!state.harmonyModules || state.harmonyModules.indexOf(request) < 0)
  23. return null;
  24. return this.getModuleVar(state, request);
  25. }
  26. }
  27. module.exports = HarmonyModulesHelpers;