@panoramax/web-viewer 3.0.2-develop-a8ea8e60

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