getLocalIdent.js 844 B

12345678910111213141516
  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. options.context = loaderContext.options && typeof loaderContext.options.context === "string" ? loaderContext.options.context : loaderContext.context;
  10. var request = path.relative(options.context, loaderContext.resourcePath);
  11. options.content = options.hashPrefix + request + "+" + localName;
  12. localIdentName = localIdentName.replace(/\[local\]/gi, localName);
  13. var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options);
  14. return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^((-?[0-9])|--)/, "_$1");
  15. };