Skip to content

Commit

Permalink
feat(index): add interpolation support (loaderUtils.interpolateName) (
Browse files Browse the repository at this point in the history
  • Loading branch information
Glinkis authored and michael-ciniawsky committed Feb 5, 2018
1 parent 2923f64 commit 201de63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ require("exports-loader?file,parse=helpers.parse!./file.js");
require("exports-loader?file!./file.js");
// adds below code to the file's source:
// module.exports = file;

require("exports-loader?[name]!./file.js");
// adds below code to the file's source:
// module.exports = file;
```

<h2 align="center">Maintainers</h2>
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module.exports = function(content, sourceMap) {
var query = loaderUtils.getOptions(this) || {};
var exports = [];
var keys = Object.keys(query);
// apply name interpolation i.e. substitute strings like [name] or [ext]
for (var i = 0; i < keys.length; i++) {
keys[i] = loaderUtils.interpolateName(this, keys[i], {});
};
if(keys.length == 1 && typeof query[keys[0]] == "boolean") {
exports.push("module.exports = " + keys[0] + ";");
} else {
Expand Down

0 comments on commit 201de63

Please sign in to comment.