Skip to content

Commit 613e2a5

Browse files
author
Morten N.O. Henriksen
committed
Use asset modules in react-scripts
1 parent 871b2e9 commit 613e2a5

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

packages/react-scripts/config/webpack.config.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -358,22 +358,30 @@ module.exports = function (webpackEnv) {
358358
// https://github.com/jshttp/mime-db
359359
{
360360
test: [/\.avif$/],
361-
loader: require.resolve('url-loader'),
362-
options: {
363-
limit: imageInlineSizeLimit,
364-
mimetype: 'image/avif',
365-
name: 'static/media/[name].[hash:8].[ext]',
361+
type: 'asset',
362+
mimetype: 'image/avif',
363+
generator: {
364+
filename: 'static/media/[hash][ext][query]',
365+
},
366+
parser: {
367+
dataUrlCondition: {
368+
maxSize: imageInlineSizeLimit,
369+
},
366370
},
367371
},
368372
// "url" loader works like "file" loader except that it embeds assets
369373
// smaller than specified limit in bytes as data URLs to avoid requests.
370374
// A missing `test` is equivalent to a match.
371375
{
372376
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
373-
loader: require.resolve('url-loader'),
374-
options: {
375-
limit: imageInlineSizeLimit,
376-
name: 'static/media/[name].[hash:8].[ext]',
377+
type: 'asset',
378+
generator: {
379+
filename: 'static/media/[hash][ext][query]',
380+
},
381+
parser: {
382+
dataUrlCondition: {
383+
maxSize: imageInlineSizeLimit,
384+
},
377385
},
378386
},
379387
// Process application JS with Babel.
@@ -558,14 +566,14 @@ module.exports = function (webpackEnv) {
558566
// This loader doesn't use a "test" so it will catch all modules
559567
// that fall through the other loaders.
560568
{
561-
loader: require.resolve('file-loader'),
562569
// Exclude `js` files to keep "css" loader working as it injects
563570
// its runtime that would otherwise be processed through "file" loader.
564571
// Also exclude `html` and `json` extensions so they get processed
565572
// by webpacks internal loaders.
566573
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
567-
options: {
568-
name: 'static/media/[name].[hash:8].[ext]',
574+
type: 'asset/resource',
575+
generator: {
576+
filename: 'static/media/[hash][ext][query]',
569577
},
570578
},
571579
// ** STOP ** Are you adding a new loader?

packages/react-scripts/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"eslint-plugin-react-hooks": "^4.2.0",
5656
"eslint-plugin-testing-library": "^3.9.2",
5757
"eslint-webpack-plugin": "^2.5.2",
58-
"file-loader": "6.2.0",
5958
"fs-extra": "^9.0.1",
6059
"html-webpack-plugin": "5.2.0",
6160
"identity-obj-proxy": "3.0.0",
@@ -79,7 +78,6 @@
7978
"semver": "7.3.4",
8079
"style-loader": "2.0.0",
8180
"ts-pnp": "1.2.0",
82-
"url-loader": "4.1.1",
8381
"webpack": "5.24.3",
8482
"webpack-dev-server": "4.0.0-beta.0",
8583
"webpack-manifest-plugin": "3.0.0",

0 commit comments

Comments
 (0)