Skip to content

Commit 3947d56

Browse files
committed
Split disableAssetsLoaders into disableImagesLoader and disableFontsLoader
1 parent 051759f commit 3947d56

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

432432
/**
433433
* Call this if you wish to disable the default
434-
* assets loaders (images and fonts).
434+
* images loader.
435435
*
436436
* @returns {exports}
437437
*/
438-
disableAssetsLoaders() {
439-
webpackConfig.disableAssetsLoaders();
438+
disableImagesLoader() {
439+
webpackConfig.disableImagesLoader();
440+
441+
return this;
442+
},
443+
444+
/**
445+
* Call this if you wish to disable the default
446+
* fonts loader.
447+
*
448+
* @returns {exports}
449+
*/
450+
disableFontsLoader() {
451+
webpackConfig.disableFontsLoader();
440452

441453
return this;
442454
},

lib/WebpackConfig.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class WebpackConfig {
5959
this.tsConfigurationCallback = function() {};
6060
this.useForkedTypeScriptTypeChecking = false;
6161
this.forkedTypeScriptTypesCheckOptionsCallback = () => {};
62-
this.useAssetsLoaders = true;
62+
this.useImagesLoader = true;
63+
this.useFontsLoader = true;
6364
}
6465

6566
getContext() {
@@ -269,8 +270,12 @@ class WebpackConfig {
269270
this.vueLoaderOptionsCallback = vueLoaderOptionsCallback;
270271
}
271272

272-
disableAssetsLoaders() {
273-
this.useAssetsLoaders = false;
273+
disableImagesLoader() {
274+
this.useImagesLoader = false;
275+
}
276+
277+
disableFontsLoader() {
278+
this.useFontsLoader = false;
274279
}
275280

276281
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
@@ -431,12 +431,21 @@ describe('WebpackConfig object', () => {
431431
});
432432
});
433433

434-
describe('disableAssetsLoaders', () => {
435-
it('Disable default assets loaders', () => {
434+
describe('disableImagesLoader', () => {
435+
it('Disable default images loader', () => {
436436
const config = createConfig();
437-
config.disableAssetsLoaders();
437+
config.disableImagesLoader();
438438

439-
expect(config.useAssetsLoaders).to.be.false;
439+
expect(config.useImagesLoader).to.be.false;
440+
});
441+
});
442+
443+
describe('disableFontsLoader', () => {
444+
it('Disable default fonts loader', () => {
445+
const config = createConfig();
446+
config.disableFontsLoader();
447+
448+
expect(config.useFontsLoader).to.be.false;
440449
});
441450
});
442451
});

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
@@ -204,10 +204,19 @@ describe('Public API', () => {
204204

205205
});
206206

207-
describe('disableAssetsLoaders', () => {
207+
describe('disableImagesLoader', () => {
208208

209209
it('must return the API object', () => {
210-
const returnedValue = api.disableAssetsLoaders();
210+
const returnedValue = api.disableImagesLoader();
211+
expect(returnedValue).to.equal(api);
212+
});
213+
214+
});
215+
216+
describe('disableFontsLoader', () => {
217+
218+
it('must return the API object', () => {
219+
const returnedValue = api.disableFontsLoader();
211220
expect(returnedValue).to.equal(api);
212221
});
213222

0 commit comments

Comments
 (0)