Skip to content

Commit

Permalink
Add support for regExp pattern in the loader-util name interpolator
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-cleary authored and kisenka committed Jul 31, 2017
1 parent fb46af3 commit e9de712
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ yarn add svg-sprite-loader -D
How `<symbol>` `id` attribute should be named.
Complete list of supported patterns: [loader-utils#interpolatename docs](https://github.com/webpack/loader-utils#interpolatename).

### `symbolRegExp` (default `''`)
Passed to the symbolId interpolator to support the [N] pattern in the loader-utils name interpolator

### `esModule` (default `true`, autoconfigured)

Generated export format:
Expand Down
7 changes: 7 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ module.exports = {
*/
symbolId: '[name]',

/**
* Regular expression passed to interpolateName.
* Supports the interpolateName [N] pattern inserting the N-th match.
* @type {string}
*/
symbolRegExp: '',

/**
* Path to Node.js module which generates client runtime.
* @type {string}
Expand Down
6 changes: 5 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ module.exports = function loader(content) {
}

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

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

0 comments on commit e9de712

Please sign in to comment.