Skip to content

Commit 55495cf

Browse files
committed
changing the default to asset/resource
This will help avoid confusion because images won't be inlined by default.
1 parent a663fbc commit 55495cf

7 files changed

+23
-16
lines changed

CHANGELOG.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
(and optionally `url-loader` via `configureUrlLoader()`) to Webpack 5's
99
new [Asset Modules](https://webpack.js.org/guides/asset-modules/).
1010
In practice, unless you have a highly-configured system, this should
11-
not cause significant changes. You will notice that smaller images
12-
and fonts (smaller than 8kb) will be "inlined" in CSS files instead
13-
of being extracted to independent files for performance. This is
14-
configurable - see the new `configureImageRule()` and `configureFontRule()`
15-
methods.
11+
not cause significant changes.
1612

1713
* [BC BREAK] The `configureUrlLoader()` method was removed. See
1814
`configureImageRule()` and `configureFontRule()` - specifically the
19-
`maxSize` option. The `url-loader` is no longer used.
15+
`maxSize` option and type: 'asset'. The `url-loader` is no longer used.
2016

2117
* [BC BREAK] The `disableImagesLoader()` and `disableFontsLoader()` methods
2218
have been removed. See `configureImageRule()` and `configureFontRule()`

index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,10 @@ class Encore {
13881388
* ```
13891389
* Encore.configureImageRule({
13901390
* // common values: asset, asset/resource, asset/inline
1391-
* // or javascript/auto to disable asset images (see next example)
1392-
* type: 'asset',
1391+
* // Using "asset" will allow smaller images to be "inlined"
1392+
* // instead of copied.
1393+
* // javascript/auto caan be used to disable asset images (see next example)
1394+
* type: 'asset/resource',
13931395
*
13941396
* // applicable when for "type: asset": files smaller than this
13951397
* // size will be "inlined" into CSS, larer files will be extracted

lib/WebpackConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ class WebpackConfig {
9898
this.cleanupOutput = false;
9999
this.extractCss = true;
100100
this.imageRuleOptions = {
101-
type: 'asset',
101+
type: 'asset/resource',
102102
maxSize: null,
103103
filename: 'images/[name].[hash:8][ext]',
104104
enabled: true,
105105
};
106106
this.fontRuleOptions = {
107-
type: 'asset',
107+
type: 'asset/resource',
108108
maxSize: null,
109109
filename: 'fonts/[name].[hash:8][ext]',
110110
enabled: true,

lib/package-helper.js

+6
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ function addPackagesVersionConstraint(packages) {
177177
const newData = Object.assign({}, packageData);
178178

179179
if (packageData.enforce_version) {
180+
if (!packageJsonData.devDependencies) {
181+
logger.warning('Could not find devDependencies key on @symfony/webpack-encore package');
182+
183+
return newData;
184+
}
185+
180186
// this method only supports devDependencies due to how it's used:
181187
// it's mean to inform the user what deps they need to install
182188
// for optional features

test/WebpackConfig.js

+2
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ describe('WebpackConfig object', () => {
12961296
const config = createConfig();
12971297
const callback = () => {};
12981298
config.configureImageRule({
1299+
type: 'asset',
12991300
maxSize: 1024,
13001301
}, callback);
13011302

@@ -1333,6 +1334,7 @@ describe('WebpackConfig object', () => {
13331334
const config = createConfig();
13341335
const callback = () => {};
13351336
config.configureFontRule({
1337+
type: 'asset',
13361338
maxSize: 1024,
13371339
}, callback);
13381340

test/config-generator.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -825,13 +825,13 @@ describe('The config-generator function', () => {
825825
const actualConfig = configGenerator(config);
826826

827827
const imagesRule = findRule(/\.(png|jpg|jpeg|gif|ico|svg|webp)$/, actualConfig.module.rules);
828-
expect(imagesRule.type).to.equal('asset');
828+
expect(imagesRule.type).to.equal('asset/resource');
829829
expect(imagesRule.generator).to.eql({ filename: 'images/[name].[hash:8][ext]' });
830830
expect(imagesRule.parser).to.eql({});
831831
expect(imagesRule).to.include.keys('test', 'type', 'generator', 'parser');
832832

833833
const fontsRule = findRule(/\.(woff|woff2|ttf|eot|otf)$/, actualConfig.module.rules);
834-
expect(fontsRule.type).to.equal('asset');
834+
expect(fontsRule.type).to.equal('asset/resource');
835835
expect(fontsRule.generator).to.eql({ filename: 'fonts/[name].[hash:8][ext]' });
836836
});
837837

@@ -858,6 +858,7 @@ describe('The config-generator function', () => {
858858
config.publicPath = '/public-path';
859859
config.addEntry('main', './main');
860860
config.configureImageRule({
861+
type: 'asset',
861862
maxSize: 3000,
862863
});
863864

test/functional.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ module.exports = {
14641464
expect(config.outputPath).to.be.a.directory().with.deep.files([
14651465
'main.js',
14661466
'main.css',
1467-
// 'images/logo.26bd867d.png', logo.png is inlined
1467+
'images/logo.26bd867d.png',
14681468
'manifest.json',
14691469
'entrypoints.json',
14701470
'runtime.js',
@@ -1529,7 +1529,7 @@ module.exports = {
15291529
expect(config.outputPath).to.be.a.directory().with.deep.files([
15301530
'main.js',
15311531
'main.css',
1532-
// 'images/logo.26bd867d.png', logo.png is inlined
1532+
'images/logo.26bd867d.png',
15331533
'manifest.json',
15341534
'entrypoints.json',
15351535
'runtime.js',
@@ -1744,8 +1744,8 @@ module.exports = {
17441744
config.setPublicPath('/build');
17451745
config.addStyleEntry('url-loader', './css/url-loader.css');
17461746
// set a size so that they do NOT inline
1747-
config.configureImageRule({ maxSize: 102400 });
1748-
config.configureFontRule({ maxSize: 102400 });
1747+
config.configureImageRule({ type: 'asset', maxSize: 102400 });
1748+
config.configureFontRule({ type: 'asset', maxSize: 102400 });
17491749

17501750
testSetup.runWebpack(config, (webpackAssert) => {
17511751
expect(config.outputPath).to.be.a.directory()

0 commit comments

Comments
 (0)