Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upgrades react-scripts to v5 #386

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
node: true,
},
extends: ['airbnb-base', 'plugin:react/recommended', 'plugin:prettier/recommended'],
parser: 'babel-eslint',
parser: '@babel/eslint-parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
Expand Down
59 changes: 59 additions & 0 deletions config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const path = require('path');

/**
* Configures `react-app-rewired` with the necessary changes to make the app work in the browser
* environment. This is necessary since the upgrade to WebPack 5.
* @param config
* @returns {*}
*/
module.exports = function override(config) {
// Resolves the modules that are missing in the browser environment
config.resolve.fallback = {
...config.resolve.fallback,
buffer: require.resolve('buffer'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
path: require.resolve('path-browserify'),
vm: require.resolve('vm-browserify'),
url: require.resolve('url'),
assert: require.resolve('assert'),
process: require.resolve('process/browser'),
};

config.resolve.alias = {
// Add an alias for our buffer shim
'buffer-shim': path.resolve(__dirname, 'src/buffer-shim.js'),
};

// Relaxing js/mjs extension resolve
config.module.rules.push({
test: /\.m?js/, // Apply this rule to .js and .mjs files
resolve: {
fullySpecified: false, // Allow resolving modules without fully specifying the file extension
},
});

// Solves process and buffer issues for WebPack
const webpack = require('webpack');
config.plugins = [
...config.plugins,
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer-shim', 'default'],
}),
];

// Add Babel configuration
config.module.rules.push({
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
},
},
});

return config;
};
Loading