main
js 148 lines 4 KB
Raw
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
9 const NODE_ENV = process.env.NODE_ENV;
10 if (!NODE_ENV) {
11 console.error('NODE_ENV not set');
12 process.exit(1);
13 }
14
15 const builtModulesDir = resolve(
16 __dirname,
17 '..',
18 '..',
19 'build',
20 'oss-experimental',
21 );
22
23 const __DEV__ = NODE_ENV === 'development';
24
25 const DEVTOOLS_VERSION = getVersionString();
26
27 const EDITOR_URL = process.env.EDITOR_URL || null;
28 const LOGGING_URL = process.env.LOGGING_URL || null;
29
30 const featureFlagTarget =
31 process.env.FEATURE_FLAG_TARGET || 'core/standalone-oss';
32
33 const babelOptions = {
34 configFile: resolve(
35 __dirname,
36 '..',
37 'react-devtools-shared',
38 'babel.config.js',
39 ),
40 };
41
42 module.exports = {
43 mode: __DEV__ ? 'development' : 'production',
44 devtool: __DEV__ ? 'eval-cheap-module-source-map' : 'source-map',
45 target: 'electron-main',
46 entry: {
47 standalone: './src/standalone.js',
48 },
49 output: {
50 path: __dirname + '/dist',
51 filename: '[name].js',
52 chunkFilename: '[name].chunk.js',
53 library: {
54 type: 'commonjs2',
55 },
56 },
57 externals: {
58 bufferutil: 'commonjs bufferutil',
59 'utf-8-validate': 'commonjs utf-8-validate',
60 },
61 resolve: {
62 alias: {
63 react: resolve(builtModulesDir, 'react'),
64 'react-debug-tools': resolve(builtModulesDir, 'react-debug-tools'),
65 'react-devtools-feature-flags': resolveFeatureFlags(featureFlagTarget),
66 'react-dom/client': resolve(builtModulesDir, 'react-dom/client'),
67 'react-dom': resolve(builtModulesDir, 'react-dom'),
68 'react-is': resolve(builtModulesDir, 'react-is'),
69 scheduler: resolve(builtModulesDir, 'scheduler'),
70 },
71 },
72 node: {
73 // Don't replace __dirname!
74 // This would break the standalone DevTools ability to load the backend.
75 // see https://github.com/facebook/react-devtools/issues/1269
76 __dirname: false,
77
78 global: false,
79 },
80 plugins: [
81 new Webpack.ProvidePlugin({
82 process: 'process/browser',
83 }),
84 new Webpack.DefinePlugin({
85 __DEV__,
86 __EXPERIMENTAL__: true,
87 __EXTENSION__: false,
88 __PROFILE__: false,
89 __TEST__: NODE_ENV === 'test',
90 __IS_NATIVE__: true,
91 __IS_FIREFOX__: false,
92 __IS_CHROME__: false,
93 __IS_EDGE__: false,
94 'process.env.DEVTOOLS_PACKAGE': `"react-devtools-core"`,
95 'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
96 'process.env.EDITOR_URL': EDITOR_URL != null ? `"${EDITOR_URL}"` : null,
97 'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
98 'process.env.LOGGING_URL': `"${LOGGING_URL}"`,
99 'process.env.NODE_ENV': `"${NODE_ENV}"`,
100 }),
101 ],
102 module: {
103 rules: [
104 {
105 test: /\.worker\.js$/,
106 use: [
107 {
108 loader: 'workerize-loader',
109 options: {
110 // Workers would have to be exposed on a public path in order to outline them.
111 inline: true,
112 name: '[name]',
113 },
114 },
115 {
116 loader: 'babel-loader',
117 options: babelOptions,
118 },
119 ],
120 },
121 {
122 test: /\.js$/,
123 loader: 'babel-loader',
124 options: babelOptions,
125 },
126 {
127 test: /\.css$/,
128 use: [
129 {
130 loader: 'style-loader',
131 },
132 {
133 loader: 'css-loader',
134 options: {
135 // WARNING It's important that we disable CSS source maps for production builds.
136 // This causes style-loader to insert styles via a <style> tag rather than URL.createObjectURL,
137 // which in turn avoids a nasty Electron/Chromium bug that breaks DevTools in Nuclide.
138 // (Calls to URL.createObjectURL seem to crash the webview process.)
139 sourceMap: __DEV__,
140 modules: true,
141 localIdentName: '[local]___[hash:base64:5]',
142 },
143 },
144 ],
145 },
146 ],
147 },
148 };