mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 00:20:28 +01:00
## Summary This was originally implemented by Mengdi @mondaychen in https://github.com/facebook/react/pull/26506. Because we patch console methods (to append components stack and some other features), errors in console will include `react_devtools_backend-....js` in its stack traces. Example: <img width="763" alt="Screenshot 2023-06-15 at 13 31 49" src="https://github.com/facebook/react/assets/28902667/fa9c3d26-b6c5-4965-af71-62d100cd806d"> Using https://github.com/mondaychen/devtools-ignore-webpack-plugin to support [x_google_ignoreList source maps extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension). @mondaychen created a react app, which throws an error via `console.error`, when user click on the button - https://3owqsn.csb.app/. Stack trace with these changes: <img width="759" alt="Screenshot 2023-06-14 at 14 26 38" src="https://github.com/facebook/react/assets/28902667/b118b168-3200-4a47-9718-39fc455ea993">
110 lines
3.1 KiB
JavaScript
110 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
const {resolve} = require('path');
|
|
const Webpack = require('webpack');
|
|
const DevToolsIgnorePlugin = require('devtools-ignore-webpack-plugin');
|
|
|
|
const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils');
|
|
const {
|
|
DARK_MODE_DIMMED_WARNING_COLOR,
|
|
DARK_MODE_DIMMED_ERROR_COLOR,
|
|
DARK_MODE_DIMMED_LOG_COLOR,
|
|
LIGHT_MODE_DIMMED_WARNING_COLOR,
|
|
LIGHT_MODE_DIMMED_ERROR_COLOR,
|
|
LIGHT_MODE_DIMMED_LOG_COLOR,
|
|
GITHUB_URL,
|
|
getVersionString,
|
|
} = require('./utils');
|
|
|
|
const NODE_ENV = process.env.NODE_ENV;
|
|
if (!NODE_ENV) {
|
|
console.error('NODE_ENV not set');
|
|
process.exit(1);
|
|
}
|
|
|
|
const builtModulesDir = resolve(
|
|
__dirname,
|
|
'..',
|
|
'..',
|
|
'build',
|
|
'oss-experimental',
|
|
);
|
|
|
|
const __DEV__ = NODE_ENV === 'development';
|
|
|
|
const DEVTOOLS_VERSION = getVersionString(process.env.DEVTOOLS_VERSION);
|
|
|
|
const featureFlagTarget = process.env.FEATURE_FLAG_TARGET || 'extension-oss';
|
|
|
|
module.exports = {
|
|
mode: __DEV__ ? 'development' : 'production',
|
|
devtool: __DEV__ ? 'cheap-module-source-map' : 'nosources-cheap-source-map',
|
|
entry: {
|
|
backend: './src/backend.js',
|
|
},
|
|
output: {
|
|
path: __dirname + '/build',
|
|
filename: 'react_devtools_backend_compact.js',
|
|
},
|
|
node: {
|
|
global: false,
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
react: resolve(builtModulesDir, 'react'),
|
|
'react-debug-tools': resolve(builtModulesDir, 'react-debug-tools'),
|
|
'react-devtools-feature-flags': resolveFeatureFlags(featureFlagTarget),
|
|
'react-dom': resolve(builtModulesDir, 'react-dom'),
|
|
'react-is': resolve(builtModulesDir, 'react-is'),
|
|
scheduler: resolve(builtModulesDir, 'scheduler'),
|
|
},
|
|
},
|
|
optimization: {
|
|
minimize: false,
|
|
},
|
|
plugins: [
|
|
new Webpack.ProvidePlugin({
|
|
process: 'process/browser',
|
|
}),
|
|
new Webpack.DefinePlugin({
|
|
__DEV__: true,
|
|
__PROFILE__: false,
|
|
__DEV____DEV__: true,
|
|
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-extensions"`,
|
|
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
|
|
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
|
|
'process.env.DARK_MODE_DIMMED_WARNING_COLOR': `"${DARK_MODE_DIMMED_WARNING_COLOR}"`,
|
|
'process.env.DARK_MODE_DIMMED_ERROR_COLOR': `"${DARK_MODE_DIMMED_ERROR_COLOR}"`,
|
|
'process.env.DARK_MODE_DIMMED_LOG_COLOR': `"${DARK_MODE_DIMMED_LOG_COLOR}"`,
|
|
'process.env.LIGHT_MODE_DIMMED_WARNING_COLOR': `"${LIGHT_MODE_DIMMED_WARNING_COLOR}"`,
|
|
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"${LIGHT_MODE_DIMMED_ERROR_COLOR}"`,
|
|
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"${LIGHT_MODE_DIMMED_LOG_COLOR}"`,
|
|
}),
|
|
new DevToolsIgnorePlugin({
|
|
shouldIgnorePath: function (path) {
|
|
if (!__DEV__) {
|
|
return true;
|
|
}
|
|
|
|
return path.includes('/node_modules/') || path.includes('/webpack/');
|
|
},
|
|
}),
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
loader: 'babel-loader',
|
|
options: {
|
|
configFile: resolve(
|
|
__dirname,
|
|
'..',
|
|
'react-devtools-shared',
|
|
'babel.config.js',
|
|
),
|
|
},
|
|
},
|
|
],
|
|
},
|
|
};
|