Skip to content

Commit b380fb2

Browse files
committed
feat: add bundle analyzer, hot loader, fix tests
1 parent 0460d0a commit b380fb2

File tree

6 files changed

+435
-5
lines changed

6 files changed

+435
-5
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
3434
const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
3535
const CompressionPlugin = require('compression-webpack-plugin');
3636
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
37+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
3738
// @remove-on-eject-begin
3839
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
3940
// @remove-on-eject-end
@@ -422,6 +423,7 @@ module.exports = function(webpackEnv) {
422423
),
423424
// @remove-on-eject-end
424425
plugins: [
426+
require.resolve('react-hot-loader/babel'),
425427
[
426428
require.resolve('babel-plugin-named-asset-import'),
427429
{
@@ -615,6 +617,11 @@ module.exports = function(webpackEnv) {
615617
new webpack.DefinePlugin(env.stringified),
616618
// This is necessary to emit hot updates (currently CSS only):
617619
isEnvDevelopment && new webpack.HotModuleReplacementPlugin(),
620+
isEnvDevelopment &&
621+
new BundleAnalyzerPlugin({
622+
openAnalyzer: false,
623+
logLevel: 'warn',
624+
}),
618625
// Watcher doesn't work well if you mistype casing in a path so we use
619626
// a plugin that prints an error when you attempt to do this.
620627
// See https://github.com/facebook/create-react-app/issues/240

packages/react-scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"postcss-safe-parser": "4.0.1",
6666
"react-app-polyfill": "^0.2.2",
6767
"react-dev-utils": "^8.0.0",
68+
"react-hot-loader": "^4.8.0",
6869
"resolve": "1.10.0",
6970
"sass-loader": "7.1.0",
7071
"style-loader": "0.23.1",

packages/react-scripts/scripts/start.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ const {
4242
createCompiler,
4343
prepareProxy,
4444
prepareUrls,
45-
} = require('react-dev-utils/WebpackDevServerUtils');
45+
} = require('./utils/webpackDevServerUtils');
4646
const paths = require('../config/paths');
4747
const configFactory = require('../config/webpack.config');
4848
const createDevServerConfig = require('../config/webpackDevServer.config');
49+
const { setConfig } = require('react-hot-loader');
50+
51+
setConfig({ logLevel: 'none' });
4952

5053
const useYarn = fs.existsSync(paths.yarnLockFile);
5154
const isInteractive = process.stdout.isTTY;

packages/react-scripts/scripts/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ argv.push(
8282
JSON.stringify(
8383
createJestConfig(
8484
relativePath => path.resolve(__dirname, '..', relativePath),
85-
path.resolve(paths.appSrc, '..'),
85+
path.resolve(paths.workspaces, '..'),
8686
false
8787
)
8888
)

packages/react-scripts/scripts/utils/createJestConfig.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ module.exports = (resolve, rootDir, isEjecting) => {
2222
: undefined;
2323

2424
const config = {
25-
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
25+
collectCoverageFrom: [
26+
'<rootDir>/**/*.{js,jsx,ts,tsx}',
27+
'!<rootDir>/**/*.d.ts',
28+
],
2629

2730
setupFiles: [
2831
isEjecting
@@ -32,8 +35,8 @@ module.exports = (resolve, rootDir, isEjecting) => {
3235

3336
setupFilesAfterEnv: setupTestsFile ? [setupTestsFile] : [],
3437
testMatch: [
35-
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
36-
'<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}',
38+
'<rootDir>/**/__tests__/**/*.{js,jsx,ts,tsx}',
39+
'<rootDir>/**/?(*.)(spec|test).{js,jsx,ts,tsx}',
3740
],
3841
testEnvironment: 'jsdom',
3942
testURL: 'http://localhost',

0 commit comments

Comments
 (0)