Skip to content

Commit

Permalink
fix(loader): #187 support rule.oneOf config
Browse files Browse the repository at this point in the history
  • Loading branch information
CXHtml authored and kisenka committed Sep 27, 2017
1 parent a1ae646 commit 75df92e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/utils/get-loader-options.js
Expand Up @@ -8,7 +8,16 @@ const isWebpack1 = require('./is-webpack-1');
* @return {Object|null}
*/
function getLoaderOptions(loaderPath, rule) {
const multiRuleProp = isWebpack1 ? 'loaders' : 'use';
let multiRuleProp;

if (isWebpack1) {
multiRuleProp = 'loaders';
} else if (rule.oneOf) {
multiRuleProp = 'oneOf';
} else {
multiRuleProp = 'use';
}

const multiRule = typeof rule === 'object' && Array.isArray(rule[multiRuleProp]) ? rule[multiRuleProp] : null;
let options;

Expand Down
22 changes: 22 additions & 0 deletions test/loader.test.js
Expand Up @@ -389,5 +389,27 @@ describe('loader and plugin', () => {
it('should emit only built chunks', () => {
// TODO test with webpack-recompilation-emulator
});

if (!webpackVersion.IS_1) {
it('should allow to generate specify svg sprite with rule.oneOf config', async () => {
const { assets } = await compile({
entry: './styles.css',
module: rules(
{
test: /\.svg$/,
oneOf: [
{ loader: loaderPath, options: { extract: true, spriteFilename: '[sha1:hash:base36:10].svg' } },
{ loader: 'svgo-loader' }
]
},
cssRule()
),
plugins: [new SpritePlugin()]
});

Object.keys(assets).should.be.lengthOf(2);
assets.should.have.property('lvn29bpor3.svg');
});
}
});
});

0 comments on commit 75df92e

Please sign in to comment.