| 1 | const {resolve} = require('path'); |
| 2 | const Webpack = require('webpack'); |
| 3 | const { |
| 4 | GITHUB_URL, |
| 5 | getVersionString, |
| 6 | } = require('react-devtools-extensions/utils'); |
| 7 | const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils'); |
| 8 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
| 9 | |
| 10 | const NODE_ENV = process.env.NODE_ENV; |
| 11 | if (!NODE_ENV) { |
| 12 | console.error('NODE_ENV not set'); |
| 13 | process.exit(1); |
| 14 | } |
| 15 | |
| 16 | const builtModulesDir = resolve( |
| 17 | __dirname, |
| 18 | '..', |
| 19 | '..', |
| 20 | 'build', |
| 21 | 'oss-experimental', |
| 22 | ); |
| 23 | |
| 24 | const __DEV__ = NODE_ENV === 'development'; |
| 25 | |
| 26 | const EDITOR_URL = process.env.EDITOR_URL || null; |
| 27 | |
| 28 | const DEVTOOLS_VERSION = getVersionString(); |
| 29 | |
| 30 | const babelOptions = { |
| 31 | configFile: resolve( |
| 32 | __dirname, |
| 33 | '..', |
| 34 | 'react-devtools-shared', |
| 35 | 'babel.config.js', |
| 36 | ), |
| 37 | }; |
| 38 | |
| 39 | module.exports = { |
| 40 | mode: __DEV__ ? 'development' : 'production', |
| 41 | entry: { |
| 42 | frontend: './src/frontend.js', |
| 43 | }, |
| 44 | experiments: { |
| 45 | outputModule: true, |
| 46 | }, |
| 47 | output: { |
| 48 | path: __dirname + '/dist', |
| 49 | publicPath: '/dist/', |
| 50 | filename: '[name].js', |
| 51 | chunkFilename: '[name].chunk.js', |
| 52 | library: { |
| 53 | type: 'module', |
| 54 | }, |
| 55 | }, |
| 56 | node: { |
| 57 | global: false, |
| 58 | }, |
| 59 | resolve: { |
| 60 | alias: { |
| 61 | 'react-devtools-feature-flags': resolveFeatureFlags('fusebox'), |
| 62 | react: resolve(builtModulesDir, 'react'), |
| 63 | 'react-debug-tools': resolve(builtModulesDir, 'react-debug-tools'), |
| 64 | 'react-dom/client': resolve(builtModulesDir, 'react-dom/client'), |
| 65 | 'react-dom': resolve(builtModulesDir, 'react-dom'), |
| 66 | 'react-is': resolve(builtModulesDir, 'react-is'), |
| 67 | scheduler: resolve(builtModulesDir, 'scheduler'), |
| 68 | }, |
| 69 | }, |
| 70 | optimization: { |
| 71 | minimize: false, |
| 72 | }, |
| 73 | plugins: [ |
| 74 | new MiniCssExtractPlugin(), |
| 75 | new Webpack.ProvidePlugin({ |
| 76 | process: 'process/browser', |
| 77 | }), |
| 78 | new Webpack.DefinePlugin({ |
| 79 | __DEV__, |
| 80 | __EXPERIMENTAL__: true, |
| 81 | __EXTENSION__: false, |
| 82 | __PROFILE__: false, |
| 83 | __TEST__: NODE_ENV === 'test', |
| 84 | __IS_NATIVE__: true, |
| 85 | __IS_CHROME__: false, |
| 86 | __IS_FIREFOX__: false, |
| 87 | __IS_EDGE__: false, |
| 88 | 'process.env.DEVTOOLS_PACKAGE': `"react-devtools-fusebox"`, |
| 89 | 'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`, |
| 90 | 'process.env.EDITOR_URL': EDITOR_URL != null ? `"${EDITOR_URL}"` : null, |
| 91 | 'process.env.GITHUB_URL': `"${GITHUB_URL}"`, |
| 92 | 'process.env.NODE_ENV': `"${NODE_ENV}"`, |
| 93 | }), |
| 94 | ], |
| 95 | module: { |
| 96 | rules: [ |
| 97 | { |
| 98 | test: /\.worker\.js$/, |
| 99 | use: [ |
| 100 | { |
| 101 | loader: 'workerize-loader', |
| 102 | options: { |
| 103 | // Workers would have to be exposed on a public path in order to outline them. |
| 104 | inline: true, |
| 105 | name: '[name]', |
| 106 | }, |
| 107 | }, |
| 108 | { |
| 109 | loader: 'babel-loader', |
| 110 | options: babelOptions, |
| 111 | }, |
| 112 | ], |
| 113 | }, |
| 114 | { |
| 115 | test: /\.js$/, |
| 116 | loader: 'babel-loader', |
| 117 | options: babelOptions, |
| 118 | }, |
| 119 | { |
| 120 | test: /\.css$/i, |
| 121 | use: [ |
| 122 | { |
| 123 | loader: MiniCssExtractPlugin.loader, |
| 124 | }, |
| 125 | { |
| 126 | loader: 'css-loader', |
| 127 | options: {modules: true}, |
| 128 | }, |
| 129 | ], |
| 130 | }, |
| 131 | ], |
| 132 | }, |
| 133 | }; |