prod-test-chat-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/.prettierrc.js +24 -0
  2. package/README.md +46 -0
  3. package/config/env.js +104 -0
  4. package/config/getHttpsConfig.js +66 -0
  5. package/config/jest/babelTransform.js +29 -0
  6. package/config/jest/cssTransform.js +14 -0
  7. package/config/jest/fileTransform.js +40 -0
  8. package/config/modules.js +134 -0
  9. package/config/paths.js +77 -0
  10. package/config/webpack/persistentCache/createEnvironmentHash.js +9 -0
  11. package/config/webpack.config.js +785 -0
  12. package/config/webpackDevServer.config.js +127 -0
  13. package/dist/Chat/AgentList/index.d.ts +9 -0
  14. package/dist/Chat/ChatFooter/index.d.ts +17 -0
  15. package/dist/Chat/Conversation/index.d.ts +11 -0
  16. package/dist/Chat/MessageContainer/index.d.ts +19 -0
  17. package/dist/Chat/MobileAgents/index.d.ts +11 -0
  18. package/dist/Chat/components/AgentTip/index.d.ts +8 -0
  19. package/dist/Chat/components/ConversationModal/index.d.ts +10 -0
  20. package/dist/Chat/components/CopilotAvatar/index.d.ts +2 -0
  21. package/dist/Chat/components/Message.d.ts +10 -0
  22. package/dist/Chat/components/RecommendQuestions/index.d.ts +6 -0
  23. package/dist/Chat/components/Text.d.ts +9 -0
  24. package/dist/Chat/constants.d.ts +19 -0
  25. package/dist/Chat/index.d.ts +17 -0
  26. package/dist/Chat/service.d.ts +11 -0
  27. package/dist/Chat/type.d.ts +97 -0
  28. package/dist/Copilot/constants.d.ts +11 -0
  29. package/dist/Copilot/index.d.ts +13 -0
  30. package/dist/ShowCase/index.d.ts +8 -0
  31. package/dist/ShowCase/service.d.ts +2 -0
  32. package/dist/ShowCase/type.d.ts +11 -0
  33. package/dist/common/constants.d.ts +58 -0
  34. package/dist/common/env.d.ts +3 -0
  35. package/dist/common/type.d.ts +247 -0
  36. package/dist/components/ChatItem/ExecuteItem.d.ts +25 -0
  37. package/dist/components/ChatItem/ExpandParseTip.d.ts +20 -0
  38. package/dist/components/ChatItem/FilterItem.d.ts +17 -0
  39. package/dist/components/ChatItem/Loading.d.ts +2 -0
  40. package/dist/components/ChatItem/ParseTip.d.ts +26 -0
  41. package/dist/components/ChatItem/ParseTipUtils.d.ts +10 -0
  42. package/dist/components/ChatItem/SimilarQuestionItem.d.ts +10 -0
  43. package/dist/components/ChatItem/SqlItem.d.ts +17 -0
  44. package/dist/components/ChatItem/SwitchEntity.d.ts +9 -0
  45. package/dist/components/ChatItem/Text.d.ts +6 -0
  46. package/dist/components/ChatItem/Typing.d.ts +2 -0
  47. package/dist/components/ChatItem/index.d.ts +33 -0
  48. package/dist/components/ChatMsg/ApplyAuth/index.d.ts +7 -0
  49. package/dist/components/ChatMsg/Bar/index.d.ts +13 -0
  50. package/dist/components/ChatMsg/DateOptions/index.d.ts +9 -0
  51. package/dist/components/ChatMsg/FilterSection/index.d.ts +8 -0
  52. package/dist/components/ChatMsg/MarkDown/index.d.ts +10 -0
  53. package/dist/components/ChatMsg/Message/index.d.ts +18 -0
  54. package/dist/components/ChatMsg/MetricCard/PeriodCompareItem.d.ts +7 -0
  55. package/dist/components/ChatMsg/MetricCard/index.d.ts +10 -0
  56. package/dist/components/ChatMsg/MetricTrend/MetricInfo.d.ts +8 -0
  57. package/dist/components/ChatMsg/MetricTrend/MetricTrendChart.d.ts +14 -0
  58. package/dist/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.d.ts +12 -0
  59. package/dist/components/ChatMsg/MetricTrend/index.d.ts +16 -0
  60. package/dist/components/ChatMsg/NoPermissionChart/index.d.ts +8 -0
  61. package/dist/components/ChatMsg/Pie/PieChart.d.ts +11 -0
  62. package/dist/components/ChatMsg/Pie/index.d.ts +14 -0
  63. package/dist/components/ChatMsg/Table/index.d.ts +12 -0
  64. package/dist/components/ChatMsg/Text/index.d.ts +9 -0
  65. package/dist/components/ChatMsg/WebPage/index.d.ts +8 -0
  66. package/dist/components/ChatMsg/index.d.ts +15 -0
  67. package/dist/components/DrillDownDimensions/DimensionSection.d.ts +11 -0
  68. package/dist/components/DrillDownDimensions/index.d.ts +13 -0
  69. package/dist/components/IconFont/index.d.ts +3 -0
  70. package/dist/components/MetricOptions/index.d.ts +11 -0
  71. package/dist/components/RecommendOptions/index.d.ts +9 -0
  72. package/dist/components/Tools/FeedbackModal.d.ts +9 -0
  73. package/dist/components/Tools/index.d.ts +12 -0
  74. package/dist/demo/Chat.d.ts +2 -0
  75. package/dist/demo/ChatDemo.d.ts +4 -0
  76. package/dist/demo/CopilotDemo.d.ts +2 -0
  77. package/dist/hooks/index.d.ts +3 -0
  78. package/dist/hooks/useComposing.d.ts +5 -0
  79. package/dist/hooks/useExportByEcharts.d.ts +10 -0
  80. package/dist/hooks/useMethodRegister.d.ts +4 -0
  81. package/dist/index.d.ts +10 -0
  82. package/dist/index.es.js +1 -0
  83. package/dist/service/axiosInstance.d.ts +3 -0
  84. package/dist/service/index.d.ts +25 -0
  85. package/dist/utils/utils.d.ts +45 -0
  86. package/package.json +214 -0
  87. package/public/favicon.ico +0 -0
  88. package/public/index.html +43 -0
  89. package/public/manifest.json +15 -0
  90. package/public/robots.txt +3 -0
  91. package/rollup/rollup.config.mjs +37 -0
  92. package/rollup/rollup.esm.config.mjs +21 -0
  93. package/rollup/rollup.umd.config.mjs +30 -0
  94. package/scripts/build.js +217 -0
  95. package/scripts/start.js +154 -0
  96. package/scripts/test.js +52 -0
  97. package/src/Chat/AgentList/index.tsx +52 -0
  98. package/src/Chat/AgentList/style.module.less +83 -0
  99. package/src/Chat/ChatFooter/index.tsx +423 -0
  100. package/src/Chat/ChatFooter/style.module.less +225 -0
  101. package/src/Chat/Conversation/index.tsx +236 -0
  102. package/src/Chat/Conversation/style.module.less +171 -0
  103. package/src/Chat/MessageContainer/index.tsx +145 -0
  104. package/src/Chat/MessageContainer/style.module.less +53 -0
  105. package/src/Chat/MobileAgents/index.tsx +62 -0
  106. package/src/Chat/MobileAgents/style.module.less +55 -0
  107. package/src/Chat/components/AgentTip/index.tsx +48 -0
  108. package/src/Chat/components/AgentTip/style.module.less +44 -0
  109. package/src/Chat/components/ConversationModal/index.tsx +65 -0
  110. package/src/Chat/components/CopilotAvatar/index.tsx +8 -0
  111. package/src/Chat/components/CopilotAvatar/style.module.less +13 -0
  112. package/src/Chat/components/Message.tsx +38 -0
  113. package/src/Chat/components/RecommendQuestions/index.tsx +64 -0
  114. package/src/Chat/components/RecommendQuestions/style.module.less +36 -0
  115. package/src/Chat/components/Text.tsx +42 -0
  116. package/src/Chat/components/style.module.less +311 -0
  117. package/src/Chat/constants.ts +37 -0
  118. package/src/Chat/index.tsx +526 -0
  119. package/src/Chat/service.ts +49 -0
  120. package/src/Chat/style.module.less +119 -0
  121. package/src/Chat/type.ts +107 -0
  122. package/src/Copilot/constants.ts +11 -0
  123. package/src/Copilot/index.tsx +149 -0
  124. package/src/Copilot/style.module.less +151 -0
  125. package/src/ShowCase/index.tsx +120 -0
  126. package/src/ShowCase/service.ts +12 -0
  127. package/src/ShowCase/style.module.less +46 -0
  128. package/src/ShowCase/type.ts +14 -0
  129. package/src/common/constants.ts +93 -0
  130. package/src/common/env.ts +5 -0
  131. package/src/common/type.ts +270 -0
  132. package/src/components/ChatItem/ExecuteItem.tsx +211 -0
  133. package/src/components/ChatItem/ExpandParseTip.tsx +333 -0
  134. package/src/components/ChatItem/FilterItem.tsx +209 -0
  135. package/src/components/ChatItem/Loading.tsx +14 -0
  136. package/src/components/ChatItem/ParseTip.tsx +322 -0
  137. package/src/components/ChatItem/ParseTipUtils.tsx +205 -0
  138. package/src/components/ChatItem/SimilarQuestionItem.tsx +84 -0
  139. package/src/components/ChatItem/SqlItem.tsx +410 -0
  140. package/src/components/ChatItem/SwitchEntity.tsx +52 -0
  141. package/src/components/ChatItem/Text.tsx +17 -0
  142. package/src/components/ChatItem/Typing.tsx +19 -0
  143. package/src/components/ChatItem/index.tsx +843 -0
  144. package/src/components/ChatItem/style.less +670 -0
  145. package/src/components/ChatMsg/ApplyAuth/index.tsx +30 -0
  146. package/src/components/ChatMsg/ApplyAuth/style.less +13 -0
  147. package/src/components/ChatMsg/Bar/index.tsx +223 -0
  148. package/src/components/ChatMsg/Bar/style.less +60 -0
  149. package/src/components/ChatMsg/DateOptions/index.tsx +46 -0
  150. package/src/components/ChatMsg/DateOptions/style.less +43 -0
  151. package/src/components/ChatMsg/FilterSection/index.tsx +42 -0
  152. package/src/components/ChatMsg/FilterSection/style.less +37 -0
  153. package/src/components/ChatMsg/MarkDown/index.tsx +26 -0
  154. package/src/components/ChatMsg/MarkDown/style.less +9 -0
  155. package/src/components/ChatMsg/Message/index.tsx +105 -0
  156. package/src/components/ChatMsg/Message/style.less +119 -0
  157. package/src/components/ChatMsg/MetricCard/PeriodCompareItem.tsx +29 -0
  158. package/src/components/ChatMsg/MetricCard/index.tsx +80 -0
  159. package/src/components/ChatMsg/MetricCard/style.less +126 -0
  160. package/src/components/ChatMsg/MetricTrend/MetricInfo.tsx +60 -0
  161. package/src/components/ChatMsg/MetricTrend/MetricTrendChart.tsx +235 -0
  162. package/src/components/ChatMsg/MetricTrend/MultiMetricsTrendChart.tsx +162 -0
  163. package/src/components/ChatMsg/MetricTrend/index.tsx +127 -0
  164. package/src/components/ChatMsg/MetricTrend/style.less +195 -0
  165. package/src/components/ChatMsg/NoPermissionChart/index.tsx +28 -0
  166. package/src/components/ChatMsg/NoPermissionChart/style.less +26 -0
  167. package/src/components/ChatMsg/Pie/PieChart.tsx +134 -0
  168. package/src/components/ChatMsg/Pie/index.tsx +88 -0
  169. package/src/components/ChatMsg/Pie/style.less +43 -0
  170. package/src/components/ChatMsg/Table/index.tsx +105 -0
  171. package/src/components/ChatMsg/Table/style.less +131 -0
  172. package/src/components/ChatMsg/Text/index.tsx +70 -0
  173. package/src/components/ChatMsg/Text/style.less +38 -0
  174. package/src/components/ChatMsg/WebPage/index.tsx +125 -0
  175. package/src/components/ChatMsg/index.tsx +428 -0
  176. package/src/components/ChatMsg/style.less +28 -0
  177. package/src/components/DrillDownDimensions/DimensionSection.tsx +99 -0
  178. package/src/components/DrillDownDimensions/index.tsx +76 -0
  179. package/src/components/DrillDownDimensions/style.less +64 -0
  180. package/src/components/IconFont/index.tsx +7 -0
  181. package/src/components/MetricOptions/index.tsx +75 -0
  182. package/src/components/MetricOptions/style.less +69 -0
  183. package/src/components/RecommendOptions/index.tsx +126 -0
  184. package/src/components/RecommendOptions/style.less +24 -0
  185. package/src/components/Tools/FeedbackModal.tsx +55 -0
  186. package/src/components/Tools/index.tsx +126 -0
  187. package/src/components/Tools/style.less +67 -0
  188. package/src/demo/Chat.tsx +73 -0
  189. package/src/demo/ChatDemo.tsx +14 -0
  190. package/src/demo/CopilotDemo.tsx +43 -0
  191. package/src/demo/style.module.less +19 -0
  192. package/src/hooks/index.ts +3 -0
  193. package/src/hooks/useComposing.ts +31 -0
  194. package/src/hooks/useExportByEcharts.ts +41 -0
  195. package/src/hooks/useMethodRegister.ts +25 -0
  196. package/src/index.tsx +44 -0
  197. package/src/service/axiosInstance.ts +58 -0
  198. package/src/service/index.ts +174 -0
  199. package/src/setupProxy.js +18 -0
  200. package/src/setupTests.ts +5 -0
  201. package/src/styles/global.less +52 -0
  202. package/src/styles/index.less +39 -0
  203. package/src/styles/reboot.less +14 -0
  204. package/src/styles/variables.less +80 -0
  205. package/src/typings.d.ts +179 -0
  206. package/src/utils/utils.ts +346 -0
  207. package/tsconfig.build.json +20 -0
  208. package/tsconfig.json +27 -0
@@ -0,0 +1,785 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const webpack = require('webpack');
6
+ const resolve = require('resolve');
7
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
8
+ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
9
+ const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
10
+ const TerserPlugin = require('terser-webpack-plugin');
11
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
12
+ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
13
+ const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
14
+ const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
15
+ const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
16
+ const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
17
+ const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
18
+ const ESLintPlugin = require('eslint-webpack-plugin');
19
+ const paths = require('./paths');
20
+ const modules = require('./modules');
21
+ const getClientEnvironment = require('./env');
22
+ const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
23
+ const ForkTsCheckerWebpackPlugin =
24
+ process.env.TSC_COMPILE_ON_ERROR === 'true'
25
+ ? require('react-dev-utils/ForkTsCheckerWarningWebpackPlugin')
26
+ : require('react-dev-utils/ForkTsCheckerWebpackPlugin');
27
+ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
28
+
29
+ const createEnvironmentHash = require('./webpack/persistentCache/createEnvironmentHash');
30
+
31
+ // Source maps are resource heavy and can cause out of memory issue for large source files.
32
+ const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
33
+
34
+ const reactRefreshRuntimeEntry = require.resolve('react-refresh/runtime');
35
+ const reactRefreshWebpackPluginRuntimeEntry = require.resolve(
36
+ '@pmmmwh/react-refresh-webpack-plugin'
37
+ );
38
+ const babelRuntimeEntry = require.resolve('babel-preset-react-app');
39
+ const babelRuntimeEntryHelpers = require.resolve(
40
+ '@babel/runtime/helpers/esm/assertThisInitialized',
41
+ { paths: [babelRuntimeEntry] }
42
+ );
43
+ const babelRuntimeRegenerator = require.resolve('@babel/runtime/regenerator', {
44
+ paths: [babelRuntimeEntry],
45
+ });
46
+
47
+ // Some apps do not need the benefits of saving a web request, so not inlining the chunk
48
+ // makes for a smoother build process.
49
+ const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
50
+
51
+ const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
52
+ const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';
53
+
54
+ const imageInlineSizeLimit = parseInt(
55
+ process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
56
+ );
57
+
58
+ // Check if TypeScript is setup
59
+ const useTypeScript = fs.existsSync(paths.appTsConfig);
60
+
61
+ // Check if Tailwind config exists
62
+ const useTailwind = fs.existsSync(
63
+ path.join(paths.appPath, 'tailwind.config.js')
64
+ );
65
+
66
+ // Get the path to the uncompiled service worker (if it exists).
67
+ const swSrc = paths.swSrc;
68
+
69
+ // style files regexes
70
+ const cssRegex = /\.css$/;
71
+ const cssModuleRegex = /\.module\.css$/;
72
+ const sassRegex = /\.(scss|sass)$/;
73
+ const sassModuleRegex = /\.module\.(scss|sass)$/;
74
+ const lessRegex = /\.less$/;
75
+ const lessModuleRegex = /\.module\.less$/;
76
+
77
+ const hasJsxRuntime = (() => {
78
+ if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
79
+ return false;
80
+ }
81
+
82
+ try {
83
+ require.resolve('react/jsx-runtime');
84
+ return true;
85
+ } catch (e) {
86
+ return false;
87
+ }
88
+ })();
89
+
90
+ // This is the production and development configuration.
91
+ // It is focused on developer experience, fast rebuilds, and a minimal bundle.
92
+ module.exports = function (webpackEnv) {
93
+ const isEnvDevelopment = webpackEnv === 'development';
94
+ const isEnvProduction = webpackEnv === 'production';
95
+
96
+ // Variable used for enabling profiling in Production
97
+ // passed into alias object. Uses a flag if passed into the build command
98
+ const isEnvProductionProfile =
99
+ isEnvProduction && process.argv.includes('--profile');
100
+
101
+ // We will provide `paths.publicUrlOrPath` to our app
102
+ // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
103
+ // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
104
+ // Get environment variables to inject into our app.
105
+ const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
106
+
107
+ const shouldUseReactRefresh = env.raw.FAST_REFRESH;
108
+
109
+ // common function to get style loaders
110
+ const getStyleLoaders = (cssOptions, preProcessor) => {
111
+ const loaders = [
112
+ isEnvDevelopment && require.resolve('style-loader'),
113
+ isEnvProduction && {
114
+ loader: MiniCssExtractPlugin.loader,
115
+ // css is located in `static/css`, use '../../' to locate index.html folder
116
+ // in production `paths.publicUrlOrPath` can be a relative path
117
+ options: paths.publicUrlOrPath.startsWith('.')
118
+ ? { publicPath: '../../' }
119
+ : {},
120
+ },
121
+ {
122
+ loader: require.resolve('css-loader'),
123
+ options: cssOptions,
124
+ },
125
+ {
126
+ // Options for PostCSS as we reference these options twice
127
+ // Adds vendor prefixing based on your specified browser support in
128
+ // package.json
129
+ loader: require.resolve('postcss-loader'),
130
+ options: {
131
+ postcssOptions: {
132
+ // Necessary for external CSS imports to work
133
+ // https://github.com/facebook/create-react-app/issues/2677
134
+ ident: 'postcss',
135
+ config: false,
136
+ plugins: !useTailwind
137
+ ? [
138
+ 'postcss-flexbugs-fixes',
139
+ [
140
+ 'postcss-preset-env',
141
+ {
142
+ autoprefixer: {
143
+ flexbox: 'no-2009',
144
+ },
145
+ stage: 3,
146
+ },
147
+ ],
148
+ // Adds PostCSS Normalize as the reset css with default options,
149
+ // so that it honors browserslist config in package.json
150
+ // which in turn let's users customize the target behavior as per their needs.
151
+ 'postcss-normalize',
152
+ ]
153
+ : [
154
+ 'tailwindcss',
155
+ 'postcss-flexbugs-fixes',
156
+ [
157
+ 'postcss-preset-env',
158
+ {
159
+ autoprefixer: {
160
+ flexbox: 'no-2009',
161
+ },
162
+ stage: 3,
163
+ },
164
+ ],
165
+ ],
166
+ },
167
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
168
+ },
169
+ },
170
+ ].filter(Boolean);
171
+ if (preProcessor) {
172
+ loaders.push(
173
+ {
174
+ loader: require.resolve('resolve-url-loader'),
175
+ options: {
176
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
177
+ root: paths.appSrc,
178
+ },
179
+ },
180
+ {
181
+ loader: require.resolve(preProcessor),
182
+ options: {
183
+ sourceMap: true,
184
+ },
185
+ }
186
+ );
187
+ }
188
+ return loaders;
189
+ };
190
+
191
+ return {
192
+ target: ['browserslist'],
193
+ // Webpack noise constrained to errors and warnings
194
+ stats: 'errors-warnings',
195
+ mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
196
+ // Stop compilation early in production
197
+ bail: isEnvProduction,
198
+ devtool: isEnvProduction
199
+ ? shouldUseSourceMap
200
+ ? 'source-map'
201
+ : false
202
+ : isEnvDevelopment && 'cheap-module-source-map',
203
+ // These are the "entry points" to our application.
204
+ // This means they will be the "root" imports that are included in JS bundle.
205
+ entry: paths.appIndexJs,
206
+ output: {
207
+ // The build folder.
208
+ path: paths.appBuild,
209
+ // Add /* filename */ comments to generated require()s in the output.
210
+ pathinfo: isEnvDevelopment,
211
+ // There will be one main bundle, and one file per asynchronous chunk.
212
+ // In development, it does not produce real files.
213
+ filename: isEnvProduction
214
+ ? 'static/js/[name].[contenthash:8].js'
215
+ : isEnvDevelopment && 'static/js/bundle.js',
216
+ // There are also additional JS chunk files if you use code splitting.
217
+ chunkFilename: isEnvProduction
218
+ ? 'static/js/[name].[contenthash:8].chunk.js'
219
+ : isEnvDevelopment && 'static/js/[name].chunk.js',
220
+ assetModuleFilename: 'static/media/[name].[hash][ext]',
221
+ // webpack uses `publicPath` to determine where the app is being served from.
222
+ // It requires a trailing slash, or the file assets will get an incorrect path.
223
+ // We inferred the "public path" (such as / or /my-project) from homepage.
224
+ publicPath: paths.publicUrlOrPath,
225
+ // Point sourcemap entries to original disk location (format as URL on Windows)
226
+ devtoolModuleFilenameTemplate: isEnvProduction
227
+ ? info =>
228
+ path
229
+ .relative(paths.appSrc, info.absoluteResourcePath)
230
+ .replace(/\\/g, '/')
231
+ : isEnvDevelopment &&
232
+ (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
233
+ },
234
+ cache: {
235
+ type: 'filesystem',
236
+ version: createEnvironmentHash(env.raw),
237
+ cacheDirectory: paths.appWebpackCache,
238
+ store: 'pack',
239
+ buildDependencies: {
240
+ defaultWebpack: ['webpack/lib/'],
241
+ config: [__filename],
242
+ tsconfig: [paths.appTsConfig, paths.appJsConfig].filter(f =>
243
+ fs.existsSync(f)
244
+ ),
245
+ },
246
+ },
247
+ infrastructureLogging: {
248
+ level: 'none',
249
+ },
250
+ optimization: {
251
+ minimize: isEnvProduction,
252
+ minimizer: [
253
+ // This is only used in production mode
254
+ new TerserPlugin({
255
+ terserOptions: {
256
+ parse: {
257
+ // We want terser to parse ecma 8 code. However, we don't want it
258
+ // to apply any minification steps that turns valid ecma 5 code
259
+ // into invalid ecma 5 code. This is why the 'compress' and 'output'
260
+ // sections only apply transformations that are ecma 5 safe
261
+ // https://github.com/facebook/create-react-app/pull/4234
262
+ ecma: 8,
263
+ },
264
+ compress: {
265
+ ecma: 5,
266
+ warnings: false,
267
+ // Disabled because of an issue with Uglify breaking seemingly valid code:
268
+ // https://github.com/facebook/create-react-app/issues/2376
269
+ // Pending further investigation:
270
+ // https://github.com/mishoo/UglifyJS2/issues/2011
271
+ comparisons: false,
272
+ // Disabled because of an issue with Terser breaking valid code:
273
+ // https://github.com/facebook/create-react-app/issues/5250
274
+ // Pending further investigation:
275
+ // https://github.com/terser-js/terser/issues/120
276
+ inline: 2,
277
+ },
278
+ mangle: {
279
+ safari10: true,
280
+ },
281
+ // Added for profiling in devtools
282
+ keep_classnames: isEnvProductionProfile,
283
+ keep_fnames: isEnvProductionProfile,
284
+ output: {
285
+ ecma: 5,
286
+ comments: false,
287
+ // Turned on because emoji and regex is not minified properly using default
288
+ // https://github.com/facebook/create-react-app/issues/2488
289
+ ascii_only: true,
290
+ },
291
+ },
292
+ }),
293
+ // This is only used in production mode
294
+ new CssMinimizerPlugin(),
295
+ ],
296
+ },
297
+ resolve: {
298
+ // This allows you to set a fallback for where webpack should look for modules.
299
+ // We placed these paths second because we want `node_modules` to "win"
300
+ // if there are any conflicts. This matches Node resolution mechanism.
301
+ // https://github.com/facebook/create-react-app/issues/253
302
+ modules: ['node_modules', paths.appNodeModules].concat(
303
+ modules.additionalModulePaths || []
304
+ ),
305
+ // These are the reasonable defaults supported by the Node ecosystem.
306
+ // We also include JSX as a common component filename extension to support
307
+ // some tools, although we do not recommend using it, see:
308
+ // https://github.com/facebook/create-react-app/issues/290
309
+ // `web` extension prefixes have been added for better support
310
+ // for React Native Web.
311
+ extensions: paths.moduleFileExtensions
312
+ .map(ext => `.${ext}`)
313
+ .filter(ext => useTypeScript || !ext.includes('ts')),
314
+ alias: {
315
+ // Support React Native Web
316
+ // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
317
+ 'react-native': 'react-native-web',
318
+ // Allows for better profiling with ReactDevTools
319
+ ...(isEnvProductionProfile && {
320
+ 'react-dom$': 'react-dom/profiling',
321
+ 'scheduler/tracing': 'scheduler/tracing-profiling',
322
+ }),
323
+ ...(modules.webpackAliases || {}),
324
+ },
325
+ plugins: [
326
+ // Prevents users from importing files from outside of src/ (or node_modules/).
327
+ // This often causes confusion because we only process files within src/ with babel.
328
+ // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
329
+ // please link the files into your node_modules/ and let module-resolution kick in.
330
+ // Make sure your source files are compiled, as they will not be processed in any way.
331
+ new ModuleScopePlugin(paths.appSrc, [
332
+ paths.appPackageJson,
333
+ reactRefreshRuntimeEntry,
334
+ reactRefreshWebpackPluginRuntimeEntry,
335
+ babelRuntimeEntry,
336
+ babelRuntimeEntryHelpers,
337
+ babelRuntimeRegenerator,
338
+ ]),
339
+ ],
340
+ },
341
+ module: {
342
+ strictExportPresence: true,
343
+ rules: [
344
+ // Handle node_modules packages that contain sourcemaps
345
+ shouldUseSourceMap && {
346
+ enforce: 'pre',
347
+ exclude: /@babel(?:\/|\\{1,2})runtime/,
348
+ test: /\.(js|mjs|jsx|ts|tsx|css)$/,
349
+ loader: require.resolve('source-map-loader'),
350
+ },
351
+ {
352
+ // "oneOf" will traverse all following loaders until one will
353
+ // match the requirements. When no loader matches it will fall
354
+ // back to the "file" loader at the end of the loader list.
355
+ oneOf: [
356
+ // TODO: Merge this config once `image/avif` is in the mime-db
357
+ // https://github.com/jshttp/mime-db
358
+ {
359
+ test: [/\.avif$/],
360
+ type: 'asset',
361
+ mimetype: 'image/avif',
362
+ parser: {
363
+ dataUrlCondition: {
364
+ maxSize: imageInlineSizeLimit,
365
+ },
366
+ },
367
+ },
368
+ // "url" loader works like "file" loader except that it embeds assets
369
+ // smaller than specified limit in bytes as data URLs to avoid requests.
370
+ // A missing `test` is equivalent to a match.
371
+ {
372
+ test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
373
+ type: 'asset',
374
+ parser: {
375
+ dataUrlCondition: {
376
+ maxSize: imageInlineSizeLimit,
377
+ },
378
+ },
379
+ },
380
+ {
381
+ test: /\.svg$/,
382
+ use: [
383
+ {
384
+ loader: require.resolve('@svgr/webpack'),
385
+ options: {
386
+ prettier: false,
387
+ svgo: false,
388
+ svgoConfig: {
389
+ plugins: [{ removeViewBox: false }],
390
+ },
391
+ titleProp: true,
392
+ ref: true,
393
+ },
394
+ },
395
+ {
396
+ loader: require.resolve('file-loader'),
397
+ options: {
398
+ name: 'static/media/[name].[hash].[ext]',
399
+ },
400
+ },
401
+ ],
402
+ issuer: {
403
+ and: [/\.(ts|tsx|js|jsx|md|mdx)$/],
404
+ },
405
+ },
406
+ // Process application JS with Babel.
407
+ // The preset includes JSX, Flow, TypeScript, and some ESnext features.
408
+ {
409
+ test: /\.(js|mjs|jsx|ts|tsx)$/,
410
+ include: paths.appSrc,
411
+ loader: require.resolve('babel-loader'),
412
+ options: {
413
+ customize: require.resolve(
414
+ 'babel-preset-react-app/webpack-overrides'
415
+ ),
416
+ presets: [
417
+ [
418
+ require.resolve('babel-preset-react-app'),
419
+ {
420
+ runtime: hasJsxRuntime ? 'automatic' : 'classic',
421
+ },
422
+ ],
423
+ ],
424
+
425
+ plugins: [
426
+ isEnvDevelopment &&
427
+ shouldUseReactRefresh &&
428
+ require.resolve('react-refresh/babel'),
429
+ ].filter(Boolean),
430
+ // This is a feature of `babel-loader` for webpack (not Babel itself).
431
+ // It enables caching results in ./node_modules/.cache/babel-loader/
432
+ // directory for faster rebuilds.
433
+ cacheDirectory: true,
434
+ // See #6846 for context on why cacheCompression is disabled
435
+ cacheCompression: false,
436
+ compact: isEnvProduction,
437
+ },
438
+ },
439
+ // Process any JS outside of the app with Babel.
440
+ // Unlike the application JS, we only compile the standard ES features.
441
+ {
442
+ test: /\.(js|mjs)$/,
443
+ exclude: /@babel(?:\/|\\{1,2})runtime/,
444
+ loader: require.resolve('babel-loader'),
445
+ options: {
446
+ babelrc: false,
447
+ configFile: false,
448
+ compact: false,
449
+ presets: [
450
+ [
451
+ require.resolve('babel-preset-react-app/dependencies'),
452
+ { helpers: true },
453
+ ],
454
+ ],
455
+ cacheDirectory: true,
456
+ // See #6846 for context on why cacheCompression is disabled
457
+ cacheCompression: false,
458
+
459
+ // Babel sourcemaps are needed for debugging into node_modules
460
+ // code. Without the options below, debuggers like VSCode
461
+ // show incorrect code and set breakpoints on the wrong lines.
462
+ sourceMaps: shouldUseSourceMap,
463
+ inputSourceMap: shouldUseSourceMap,
464
+ },
465
+ },
466
+ // "postcss" loader applies autoprefixer to our CSS.
467
+ // "css" loader resolves paths in CSS and adds assets as dependencies.
468
+ // "style" loader turns CSS into JS modules that inject <style> tags.
469
+ // In production, we use MiniCSSExtractPlugin to extract that CSS
470
+ // to a file, but in development "style" loader enables hot editing
471
+ // of CSS.
472
+ // By default we support CSS Modules with the extension .module.css
473
+ {
474
+ test: cssRegex,
475
+ exclude: cssModuleRegex,
476
+ use: getStyleLoaders({
477
+ importLoaders: 1,
478
+ sourceMap: isEnvProduction
479
+ ? shouldUseSourceMap
480
+ : isEnvDevelopment,
481
+ modules: {
482
+ mode: 'icss',
483
+ },
484
+ }),
485
+ // Don't consider CSS imports dead code even if the
486
+ // containing package claims to have no side effects.
487
+ // Remove this when webpack adds a warning or an error for this.
488
+ // See https://github.com/webpack/webpack/issues/6571
489
+ sideEffects: true,
490
+ },
491
+ // Adds support for CSS Modules (https://github.com/css-modules/css-modules)
492
+ // using the extension .module.css
493
+ {
494
+ test: cssModuleRegex,
495
+ use: getStyleLoaders({
496
+ importLoaders: 1,
497
+ sourceMap: isEnvProduction
498
+ ? shouldUseSourceMap
499
+ : isEnvDevelopment,
500
+ modules: {
501
+ mode: 'local',
502
+ getLocalIdent: getCSSModuleLocalIdent,
503
+ },
504
+ }),
505
+ },
506
+ // Opt-in support for SASS (using .scss or .sass extensions).
507
+ // By default we support SASS Modules with the
508
+ // extensions .module.scss or .module.sass
509
+ {
510
+ test: sassRegex,
511
+ exclude: sassModuleRegex,
512
+ use: getStyleLoaders(
513
+ {
514
+ importLoaders: 3,
515
+ sourceMap: isEnvProduction
516
+ ? shouldUseSourceMap
517
+ : isEnvDevelopment,
518
+ modules: {
519
+ mode: 'icss',
520
+ },
521
+ },
522
+ 'sass-loader'
523
+ ),
524
+ // Don't consider CSS imports dead code even if the
525
+ // containing package claims to have no side effects.
526
+ // Remove this when webpack adds a warning or an error for this.
527
+ // See https://github.com/webpack/webpack/issues/6571
528
+ sideEffects: true,
529
+ },
530
+ // Adds support for CSS Modules, but using SASS
531
+ // using the extension .module.scss or .module.sass
532
+ {
533
+ test: sassModuleRegex,
534
+ use: getStyleLoaders(
535
+ {
536
+ importLoaders: 3,
537
+ sourceMap: isEnvProduction
538
+ ? shouldUseSourceMap
539
+ : isEnvDevelopment,
540
+ modules: {
541
+ mode: 'local',
542
+ getLocalIdent: getCSSModuleLocalIdent,
543
+ },
544
+ },
545
+ 'sass-loader'
546
+ ),
547
+ },
548
+ {
549
+ test: lessRegex,
550
+ exclude: lessModuleRegex,
551
+ use: getStyleLoaders(
552
+ {
553
+ importLoaders: 2,
554
+ sourceMap: isEnvProduction && shouldUseSourceMap,
555
+ },
556
+ 'less-loader'
557
+ ),
558
+ sideEffects: true,
559
+ },
560
+ {
561
+ test: lessModuleRegex,
562
+ use: getStyleLoaders(
563
+ {
564
+ importLoaders: 3,
565
+ sourceMap: isEnvProduction
566
+ ? shouldUseSourceMap
567
+ : isEnvDevelopment,
568
+ modules: {
569
+ mode: 'local',
570
+ getLocalIdent: getCSSModuleLocalIdent,
571
+ },
572
+ },
573
+ 'less-loader'
574
+ )
575
+ },
576
+ // "file" loader makes sure those assets get served by WebpackDevServer.
577
+ // When you `import` an asset, you get its (virtual) filename.
578
+ // In production, they would get copied to the `build` folder.
579
+ // This loader doesn't use a "test" so it will catch all modules
580
+ // that fall through the other loaders.
581
+ {
582
+ // Exclude `js` files to keep "css" loader working as it injects
583
+ // its runtime that would otherwise be processed through "file" loader.
584
+ // Also exclude `html` and `json` extensions so they get processed
585
+ // by webpacks internal loaders.
586
+ exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
587
+ type: 'asset/resource',
588
+ },
589
+ // ** STOP ** Are you adding a new loader?
590
+ // Make sure to add the new loader(s) before the "file" loader.
591
+ ],
592
+ },
593
+ ].filter(Boolean),
594
+ },
595
+ plugins: [
596
+ // Generates an `index.html` file with the <script> injected.
597
+ new HtmlWebpackPlugin(
598
+ Object.assign(
599
+ {},
600
+ {
601
+ inject: true,
602
+ template: paths.appHtml,
603
+ },
604
+ isEnvProduction
605
+ ? {
606
+ minify: {
607
+ removeComments: true,
608
+ collapseWhitespace: true,
609
+ removeRedundantAttributes: true,
610
+ useShortDoctype: true,
611
+ removeEmptyAttributes: true,
612
+ removeStyleLinkTypeAttributes: true,
613
+ keepClosingSlash: true,
614
+ minifyJS: true,
615
+ minifyCSS: true,
616
+ minifyURLs: true,
617
+ },
618
+ }
619
+ : undefined
620
+ )
621
+ ),
622
+ // Inlines the webpack runtime script. This script is too small to warrant
623
+ // a network request.
624
+ // https://github.com/facebook/create-react-app/issues/5358
625
+ isEnvProduction &&
626
+ shouldInlineRuntimeChunk &&
627
+ new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime-.+[.]js/]),
628
+ // Makes some environment variables available in index.html.
629
+ // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
630
+ // <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
631
+ // It will be an empty string unless you specify "homepage"
632
+ // in `package.json`, in which case it will be the pathname of that URL.
633
+ new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
634
+ // This gives some necessary context to module not found errors, such as
635
+ // the requesting resource.
636
+ new ModuleNotFoundPlugin(paths.appPath),
637
+ // Makes some environment variables available to the JS code, for example:
638
+ // if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
639
+ // It is absolutely essential that NODE_ENV is set to production
640
+ // during a production build.
641
+ // Otherwise React will be compiled in the very slow development mode.
642
+ new webpack.DefinePlugin(env.stringified),
643
+ // Experimental hot reloading for React .
644
+ // https://github.com/facebook/react/tree/main/packages/react-refresh
645
+ isEnvDevelopment &&
646
+ shouldUseReactRefresh &&
647
+ new ReactRefreshWebpackPlugin({
648
+ overlay: false,
649
+ }),
650
+ // Watcher doesn't work well if you mistype casing in a path so we use
651
+ // a plugin that prints an error when you attempt to do this.
652
+ // See https://github.com/facebook/create-react-app/issues/240
653
+ isEnvDevelopment && new CaseSensitivePathsPlugin(),
654
+ isEnvProduction &&
655
+ new MiniCssExtractPlugin({
656
+ // Options similar to the same options in webpackOptions.output
657
+ // both options are optional
658
+ filename: 'static/css/[name].[contenthash:8].css',
659
+ chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
660
+ }),
661
+ // Generate an asset manifest file with the following content:
662
+ // - "files" key: Mapping of all asset filenames to their corresponding
663
+ // output file so that tools can pick it up without having to parse
664
+ // `index.html`
665
+ // - "entrypoints" key: Array of files which are included in `index.html`,
666
+ // can be used to reconstruct the HTML if necessary
667
+ new WebpackManifestPlugin({
668
+ fileName: 'asset-manifest.json',
669
+ publicPath: paths.publicUrlOrPath,
670
+ generate: (seed, files, entrypoints) => {
671
+ const manifestFiles = files.reduce((manifest, file) => {
672
+ manifest[file.name] = file.path;
673
+ return manifest;
674
+ }, seed);
675
+ const entrypointFiles = entrypoints.main.filter(
676
+ fileName => !fileName.endsWith('.map')
677
+ );
678
+
679
+ return {
680
+ files: manifestFiles,
681
+ entrypoints: entrypointFiles,
682
+ };
683
+ },
684
+ }),
685
+ // Moment.js is an extremely popular library that bundles large locale files
686
+ // by default due to how webpack interprets its code. This is a practical
687
+ // solution that requires the user to opt into importing specific locales.
688
+ // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
689
+ // You can remove this if you don't use Moment.js:
690
+ new webpack.IgnorePlugin({
691
+ resourceRegExp: /^\.\/locale$/,
692
+ contextRegExp: /moment$/,
693
+ }),
694
+ // Generate a service worker script that will precache, and keep up to date,
695
+ // the HTML & assets that are part of the webpack build.
696
+ isEnvProduction &&
697
+ fs.existsSync(swSrc) &&
698
+ new WorkboxWebpackPlugin.InjectManifest({
699
+ swSrc,
700
+ dontCacheBustURLsMatching: /\.[0-9a-f]{8}\./,
701
+ exclude: [/\.map$/, /asset-manifest\.json$/, /LICENSE/],
702
+ // Bump up the default maximum size (2mb) that's precached,
703
+ // to make lazy-loading failure scenarios less likely.
704
+ // See https://github.com/cra-template/pwa/issues/13#issuecomment-722667270
705
+ maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
706
+ }),
707
+ // TypeScript type checking
708
+ useTypeScript &&
709
+ new ForkTsCheckerWebpackPlugin({
710
+ async: isEnvDevelopment,
711
+ typescript: {
712
+ typescriptPath: resolve.sync('typescript', {
713
+ basedir: paths.appNodeModules,
714
+ }),
715
+ configOverwrite: {
716
+ compilerOptions: {
717
+ sourceMap: isEnvProduction
718
+ ? shouldUseSourceMap
719
+ : isEnvDevelopment,
720
+ skipLibCheck: true,
721
+ inlineSourceMap: false,
722
+ declarationMap: false,
723
+ noEmit: true,
724
+ incremental: true,
725
+ tsBuildInfoFile: paths.appTsBuildInfoFile,
726
+ },
727
+ },
728
+ context: paths.appPath,
729
+ diagnosticOptions: {
730
+ syntactic: true,
731
+ },
732
+ mode: 'write-references',
733
+ // profile: true,
734
+ },
735
+ issue: {
736
+ // This one is specifically to match during CI tests,
737
+ // as micromatch doesn't match
738
+ // '../cra-template-typescript/template/src/App.tsx'
739
+ // otherwise.
740
+ include: [
741
+ { file: '../**/src/**/*.{ts,tsx}' },
742
+ { file: '**/src/**/*.{ts,tsx}' },
743
+ ],
744
+ exclude: [
745
+ { file: '**/src/**/__tests__/**' },
746
+ { file: '**/src/**/?(*.){spec|test}.*' },
747
+ { file: '**/src/setupProxy.*' },
748
+ { file: '**/src/setupTests.*' },
749
+ ],
750
+ },
751
+ logger: {
752
+ infrastructure: 'silent',
753
+ },
754
+ }),
755
+ !disableESLintPlugin &&
756
+ new ESLintPlugin({
757
+ // Plugin options
758
+ extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
759
+ formatter: require.resolve('react-dev-utils/eslintFormatter'),
760
+ eslintPath: require.resolve('eslint'),
761
+ failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),
762
+ context: paths.appSrc,
763
+ cache: true,
764
+ cacheLocation: path.resolve(
765
+ paths.appNodeModules,
766
+ '.cache/.eslintcache'
767
+ ),
768
+ // ESLint class options
769
+ cwd: paths.appPath,
770
+ resolvePluginsRelativeTo: __dirname,
771
+ baseConfig: {
772
+ extends: [require.resolve('eslint-config-react-app/base')],
773
+ rules: {
774
+ ...(!hasJsxRuntime && {
775
+ 'react/react-in-jsx-scope': 'error',
776
+ }),
777
+ },
778
+ },
779
+ }),
780
+ ].filter(Boolean),
781
+ // Turn off performance processing because we utilize
782
+ // our own hints via the FileSizeReporter
783
+ performance: false,
784
+ };
785
+ };