-
Notifications
You must be signed in to change notification settings - Fork 31.2k
[dev-overlay] Render /app Dev Overlay with a separate React instance #79699
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
Changes from all commits
279888b
b36ce5c
57f00ef
5cfc5b5
9a9abc9
ec4e690
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| const path = require('path') | ||
| const webpack = require('@rspack/core') | ||
| const MODERN_BROWSERSLIST_TARGET = require('./src/shared/lib/modern-browserslist-target') | ||
| const DevToolsIgnoreListPlugin = require('./webpack-plugins/devtools-ignore-list-plugin') | ||
|
|
||
| function shouldIgnorePath(modulePath) { | ||
| // For consumers, everything will be considered 3rd party dependency if they use | ||
| // the bundles we produce here. | ||
| // In other words, this is all library code and should therefore be ignored. | ||
| return true | ||
| } | ||
|
|
||
| /** | ||
| * @param {Object} options | ||
| * @param {boolean} options.dev | ||
| * @param {Partial<webpack.Configuration>} options.rest | ||
| * @returns {webpack.Configuration} | ||
| */ | ||
| module.exports = ({ dev, ...rest }) => { | ||
| const experimental = false | ||
| const turbo = false | ||
|
|
||
| const bundledReactChannel = experimental ? '-experimental' : '' | ||
|
|
||
| const target = `browserslist:${MODERN_BROWSERSLIST_TARGET.join(', ')}` | ||
|
|
||
| return { | ||
| entry: path.join( | ||
| __dirname, | ||
| 'src/client/components/react-dev-overlay/app/entrypoint.js' | ||
| ), | ||
| target, | ||
| mode: dev ? 'development' : 'production', | ||
| output: { | ||
| path: path.join(__dirname, 'dist/compiled/next-devtools'), | ||
| filename: `index.js`, | ||
| iife: false, | ||
| library: { | ||
| type: 'commonjs-static', | ||
| }, | ||
| }, | ||
| devtool: 'source-map', | ||
| optimization: { | ||
| moduleIds: 'named', | ||
| minimize: true, | ||
| concatenateModules: true, | ||
| minimizer: [ | ||
| new webpack.SwcJsMinimizerRspackPlugin({ | ||
| minimizerOptions: { | ||
| mangle: dev || process.env.NEXT_SERVER_NO_MANGLE ? false : true, | ||
| }, | ||
| }), | ||
| ], | ||
| }, | ||
| plugins: [ | ||
| // TODO: React Compiler | ||
| new DevToolsIgnoreListPlugin({ shouldIgnorePath }), | ||
| new webpack.DefinePlugin({ | ||
| // TODO: Hardcode it and ensure module resolution resolves to .node entrypoint in Node.js | ||
| // 'typeof window': JSON.stringify('object'), | ||
| 'process.env.NEXT_MINIMAL': JSON.stringify('true'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 'this.serverOptions.experimentalTestProxy': JSON.stringify(false), | ||
| 'this.minimalMode': JSON.stringify(true), | ||
| 'this.renderOpts.dev': JSON.stringify(dev), | ||
| 'renderOpts.dev': JSON.stringify(dev), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think renderOpts should be removed, it should always be
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to keep these in sync with the runtime for now until we isolated the bundler better codewise |
||
| 'process.env.NODE_ENV': JSON.stringify( | ||
| dev ? 'development' : 'production' | ||
| ), | ||
| 'process.env.__NEXT_EXPERIMENTAL_REACT': JSON.stringify( | ||
| experimental ? true : false | ||
| ), | ||
| 'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'), | ||
| 'process.turbopack': JSON.stringify(turbo), | ||
| 'process.env.TURBOPACK': JSON.stringify(turbo), | ||
| }), | ||
| ].filter(Boolean), | ||
| stats: { | ||
| optimizationBailout: true, | ||
| }, | ||
| resolve: { | ||
| alias: { | ||
| // TODO: Get dedicated React version for NDT to uncouple development. | ||
| react: `next/dist/compiled/react${bundledReactChannel}`, | ||
| 'react-dom$': `next/dist/compiled/react-dom${bundledReactChannel}`, | ||
| 'react-dom/client$': `next/dist/compiled/react-dom${bundledReactChannel}/client`, | ||
| 'react-is$': `next/dist/compiled/react-is${bundledReactChannel}`, | ||
| scheduler$: `next/dist/compiled/scheduler${bundledReactChannel}`, | ||
| }, | ||
| extensions: ['.ts', '.tsx', '.js', '.json'], | ||
| }, | ||
| module: { | ||
| rules: [ | ||
| { test: /\.m?js$/, loader: `source-map-loader`, enforce: `pre` }, | ||
| { | ||
| test: /\.(ts|tsx)$/, | ||
| exclude: [/node_modules/], | ||
| loader: 'builtin:swc-loader', | ||
| options: { | ||
| jsc: { | ||
| parser: { | ||
| syntax: 'typescript', | ||
| tsx: true, | ||
| }, | ||
| transform: { | ||
| react: { | ||
| development: dev, | ||
| runtime: 'automatic', | ||
| // TODO: Fast Refresh | ||
| // refresh: dev, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| type: 'javascript/auto', | ||
| }, | ||
| ], | ||
| }, | ||
| externals: [], | ||
| experiments: {}, | ||
| ...rest, | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we try
modern-moduleto get better bundle size? webpack supports it in 5.93.0+There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can experiment with that if you want. I don't want to tinker with this for Turbopack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need all the entrypoints anyway. There's nothing that the bundler would tree-shake. Ideally, it would ignore the source code entirely for further analysis since it's already sufficiently optimized.