Skip to content

Commit 5e942da

Browse files
committed
Add support for [component] in name interpolation for module mode
1 parent 2460b9d commit 5e942da

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/getLocalIdent.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
var path = require("path");
56
var loaderUtils = require("loader-utils");
67
module.exports = function getLocalIdent(loaderContext, localIdentName, localName, options) {
78
if (!( /^[a-z]/.test(localName) )) return localName;
@@ -11,6 +12,11 @@ module.exports = function getLocalIdent(loaderContext, localIdentName, localName
1112
options.content = localName + " " + request;
1213
options.context = loaderContext.options && typeof loaderContext.options.context === "string" ? loaderContext.options.context : loaderContext.context;
1314
localIdentName = localIdentName.replace(/\[local\]/gi, localName);
15+
var componentName = path.basename(loaderContext.resourcePath, path.extname(loaderContext.resourcePath));
16+
if (componentName === 'index' || /^_/.test(componentName)) {
17+
componentName = path.basename(path.dirname(loaderContext.resourcePath))
18+
}
19+
localIdentName = localIdentName.replace(/\[component\]/gi, componentName);
1420
var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options);
1521
return hash.replace(/[^a-zA-Z0-9\-_]/g, "-").replace(/^([^a-zA-Z_])/, "_$1");
1622
};

0 commit comments

Comments
 (0)