Skip to content

Commit a1176d3

Browse files
committed
Split disableAssetsLoaders into disableImagesLoader and disableFontsLoader
1 parent f590ce3 commit a1176d3

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
@@ -400,12 +400,24 @@ module.exports = {
400400

401401
/**
402402
* Call this if you wish to disable the default
403-
* assets loaders (images and fonts).
403+
* images loader.
404404
*
405405
* @returns {exports}
406406
*/
407-
disableAssetsLoaders() {
408-
webpackConfig.disableAssetsLoaders();
407+
disableImagesLoader() {
408+
webpackConfig.disableImagesLoader();
409+
410+
return this;
411+
},
412+
413+
/**
414+
* Call this if you wish to disable the default
415+
* fonts loader.
416+
*
417+
* @returns {exports}
418+
*/
419+
disableFontsLoader() {
420+
webpackConfig.disableFontsLoader();
409421

410422
return this;
411423
},

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() {
@@ -254,8 +255,12 @@ class WebpackConfig {
254255
this.vueLoaderOptionsCallback = vueLoaderOptionsCallback;
255256
}
256257

257-
disableAssetsLoaders() {
258-
this.useAssetsLoaders = false;
258+
disableImagesLoader() {
259+
this.useImagesLoader = false;
260+
}
261+
262+
disableFontsLoader() {
263+
this.useFontsLoader = false;
259264
}
260265

261266
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
@@ -359,12 +359,21 @@ describe('WebpackConfig object', () => {
359359
});
360360
});
361361

362-
describe('disableAssetsLoaders', () => {
363-
it('Disable default assets loaders', () => {
362+
describe('disableImagesLoader', () => {
363+
it('Disable default images loader', () => {
364364
const config = createConfig();
365-
config.disableAssetsLoaders();
365+
config.disableImagesLoader();
366366

367-
expect(config.useAssetsLoaders).to.be.false;
367+
expect(config.useImagesLoader).to.be.false;
368+
});
369+
});
370+
371+
describe('disableFontsLoader', () => {
372+
it('Disable default fonts loader', () => {
373+
const config = createConfig();
374+
config.disableFontsLoader();
375+
376+
expect(config.useFontsLoader).to.be.false;
368377
});
369378
});
370379
});

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)