Skip to content

Commit

Permalink
fix(loader): interpolate sprite filename properly
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #174
  • Loading branch information
kisenka committed Aug 10, 2017
1 parent 6cd87c9 commit b17e5e0
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 43 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ yarn add svg-sprite-loader -D

### `symbolId` (default `[name]`)

How `<symbol>` `id` attribute should be named.
Complete list of supported patterns: [loader-utils#interpolatename docs](https://github.com/webpack/loader-utils#interpolatename).
How `<symbol>` `id` attribute should be named. All patterns from [loader-utils#interpolateName](https://github.com/webpack/loader-utils#interpolatename)
are supported.

### `symbolRegExp` (default `''`)
Passed to the symbolId interpolator to support the [N] pattern in the loader-utils name interpolator
Expand Down Expand Up @@ -221,8 +221,8 @@ module: {
}
```

It is also possible to generate sprite for each chunk by using `[chunkname]` pattern in spriteFilename option.
This is experimental feature, so use with caution!
All patterns from [loader-utils#interpolateName](https://github.com/webpack/loader-utils#interpolatename) are supported.
It is also possible to generate sprite for each chunk by using `[chunkname]` pattern in spriteFilename option. This is experimental feature, use it with caution!

## Examples

Expand Down
28 changes: 0 additions & 28 deletions lib/utils/hash-tokens.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports.getMatchedRule = require('./get-matched-rule');
module.exports.getMatchedRules = require('./get-matched-rules');
module.exports.getModuleChunk = require('./get-module-chunk');
module.exports.getWebpackVersion = require('./get-webpack-version');
module.exports.hashTokens = require('./hash-tokens');
module.exports.isModuleShouldBeExtracted = require('./is-module-should-be-extracted');
module.exports.interpolate = require('./interpolate');
module.exports.isWebpack1 = require('./is-webpack-1');
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/mapped-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class MappedList {
const filenames = Object.keys(itemsBySpriteFilename);

filenames.forEach((filename) => {
if (!filename.includes('[hash')) {
if (!filename.includes('hash')) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ describe('loader and plugin', () => {
const { assets } = await compile({
entry: './entry',
module: rules(
svgRule({ extract: true, spriteFilename: 'sprite-[hash:8].svg' })
svgRule({ extract: true, spriteFilename: '[sha1:hash:base36:10].svg' })
),
plugins: [new SpritePlugin()]
});

assets.should.have.property('sprite-55f2b4ab.svg');
assets.should.have.property('lvn29bpor3.svg');
});

// Fails when webpack buildin runtime will change
Expand Down
7 changes: 0 additions & 7 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,4 @@ describe('utils', () => {
getLoadersRules(compilerMock).should.be.deep.equal(rules);
});
});

describe('hashTokens', () => {
it('should work', () => {
const result = hashTokens('content-[customhash:6]', { customhash: '123' });
result.should.be.equals('content-202cb9');
});
});
});

0 comments on commit b17e5e0

Please sign in to comment.