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.

23 lines
982 B

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. var loaderUtils = require("loader-utils");
  6. var path = require("path");
  7. module.exports = function getLocalIdent(loaderContext, localIdentName, localName, options) {
  8. if(!options.context) {
  9. if (loaderContext.rootContext) {
  10. options.context = loaderContext.rootContext;
  11. } else if (loaderContext.options && typeof loaderContext.options.context === "string") {
  12. options.context = loaderContext.options.context;
  13. } else {
  14. options.context = loaderContext.context;
  15. }
  16. }
  17. var request = path.relative(options.context, loaderContext.resourcePath);
  18. options.content = options.hashPrefix + request + "+" + localName;
  19. localIdentName = localIdentName.replace(/\[local\]/gi, localName);
  20. var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options);
  21. return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^((-?[0-9])|--)/, "_$1");
  22. };