Skip to content

Commit e9de712

Browse files
evan-clearykisenka
authored andcommitted
Add support for regExp pattern in the loader-util name interpolator
1 parent fb46af3 commit e9de712

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ yarn add svg-sprite-loader -D
9292
How `<symbol>` `id` attribute should be named.
9393
Complete list of supported patterns: [loader-utils#interpolatename docs](https://github.com/webpack/loader-utils#interpolatename).
9494

95+
### `symbolRegExp` (default `''`)
96+
Passed to the symbolId interpolator to support the [N] pattern in the loader-utils name interpolator
97+
9598
### `esModule` (default `true`, autoconfigured)
9699

97100
Generated export format:

lib/config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ module.exports = {
2020
*/
2121
symbolId: '[name]',
2222

23+
/**
24+
* Regular expression passed to interpolateName.
25+
* Supports the interpolateName [N] pattern inserting the N-th match.
26+
* @type {string}
27+
*/
28+
symbolRegExp: '',
29+
2330
/**
2431
* Path to Node.js module which generates client runtime.
2532
* @type {string}

lib/loader.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ module.exports = function loader(content) {
6060
}
6161

6262
const idPattern = config.symbolId + (resourceQuery ? `--${urlSlug(resourceQuery)}` : '');
63-
const id = interpolateName(loaderContext, idPattern, { content, context: compiler.context });
63+
const id = interpolateName(loaderContext, idPattern, {
64+
content,
65+
context: compiler.context,
66+
regExp: config.symbolRegExp
67+
});
6468

6569
svgCompiler.addSymbol({ id, content, path: resourcePath + resourceQuery })
6670
.then((symbol) => {

0 commit comments

Comments
 (0)