Skip to content

Commit c62496e

Browse files
committed
chore(webpack): make sure that images are always inlined in web build
1 parent 315d413 commit c62496e

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

configs/webpack-config-compass/src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
sourceLoader,
2323
cssLoader,
2424
lessLoader,
25-
assetsLoader,
25+
fontLoader,
26+
imageLoader,
2627
resourceLoader,
2728
sharedObjectLoader,
2829
} from './loaders';
@@ -225,7 +226,8 @@ export function createElectronRendererConfig(
225226
nodeLoader(opts),
226227
cssLoader(opts),
227228
lessLoader(opts),
228-
assetsLoader(opts),
229+
fontLoader(opts),
230+
imageLoader(opts),
229231
sharedObjectLoader(opts),
230232
sourceLoader(opts),
231233
],
@@ -370,7 +372,8 @@ export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
370372
nodeLoader(opts),
371373
cssLoader(opts, true),
372374
lessLoader(opts),
373-
assetsLoader(opts),
375+
fontLoader(opts),
376+
imageLoader(opts),
374377
sourceLoader(opts),
375378
],
376379
parser: {

configs/webpack-config-compass/src/loaders.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,18 @@ export const lessLoader = (args: ConfigArgs) => ({
187187
});
188188

189189
// eslint-disable-next-line @typescript-eslint/no-unused-vars
190-
export const assetsLoader = (_args: ConfigArgs) => ({
191-
test: /\.(jpe?g|png|svg|gif|woff|woff2|ttf|eot|otf)(\?.+?)?$/,
192-
// asset (or asset auto) will either compile as data-uri or to a file path
193-
// based on the size, this is a good strategy for loading assets in the GUI
194-
type: 'asset',
195-
parser: {
196-
dataUrlCondition: {
197-
maxSize: 2 * 1024, // 2kb
198-
},
199-
},
190+
export const fontLoader = (_args: ConfigArgs) => ({
191+
test: /\.(woff|woff2|ttf|eot|otf)(\?.+?)?$/,
192+
// fonts are always big and should be emitted as a separate file
193+
type: 'asset/resource',
194+
});
195+
196+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
197+
export const imageLoader = (_args: ConfigArgs) => ({
198+
test: /\.(jpe?g|png|svg|gif)(\?.+?)?$/,
199+
// it's convenient to inline images as data-urls to make sure that publised
200+
// library artifacts only produce importable javascript assets
201+
type: 'asset/inline',
200202
});
201203

202204
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -223,7 +225,7 @@ export const sourceLoader = (args: ConfigArgs) => ({
223225
nodeLoader(args).test,
224226
cssLoader(args).test,
225227
lessLoader(args).test,
226-
assetsLoader(args).test,
228+
resourceLoader(args).test,
227229
sharedObjectLoader(args).test,
228230
// Produced by html-webpack-plugin and should not be handled
229231
/\.(ejs|html)$/,

0 commit comments

Comments
 (0)