Skip to content

Commit d975d80

Browse files
committed
Split disableAssetsLoaders into disableImagesLoader and disableFontsLoader
1 parent 1b776ce commit d975d80

File tree

6 files changed

+84
-19
lines changed

6 files changed

+84
-19
lines changed

index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,24 @@ module.exports = {
404404

405405
/**
406406
* Call this if you wish to disable the default
407-
* assets loaders (images and fonts).
407+
* images loader.
408408
*
409409
* @returns {exports}
410410
*/
411-
disableAssetsLoaders() {
412-
webpackConfig.disableAssetsLoaders();
411+
disableImagesLoader() {
412+
webpackConfig.disableImagesLoader();
413+
414+
return this;
415+
},
416+
417+
/**
418+
* Call this if you wish to disable the default
419+
* fonts loader.
420+
*
421+
* @returns {exports}
422+
*/
423+
disableFontsLoader() {
424+
webpackConfig.disableFontsLoader();
413425

414426
return this;
415427
},

lib/WebpackConfig.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class WebpackConfig {
5656
this.loaders = [];
5757
this.useTypeScriptLoader = false;
5858
this.tsConfigurationCallback = function() {};
59-
this.useAssetsLoaders = true;
59+
this.useImagesLoader = true;
60+
this.useFontsLoader = true;
6061
}
6162

6263
getContext() {
@@ -249,8 +250,12 @@ class WebpackConfig {
249250
this.vueLoaderOptionsCallback = vueLoaderOptionsCallback;
250251
}
251252

252-
disableAssetsLoaders() {
253-
this.useAssetsLoaders = false;
253+
disableImagesLoader() {
254+
this.useImagesLoader = false;
255+
}
256+
257+
disableFontsLoader() {
258+
this.useFontsLoader = false;
254259
}
255260

256261
cleanupOutputBeforeBuild() {

lib/config-generator.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class ConfigGenerator {
125125
}
126126
];
127127

128-
if (this.webpackConfig.useAssetsLoaders) {
128+
if (this.webpackConfig.useImagesLoader) {
129129
rules.push({
130130
test: /\.(png|jpg|jpeg|gif|ico|svg)$/,
131131
loader: 'file-loader',
@@ -134,7 +134,9 @@ class ConfigGenerator {
134134
publicPath: this.webpackConfig.getRealPublicPath()
135135
}
136136
});
137+
}
137138

139+
if (this.webpackConfig.useFontsLoader) {
138140
rules.push({
139141
test: /\.(woff|woff2|ttf|eot|otf)$/,
140142
loader: 'file-loader',

test/WebpackConfig.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,21 @@ describe('WebpackConfig object', () => {
388388
});
389389
});
390390

391-
describe('disableAssetsLoaders', () => {
392-
it('Disable default assets loaders', () => {
391+
describe('disableImagesLoader', () => {
392+
it('Disable default images loader', () => {
393393
const config = createConfig();
394-
config.disableAssetsLoaders();
394+
config.disableImagesLoader();
395395

396-
expect(config.useAssetsLoaders).to.be.false;
396+
expect(config.useImagesLoader).to.be.false;
397+
});
398+
});
399+
400+
describe('disableFontsLoader', () => {
401+
it('Disable default fonts loader', () => {
402+
const config = createConfig();
403+
config.disableFontsLoader();
404+
405+
expect(config.useFontsLoader).to.be.false;
397406
});
398407
});
399408
});

test/config-generator.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,33 +417,61 @@ describe('The config-generator function', () => {
417417
});
418418
});
419419

420-
describe('disableAssetsLoaders() removes the default assets loaders', () => {
421-
it('without disableAssetsLoaders()', () => {
420+
describe('disableImagesLoader() removes the default images loader', () => {
421+
it('without disableImagesLoader()', () => {
422422
const config = createConfig();
423423
config.outputPath = '/tmp/output/public-path';
424424
config.publicPath = '/public-path';
425425
config.addEntry('main', './main');
426-
// do not call disableAssetsLoaders
426+
// do not call disableImagesLoader
427427

428428
const actualConfig = configGenerator(config);
429429

430430
expect(function() {
431431
findRule(/\.(png|jpg|jpeg|gif|ico|svg)$/, actualConfig.module.rules);
432-
findRule(/\.(woff|woff2|ttf|eot|otf)$/, actualConfig.module.rules);
433432
}).to.not.throw();
434433
});
435434

436-
it('with disableAssetsLoaders()', () => {
435+
it('with disableImagesLoader()', () => {
437436
const config = createConfig();
438437
config.outputPath = '/tmp/output/public-path';
439438
config.publicPath = '/public-path';
440439
config.addEntry('main', './main');
441-
config.disableAssetsLoaders();
440+
config.disableImagesLoader();
442441

443442
const actualConfig = configGenerator(config);
444443

445444
expect(function() {
446445
findRule(/\.(png|jpg|jpeg|gif|ico|svg)$/, actualConfig.module.rules);
446+
}).to.throw();
447+
});
448+
});
449+
450+
describe('disableFontsLoader() removes the default fonts loader', () => {
451+
it('without disableFontsLoader()', () => {
452+
const config = createConfig();
453+
config.outputPath = '/tmp/output/public-path';
454+
config.publicPath = '/public-path';
455+
config.addEntry('main', './main');
456+
// do not call disableFontsLoader
457+
458+
const actualConfig = configGenerator(config);
459+
460+
expect(function() {
461+
findRule(/\.(woff|woff2|ttf|eot|otf)$/, actualConfig.module.rules);
462+
}).to.not.throw();
463+
});
464+
465+
it('with disableFontsLoader()', () => {
466+
const config = createConfig();
467+
config.outputPath = '/tmp/output/public-path';
468+
config.publicPath = '/public-path';
469+
config.addEntry('main', './main');
470+
config.disableFontsLoader();
471+
472+
const actualConfig = configGenerator(config);
473+
474+
expect(function() {
447475
findRule(/\.(woff|woff2|ttf|eot|otf)$/, actualConfig.module.rules);
448476
}).to.throw();
449477
});

test/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,19 @@ describe('Public API', () => {
195195

196196
});
197197

198-
describe('disableAssetsLoaders', () => {
198+
describe('disableImagesLoader', () => {
199199

200200
it('must return the API object', () => {
201-
const returnedValue = api.disableAssetsLoaders();
201+
const returnedValue = api.disableImagesLoader();
202+
expect(returnedValue).to.equal(api);
203+
});
204+
205+
});
206+
207+
describe('disableFontsLoader', () => {
208+
209+
it('must return the API object', () => {
210+
const returnedValue = api.disableFontsLoader();
202211
expect(returnedValue).to.equal(api);
203212
});
204213

0 commit comments

Comments
 (0)