Skip to content

Commit 1c622ec

Browse files
bebbifson
authored andcommitted
Use url-loader with limit 10k as a default loader. (#1059)
Loads all files not already handled by other loaders. Also, switch image loading from file loader to url-loader.
1 parent 8edfcb5 commit 1c622ec

File tree

3 files changed

+52
-42
lines changed

3 files changed

+52
-42
lines changed

Diff for: packages/react-scripts/config/webpack.config.dev.js

+26-20
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,32 @@ module.exports = {
108108
}
109109
],
110110
loaders: [
111+
// Default loader: load all assets that are not handled
112+
// by other loaders with the url loader.
113+
// Note: This list needs to be updated with every change of extensions
114+
// the other loaders match.
115+
// E.g., when adding a loader for a new supported file extension,
116+
// we need to add the supported extension to this loader too.
117+
// Add one new line in `exclude` for each loader.
118+
//
119+
// "file" loader makes sure those assets get served by WebpackDevServer.
120+
// When you `import` an asset, you get its (virtual) filename.
121+
// In production, they would get copied to the `build` folder.
122+
// "url" loader works like "file" loader except that it embeds assets
123+
// smaller than specified limit in bytes as data URLs to avoid requests.
124+
// A missing `test` is equivalent to a match.
125+
{
126+
exclude: [
127+
/\.(js|jsx)$/,
128+
/\.css$/,
129+
/\.json$/
130+
],
131+
loader: 'url',
132+
query: {
133+
limit: 10000,
134+
name: 'static/media/[name].[hash:8].[ext]'
135+
}
136+
},
111137
// Process JS with Babel.
112138
{
113139
test: /\.(js|jsx)$/,
@@ -138,26 +164,6 @@ module.exports = {
138164
{
139165
test: /\.json$/,
140166
loader: 'json'
141-
},
142-
// "file" loader makes sure those assets get served by WebpackDevServer.
143-
// When you `import` an asset, you get its (virtual) filename.
144-
// In production, they would get copied to the `build` folder.
145-
{
146-
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
147-
loader: 'file',
148-
query: {
149-
name: 'static/media/[name].[hash:8].[ext]'
150-
}
151-
},
152-
// "url" loader works just like "file" loader but it also embeds
153-
// assets smaller than specified size as data URLs to avoid requests.
154-
{
155-
test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
156-
loader: 'url',
157-
query: {
158-
limit: 10000,
159-
name: 'static/media/[name].[hash:8].[ext]'
160-
}
161167
}
162168
]
163169
},

Diff for: packages/react-scripts/config/webpack.config.prod.js

+26-19
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,32 @@ module.exports = {
116116
}
117117
],
118118
loaders: [
119+
// Default loader: load all assets that are not handled
120+
// by other loaders with the url loader.
121+
// Note: This list needs to be updated with every change of extensions
122+
// the other loaders match.
123+
// E.g., when adding a loader for a new supported file extension,
124+
// we need to add the supported extension to this loader too.
125+
// Add one new line in `exclude` for each loader.
126+
//
127+
// "file" loader makes sure those assets get served by WebpackDevServer.
128+
// When you `import` an asset, you get its (virtual) filename.
129+
// In production, they would get copied to the `build` folder.
130+
// "url" loader works like "file" loader except that it embeds assets
131+
// smaller than specified limit in bytes as data URLs to avoid requests.
132+
// A missing `test` is equivalent to a match.
133+
{
134+
exclude: [
135+
/\.(js|jsx)$/,
136+
/\.css$/,
137+
/\.json$/
138+
],
139+
loader: 'url',
140+
query: {
141+
limit: 10000,
142+
name: 'static/media/[name].[hash:8].[ext]'
143+
}
144+
},
119145
// Process JS with Babel.
120146
{
121147
test: /\.(js|jsx)$/,
@@ -150,25 +176,6 @@ module.exports = {
150176
{
151177
test: /\.json$/,
152178
loader: 'json'
153-
},
154-
// "file" loader makes sure those assets end up in the `build` folder.
155-
// When you `import` an asset, you get its filename.
156-
{
157-
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
158-
loader: 'file',
159-
query: {
160-
name: 'static/media/[name].[hash:8].[ext]'
161-
}
162-
},
163-
// "url" loader works just like "file" loader but it also embeds
164-
// assets smaller than specified size as data URLs to avoid requests.
165-
{
166-
test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
167-
loader: 'url',
168-
query: {
169-
limit: 10000,
170-
name: 'static/media/[name].[hash:8].[ext]'
171-
}
172179
}
173180
]
174181
},

Diff for: tasks/e2e.sh

-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ npm run build
7575
test -e build/*.html
7676
test -e build/static/js/*.js
7777
test -e build/static/css/*.css
78-
test -e build/static/media/*.svg
7978
test -e build/favicon.ico
8079

8180
# Run tests with CI flag
@@ -133,7 +132,6 @@ npm run build
133132
test -e build/*.html
134133
test -e build/static/js/*.js
135134
test -e build/static/css/*.css
136-
test -e build/static/media/*.svg
137135
test -e build/favicon.ico
138136

139137
# Run tests with CI flag
@@ -163,7 +161,6 @@ npm run build
163161
test -e build/*.html
164162
test -e build/static/js/*.js
165163
test -e build/static/css/*.css
166-
test -e build/static/media/*.svg
167164
test -e build/favicon.ico
168165

169166
# Run tests, overring the watch option to disable it.

0 commit comments

Comments
 (0)