Skip to content

Commit f4ef8b5

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

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
@@ -122,6 +122,32 @@ module.exports = function(publicPath) {
122122
}
123123
],
124124
loaders: [
125+
// Default loader: load all assets that are not handled
126+
// by other loaders with the url loader.
127+
// Note: This list needs to be updated with every change of extensions
128+
// the other loaders match.
129+
// E.g., when adding a loader for a new supported file extension,
130+
// we need to add the supported extension to this loader too.
131+
// Add one new line in `exclude` for each loader.
132+
//
133+
// "file" loader makes sure those assets get served by WebpackDevServer.
134+
// When you `import` an asset, you get its (virtual) filename.
135+
// In production, they would get copied to the `build` folder.
136+
// "url" loader works like "file" loader except that it embeds assets
137+
// smaller than specified limit in bytes as data URLs to avoid requests.
138+
// A missing `test` is equivalent to a match.
139+
{
140+
exclude: [
141+
/\.(js|jsx)$/,
142+
/\.css$/,
143+
/\.json$/
144+
],
145+
loader: 'url',
146+
query: {
147+
limit: 10000,
148+
name: 'static/media/[name].[hash:8].[ext]'
149+
}
150+
},
125151
// Process JS with Babel.
126152
{
127153
test: /\.(js|jsx)$/,
@@ -165,26 +191,6 @@ module.exports = function(publicPath) {
165191
{
166192
test: /\.json$/,
167193
loader: 'json'
168-
},
169-
// "file" loader makes sure those assets get served by WebpackDevServer.
170-
// When you `import` an asset, you get its (virtual) filename.
171-
// In production, they would get copied to the `build` folder.
172-
{
173-
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
174-
loader: 'file',
175-
query: {
176-
name: 'static/media/[name].[hash:8].[ext]'
177-
}
178-
},
179-
// "url" loader works just like "file" loader but it also embeds
180-
// assets smaller than specified size as data URLs to avoid requests.
181-
{
182-
test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
183-
loader: 'url',
184-
query: {
185-
limit: 10000,
186-
name: 'static/media/[name].[hash:8].[ext]'
187-
}
188194
}
189195
]
190196
},

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)$/,
@@ -168,25 +194,6 @@ module.exports = {
168194
{
169195
test: /\.json$/,
170196
loader: 'json'
171-
},
172-
// "file" loader makes sure those assets end up in the `build` folder.
173-
// When you `import` an asset, you get its filename.
174-
{
175-
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
176-
loader: 'file',
177-
query: {
178-
name: 'static/media/[name].[hash:8].[ext]'
179-
}
180-
},
181-
// "url" loader works just like "file" loader but it also embeds
182-
// assets smaller than specified size as data URLs to avoid requests.
183-
{
184-
test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
185-
loader: 'url',
186-
query: {
187-
limit: 10000,
188-
name: 'static/media/[name].[hash:8].[ext]'
189-
}
190197
}
191198
]
192199
},

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)