diff --git a/.gitignore b/.gitignore index 3091757a..0c79f8d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +/.idea/ node_modules -coverage \ No newline at end of file +coverage diff --git a/lib/getLocalIdent.js b/lib/getLocalIdent.js index 7321669d..c10e407a 100644 --- a/lib/getLocalIdent.js +++ b/lib/getLocalIdent.js @@ -2,14 +2,25 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ +var path = require("path"); var loaderUtils = require("loader-utils"); module.exports = function getLocalIdent(loaderContext, localIdentName, localName, options) { + if (!( /^[a-z]/.test(localName) )) return localName; var request = loaderContext.options && typeof loaderContext.options.context === "string" ? loaderUtils.stringifyRequest({ context: loaderContext.options.context }, loaderUtils.getRemainingRequest(loaderContext)) : loaderContext.request; options.content = localName + " " + request; options.context = loaderContext.options && typeof loaderContext.options.context === "string" ? loaderContext.options.context : loaderContext.context; - localIdentName = localIdentName.replace(/\[local\]/gi, localName); + if (localName === 'root') { + localIdentName = localIdentName.replace(/[_-]?\[local\]/gi, ''); + } else { + localIdentName = localIdentName.replace(/\[local\]/gi, localName); + } + var componentName = path.basename(loaderContext.resourcePath, path.extname(loaderContext.resourcePath)); + if (componentName === 'index' || /^_/.test(componentName)) { + componentName = path.basename(path.dirname(loaderContext.resourcePath)) + } + localIdentName = localIdentName.replace(/\[component\]/gi, componentName); var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options); return hash.replace(/[^a-zA-Z0-9\-_]/g, "-").replace(/^([^a-zA-Z_])/, "_$1"); };