From f4ef8b5cc432e17e61ece5d662bc5d7e1926595d Mon Sep 17 00:00:00 2001 From: Stefan Date: Sun, 20 Nov 2016 23:00:10 +0100 Subject: [PATCH] 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. --- .../config/webpack.config.dev.js | 46 +++++++++++-------- .../config/webpack.config.prod.js | 45 ++++++++++-------- tasks/e2e.sh | 3 -- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index e002befc1e4..137529b79ba 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -122,6 +122,32 @@ module.exports = function(publicPath) { } ], loaders: [ + // Default loader: load all assets that are not handled + // by other loaders with the url loader. + // Note: This list needs to be updated with every change of extensions + // the other loaders match. + // E.g., when adding a loader for a new supported file extension, + // we need to add the supported extension to this loader too. + // Add one new line in `exclude` for each loader. + // + // "file" loader makes sure those assets get served by WebpackDevServer. + // When you `import` an asset, you get its (virtual) filename. + // In production, they would get copied to the `build` folder. + // "url" loader works like "file" loader except that it embeds assets + // smaller than specified limit in bytes as data URLs to avoid requests. + // A missing `test` is equivalent to a match. + { + exclude: [ + /\.(js|jsx)$/, + /\.css$/, + /\.json$/ + ], + loader: 'url', + query: { + limit: 10000, + name: 'static/media/[name].[hash:8].[ext]' + } + }, // Process JS with Babel. { test: /\.(js|jsx)$/, @@ -165,26 +191,6 @@ module.exports = function(publicPath) { { test: /\.json$/, loader: 'json' - }, - // "file" loader makes sure those assets get served by WebpackDevServer. - // When you `import` an asset, you get its (virtual) filename. - // In production, they would get copied to the `build` folder. - { - test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/, - loader: 'file', - query: { - name: 'static/media/[name].[hash:8].[ext]' - } - }, - // "url" loader works just like "file" loader but it also embeds - // assets smaller than specified size as data URLs to avoid requests. - { - test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/, - loader: 'url', - query: { - limit: 10000, - name: 'static/media/[name].[hash:8].[ext]' - } } ] }, diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index bc091df4736..6ca87963a64 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -116,6 +116,32 @@ module.exports = { } ], loaders: [ + // Default loader: load all assets that are not handled + // by other loaders with the url loader. + // Note: This list needs to be updated with every change of extensions + // the other loaders match. + // E.g., when adding a loader for a new supported file extension, + // we need to add the supported extension to this loader too. + // Add one new line in `exclude` for each loader. + // + // "file" loader makes sure those assets get served by WebpackDevServer. + // When you `import` an asset, you get its (virtual) filename. + // In production, they would get copied to the `build` folder. + // "url" loader works like "file" loader except that it embeds assets + // smaller than specified limit in bytes as data URLs to avoid requests. + // A missing `test` is equivalent to a match. + { + exclude: [ + /\.(js|jsx)$/, + /\.css$/, + /\.json$/ + ], + loader: 'url', + query: { + limit: 10000, + name: 'static/media/[name].[hash:8].[ext]' + } + }, // Process JS with Babel. { test: /\.(js|jsx)$/, @@ -168,25 +194,6 @@ module.exports = { { test: /\.json$/, loader: 'json' - }, - // "file" loader makes sure those assets end up in the `build` folder. - // When you `import` an asset, you get its filename. - { - test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/, - loader: 'file', - query: { - name: 'static/media/[name].[hash:8].[ext]' - } - }, - // "url" loader works just like "file" loader but it also embeds - // assets smaller than specified size as data URLs to avoid requests. - { - test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/, - loader: 'url', - query: { - limit: 10000, - name: 'static/media/[name].[hash:8].[ext]' - } } ] }, diff --git a/tasks/e2e.sh b/tasks/e2e.sh index 094fba9e22b..9066af93f21 100755 --- a/tasks/e2e.sh +++ b/tasks/e2e.sh @@ -75,7 +75,6 @@ npm run build test -e build/*.html test -e build/static/js/*.js test -e build/static/css/*.css -test -e build/static/media/*.svg test -e build/favicon.ico # Run tests with CI flag @@ -133,7 +132,6 @@ npm run build test -e build/*.html test -e build/static/js/*.js test -e build/static/css/*.css -test -e build/static/media/*.svg test -e build/favicon.ico # Run tests with CI flag @@ -163,7 +161,6 @@ npm run build test -e build/*.html test -e build/static/js/*.js test -e build/static/css/*.css -test -e build/static/media/*.svg test -e build/favicon.ico # Run tests, overring the watch option to disable it.