Skip to content

Commit e078772

Browse files
committed
Update addLoader to take a raw loader config object
1 parent b21f7aa commit e078772

File tree

5 files changed

+20
-32
lines changed

5 files changed

+20
-32
lines changed

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <fabien@symfony.com>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
110
'use strict';
211

312
const WebpackConfig = require('./lib/WebpackConfig');

lib/WebpackConfig.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class WebpackConfig {
4949
this.providedVariables = {};
5050
this.babelConfigurationCallback = function() {};
5151
this.useReact = false;
52-
this.loaders = new Set();
52+
this.loaders = [];
5353
}
5454

5555
getContext() {
@@ -158,8 +158,8 @@ class WebpackConfig {
158158
this.styleEntries.set(name, src);
159159
}
160160

161-
addLoader(test, use, options = { include: null, exclude: null }) {
162-
this.loaders.add({ 'test': test, 'use': use, 'include': options.include || null, 'exclude': options.exclude || null });
161+
addLoader(loader) {
162+
this.loaders.push(loader);
163163
}
164164

165165
enableVersioning(enabled = true) {

lib/config-generator.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,9 @@ class ConfigGenerator {
235235
});
236236
}
237237

238-
if (this.webpackConfig.loaders.size > 0) {
239-
this.webpackConfig.loaders.forEach((loader) => {
240-
rules.push(loader);
241-
});
242-
}
238+
this.webpackConfig.loaders.forEach((loader) => {
239+
rules.push(loader);
240+
});
243241

244242
return rules;
245243
}

test/WebpackConfig.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,9 @@ describe('WebpackConfig object', () => {
281281
it('Adds a new loader with default options', () => {
282282
const config = createConfig();
283283

284-
config.addLoader(/\.custom$/, 'custom-loader');
284+
config.addLoader({ 'test': /\.custom$/, 'loader': 'custom-loader' });
285285

286-
expect(Array.from(config.loaders)).to.deep.equals([{ 'test': /\.custom$/, 'use': 'custom-loader', 'include': null, 'exclude': null }]);
287-
});
288-
289-
it('Adds a custom exclude path', () => {
290-
const config = createConfig();
291-
292-
config.addLoader(/\.custom$/, 'custom-loader', { 'exclude': 'node_modules' });
293-
294-
expect(Array.from(config.loaders)).to.deep.equals([{ 'test': /\.custom$/, 'use': 'custom-loader', 'include': null, 'exclude': 'node_modules' }]);
286+
expect(Array.from(config.loaders)).to.deep.equals([{ 'test': /\.custom$/, 'loader': 'custom-loader' }]);
295287
});
296288
});
297289
});

test/config-generator.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,27 +348,16 @@ describe('The config-generator function', () => {
348348
});
349349
});
350350

351-
describe('addLoader() adds custom rules', () => {
351+
describe('addLoader() adds a custom loader', () => {
352352
it('addLoader()', () => {
353353
const config = createConfig();
354354
config.outputPath = '/tmp/output/public-path';
355355
config.publicPath = '/public-path';
356-
config.addLoader(/\.custom$/, 'custom-loader');
356+
config.addLoader({ 'test': /\.custom$/, 'loader': 'custom-loader' });
357357

358358
const actualConfig = configGenerator(config);
359359

360-
expect(actualConfig.module.rules).to.deep.include({ 'test': /\.custom$/, 'use': 'custom-loader', 'include': null, 'exclude': null });
361-
});
362-
363-
it('addLoader() with custom exlude path', () => {
364-
const config = createConfig();
365-
config.outputPath = '/tmp/output/public-path';
366-
config.publicPath = '/public-path';
367-
config.addLoader(/\.custom$/, 'custom-loader', { 'exclude': 'node_modules' });
368-
369-
const actualConfig = configGenerator(config);
370-
371-
expect(actualConfig.module.rules).to.deep.include({ 'test': /\.custom$/, 'use': 'custom-loader', 'include': null, 'exclude': 'node_modules' });
360+
expect(actualConfig.module.rules).to.deep.include({ 'test': /\.custom$/, 'loader': 'custom-loader' });
372361
});
373362
});
374363

0 commit comments

Comments
 (0)