cssModules.js 697 B

123456789101112131415161718192021
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.genCSSModulesCode = void 0;
  4. function genCSSModulesCode(id, index, request, moduleName, needsHotReload) {
  5. const styleVar = `style${index}`;
  6. let code = `\nimport ${styleVar} from ${request}`;
  7. // inject variable
  8. const name = typeof moduleName === 'string' ? moduleName : '$style';
  9. code += `\ncssModules["${name}"] = ${styleVar}`;
  10. if (needsHotReload) {
  11. code += `
  12. if (module.hot) {
  13. module.hot.accept(${request}, () => {
  14. cssModules["${name}"] = ${styleVar}
  15. __VUE_HMR_RUNTIME__.rerender("${id}")
  16. })
  17. }`;
  18. }
  19. return code;
  20. }
  21. exports.genCSSModulesCode = genCSSModulesCode;