@commercetools-frontend/mc-scripts 21.7.0 → 21.9.0

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 (152) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -42
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +1 -0
  4. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
  5. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
  6. package/{build/config/application-runtime.js → application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js} +2 -2
  7. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
  8. package/application-runtime/package.json +4 -0
  9. package/bin/cli.js +1 -1
  10. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +1 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +361 -0
  12. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
  13. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +361 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +345 -0
  15. package/cli/package.json +4 -0
  16. package/config/create-webpack-config-for-development.js +7 -1
  17. package/config/create-webpack-config-for-production.js +7 -1
  18. package/config/vendors-to-transpile.js +5 -1
  19. package/dist/build-5357ad26.cjs.prod.js +224 -0
  20. package/dist/build-9b6d7eee.cjs.dev.js +224 -0
  21. package/dist/build-c483e87f.esm.js +209 -0
  22. package/dist/build-vite-3b82522e.cjs.dev.js +151 -0
  23. package/dist/build-vite-93abdc95.esm.js +139 -0
  24. package/dist/build-vite-b7cd993a.cjs.prod.js +151 -0
  25. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +1 -0
  26. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +30 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +30 -0
  29. package/dist/commercetools-frontend-mc-scripts.esm.js +22 -0
  30. package/dist/compile-html-4361a0b3.esm.js +77 -0
  31. package/dist/compile-html-d6331c35.cjs.prod.js +87 -0
  32. package/dist/compile-html-d9e731aa.cjs.dev.js +87 -0
  33. package/dist/config-sync-6b31d972.esm.js +840 -0
  34. package/dist/config-sync-a478bc0f.cjs.dev.js +864 -0
  35. package/dist/config-sync-f07734e4.cjs.prod.js +859 -0
  36. package/{build/config/create-postcss-config.js → dist/create-postcss-config-04243dea.esm.js} +27 -25
  37. package/dist/create-postcss-config-760e2dc5.cjs.dev.js +90 -0
  38. package/dist/create-postcss-config-ddc3abee.cjs.prod.js +90 -0
  39. package/dist/create-webpack-config-for-development-76fdab59.cjs.prod.js +419 -0
  40. package/{build/config/create-webpack-config-for-development.js → dist/create-webpack-config-for-development-d93ae4b2.esm.js} +94 -57
  41. package/dist/create-webpack-config-for-development-dfd1c174.cjs.dev.js +419 -0
  42. package/{build/config/create-webpack-config-for-production.js → dist/create-webpack-config-for-production-9290479a.esm.js} +120 -54
  43. package/dist/create-webpack-config-for-production-bc8c1f37.cjs.dev.js +469 -0
  44. package/dist/create-webpack-config-for-production-d652ad1a.cjs.prod.js +469 -0
  45. package/dist/declarations/src/application-runtime.d.ts +1 -0
  46. package/dist/declarations/src/cli.d.ts +4 -0
  47. package/dist/declarations/src/commands/build-vite.d.ts +2 -0
  48. package/dist/declarations/src/commands/build.d.ts +2 -0
  49. package/dist/declarations/src/commands/compile-html.d.ts +3 -0
  50. package/dist/declarations/src/commands/config-sync.d.ts +3 -0
  51. package/dist/declarations/src/commands/login.d.ts +2 -0
  52. package/dist/declarations/src/commands/serve.d.ts +2 -0
  53. package/dist/declarations/src/commands/start-vite.d.ts +2 -0
  54. package/dist/declarations/src/commands/start.d.ts +2 -0
  55. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  56. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  57. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  58. package/dist/declarations/src/config/has-jsx-runtime.d.ts +2 -0
  59. package/dist/declarations/src/config/moment-locales.d.ts +2 -0
  60. package/dist/declarations/src/config/paths.d.ts +12 -0
  61. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  62. package/dist/declarations/src/config/webpack-dev-server.config.d.ts +6 -0
  63. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  64. package/dist/declarations/src/generated/core.d.ts +710 -0
  65. package/dist/declarations/src/generated/settings.d.ts +2485 -0
  66. package/dist/declarations/src/index.d.ts +3 -0
  67. package/dist/declarations/src/postcss.d.ts +1 -0
  68. package/dist/declarations/src/types.d.ts +82 -0
  69. package/dist/declarations/src/utils/auth.d.ts +6 -0
  70. package/dist/declarations/src/utils/credentials-storage.d.ts +11 -0
  71. package/dist/declarations/src/utils/get-config-diff.d.ts +3 -0
  72. package/dist/declarations/src/utils/graphql-requests.d.ts +80 -0
  73. package/dist/declarations/src/utils/user-agent.d.ts +2 -0
  74. package/dist/declarations/src/version.d.ts +2 -0
  75. package/dist/declarations/src/vite-plugins/vite-plugin-custom-application.d.ts +4 -0
  76. package/dist/declarations/src/vite-plugins/vite-plugin-dynamic-base-assets-globals.d.ts +3 -0
  77. package/dist/declarations/src/vite-plugins/vite-plugin-svgr.d.ts +3 -0
  78. package/dist/declarations/src/webpack-plugins/final-stats-writer-plugin.d.ts +12 -0
  79. package/dist/declarations/src/webpack-plugins/local-html-webpack-plugin.d.ts +5 -0
  80. package/dist/declarations/src/webpack.d.ts +2 -0
  81. package/dist/has-jsx-runtime-0b03b72e.cjs.prod.js +17 -0
  82. package/dist/has-jsx-runtime-3d4bb633.cjs.dev.js +17 -0
  83. package/{build/config/has-jsx-runtime.js → dist/has-jsx-runtime-8314226e.esm.js} +1 -3
  84. package/dist/login-7b7ae27e.esm.js +155 -0
  85. package/dist/login-b13f26e7.cjs.dev.js +165 -0
  86. package/dist/login-c11fb977.cjs.prod.js +165 -0
  87. package/dist/package-4b4fcf02.cjs.prod.js +139 -0
  88. package/dist/package-4c3e3fb7.cjs.dev.js +139 -0
  89. package/dist/package-8e6305bd.esm.js +137 -0
  90. package/dist/paths-16823f56.cjs.dev.js +55 -0
  91. package/dist/paths-76b66e74.cjs.prod.js +55 -0
  92. package/dist/paths-ed23d5a1.esm.js +46 -0
  93. package/dist/serve-12de323b.cjs.dev.js +70 -0
  94. package/dist/serve-784f4fcd.cjs.prod.js +70 -0
  95. package/dist/serve-d6b437b1.esm.js +62 -0
  96. package/dist/start-1b7dad90.cjs.prod.js +209 -0
  97. package/dist/start-45ca01f2.cjs.dev.js +209 -0
  98. package/dist/start-600d06a3.esm.js +194 -0
  99. package/dist/start-vite-22de08dc.cjs.dev.js +151 -0
  100. package/dist/start-vite-dc046cba.esm.js +138 -0
  101. package/dist/start-vite-fe13330b.cjs.prod.js +151 -0
  102. package/dist/user-agent-5f8ec93d.cjs.prod.js +106 -0
  103. package/dist/user-agent-ca628320.esm.js +94 -0
  104. package/dist/user-agent-ee57c98a.cjs.dev.js +106 -0
  105. package/dist/vendors-to-transpile-367e0ba8.cjs.prod.js +5 -0
  106. package/dist/vendors-to-transpile-68e03526.esm.js +3 -0
  107. package/dist/vendors-to-transpile-b51af5d3.cjs.dev.js +5 -0
  108. package/dist/vite-plugin-svgr-4205f2b5.cjs.dev.js +110 -0
  109. package/dist/vite-plugin-svgr-eb8524fa.esm.js +85 -0
  110. package/dist/vite-plugin-svgr-f3bbedbe.cjs.prod.js +110 -0
  111. package/package.json +56 -50
  112. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +1 -0
  113. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +14 -0
  114. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  115. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +14 -0
  116. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +6 -0
  117. package/postcss/package.json +4 -0
  118. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +1 -0
  119. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +51 -0
  120. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  121. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +51 -0
  122. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +42 -0
  123. package/webpack/package.json +4 -0
  124. package/build/bin/cli.js +0 -264
  125. package/build/commands/build-vite.js +0 -91
  126. package/build/commands/build.js +0 -140
  127. package/build/commands/compile-html.js +0 -53
  128. package/build/commands/config-sync.js +0 -176
  129. package/build/commands/login.js +0 -60
  130. package/build/commands/serve.js +0 -37
  131. package/build/commands/start-vite.js +0 -138
  132. package/build/commands/start.js +0 -108
  133. package/build/config/paths.js +0 -38
  134. package/build/config/vendors-to-transpile.js +0 -3
  135. package/build/config/webpack-dev-server.config.js +0 -69
  136. package/build/index.js +0 -16
  137. package/build/utils/auth.js +0 -34
  138. package/build/utils/auth.spec.js +0 -61
  139. package/build/utils/create-custom-application.settings.graphql +0 -8
  140. package/build/utils/credentials-storage.js +0 -72
  141. package/build/utils/credentials-storage.spec.js +0 -69
  142. package/build/utils/fetch-custom-application.settings.graphql +0 -36
  143. package/build/utils/fetch-user-organizations.core.graphql +0 -9
  144. package/build/utils/get-config-diff.js +0 -308
  145. package/build/utils/get-config-diff.spec.js +0 -285
  146. package/build/utils/graphql-requests.js +0 -105
  147. package/build/utils/graphql-requests.spec.js +0 -159
  148. package/build/utils/require-graphql.js +0 -15
  149. package/build/utils/update-custom-application.settings.graphql +0 -13
  150. package/build/utils/user-agent.js +0 -15
  151. package/build/webpack-plugins/final-stats-writer-plugin.js +0 -50
  152. package/build/webpack-plugins/local-html-webpack-plugin.js +0 -38
@@ -0,0 +1,469 @@
1
+ 'use strict';
2
+
3
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
4
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
5
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
6
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
7
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
8
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
9
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
10
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
11
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
12
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
13
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
14
+ var _endsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/ends-with');
15
+ var _Number$isInteger = require('@babel/runtime-corejs3/core-js-stable/number/is-integer');
16
+ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
17
+ var webpack = require('webpack');
18
+ var HtmlWebpackPlugin = require('html-webpack-plugin');
19
+ var webpackBundleAnalyzer = require('webpack-bundle-analyzer');
20
+ var CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
21
+ var MiniCssExtractPlugin = require('mini-css-extract-plugin');
22
+ var MomentLocalesPlugin = require('moment-locales-webpack-plugin');
23
+ var TerserPlugin = require('terser-webpack-plugin');
24
+ var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
25
+ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
26
+ var _bindInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/bind');
27
+ var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
28
+ var _Object$assign = require('@babel/runtime-corejs3/core-js-stable/object/assign');
29
+ var fs = require('fs');
30
+ var path = require('path');
31
+ var paths = require('./paths-16823f56.cjs.dev.js');
32
+ var vendorsToTranspile = require('./vendors-to-transpile-b51af5d3.cjs.dev.js');
33
+ var createPostcssConfig = require('./create-postcss-config-760e2dc5.cjs.dev.js');
34
+ var hasJsxRuntime = require('./has-jsx-runtime-3d4bb633.cjs.dev.js');
35
+
36
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
37
+
38
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
39
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
40
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
41
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
42
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
43
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
44
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
45
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
46
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
47
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
48
+ var _endsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_endsWithInstanceProperty);
49
+ var _Number$isInteger__default = /*#__PURE__*/_interopDefault(_Number$isInteger);
50
+ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
51
+ var webpack__default = /*#__PURE__*/_interopDefault(webpack);
52
+ var HtmlWebpackPlugin__default = /*#__PURE__*/_interopDefault(HtmlWebpackPlugin);
53
+ var CssMinimizerPlugin__default = /*#__PURE__*/_interopDefault(CssMinimizerPlugin);
54
+ var MiniCssExtractPlugin__default = /*#__PURE__*/_interopDefault(MiniCssExtractPlugin);
55
+ var MomentLocalesPlugin__default = /*#__PURE__*/_interopDefault(MomentLocalesPlugin);
56
+ var TerserPlugin__default = /*#__PURE__*/_interopDefault(TerserPlugin);
57
+ var _bindInstanceProperty__default = /*#__PURE__*/_interopDefault(_bindInstanceProperty);
58
+ var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
59
+ var _Object$assign__default = /*#__PURE__*/_interopDefault(_Object$assign);
60
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
61
+ var path__default = /*#__PURE__*/_interopDefault(path);
62
+
63
+ var FinalStatsWriterPlugin = /*#__PURE__*/function () {
64
+ // Expected options:
65
+ // - `outputPath`
66
+ // - `includeFields`
67
+ function FinalStatsWriterPlugin(config) {
68
+ _classCallCheck(this, FinalStatsWriterPlugin);
69
+
70
+ this.config = void 0;
71
+ if (!config) throw new Error('Missing config options');
72
+ this.config = config;
73
+ }
74
+
75
+ _createClass(FinalStatsWriterPlugin, [{
76
+ key: "apply",
77
+ value: function apply(compiler) {
78
+ // This is the only hook that return the `stats` plugin
79
+ // with the `time` info. It also contains all the stats that
80
+ // we would get from the original `emit` hook.
81
+ // https://webpack.js.org/api/compiler-hooks/#done
82
+ // https://webpack.js.org/api/plugins/#plugin-types
83
+ if (compiler.hooks) {
84
+ var _context;
85
+
86
+ compiler.hooks.done.tap('custom-stats-writer-plugin', _bindInstanceProperty__default["default"](_context = this.writeStats).call(_context, this));
87
+ } else {
88
+ var _context2;
89
+
90
+ // @ts-ignore
91
+ compiler.plugin('done', _bindInstanceProperty__default["default"](_context2 = this.writeStats).call(_context2, this));
92
+ }
93
+ }
94
+ }, {
95
+ key: "writeStats",
96
+ value: function writeStats(stats) {
97
+ var finalStats = stats.toJson(); // Filter only included fields
98
+
99
+ if (this.config.includeFields) {
100
+ var _context3;
101
+
102
+ finalStats = _reduceInstanceProperty__default["default"](_context3 = this.config.includeFields).call(_context3, function (aggregatedStats, key) {
103
+ return (// eslint-disable-next-line
104
+ _Object$assign__default["default"]({}, aggregatedStats, _defineProperty({}, key, finalStats[key]))
105
+ );
106
+ }, {});
107
+ }
108
+
109
+ try {
110
+ fs__default["default"].accessSync(this.config.outputPath, fs__default["default"].constants.F_OK);
111
+ fs__default["default"].writeFileSync(path__default["default"].join(this.config.outputPath, 'stats.json'), _JSON$stringify__default["default"](finalStats, null, 2));
112
+ } catch (error) {
113
+ // eslint-disable-next-line no-console
114
+ console.warn("[FinalStatsWriterPlugin] The dist folder could not be found at ".concat(this.config.outputPath, ". Check the console for errors during the webpack compilation."));
115
+ }
116
+ }
117
+ }]);
118
+
119
+ return FinalStatsWriterPlugin;
120
+ }();
121
+
122
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
123
+
124
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context7, _context8; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context7 = ownKeys(Object(source), !0)).call(_context7, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context8 = ownKeys(Object(source))).call(_context8, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
125
+
126
+ var momentLocalesToKeep = ["de", "de-at", "de-ch", "en-au", "en-ca", "en-gb", "en-ie", "en-in", "en-nz", "en-sg", "es", "es-do", "es-mx", "fr", "ja", "zh-cn"];
127
+ var defaultToggleFlags = {
128
+ // Allow to disable CSS extraction in case it's not necessary (e.g. for Storybook)
129
+ enableExtractCss: true,
130
+ // Allow to disable index.html generation in case it's not necessary (e.g. for Storybook)
131
+ generateIndexHtml: true,
132
+ // Some plugins spawn workers to speed up the build. However this can cause trouble on
133
+ // certain machines local and CI. This flag set to limit or disable any parallelism.
134
+ // Options:
135
+ // `true` to default to the machines number of CPUs
136
+ // `false` to disable any paralelism
137
+ // `int` for a specific number of CPUs
138
+ parallelism: true,
139
+ // Some environemnts do not require `core-js` and can hence disable
140
+ // it explicitely. This will disable `core-js` for `preset-env` and the
141
+ // `plugin-transform-runtime`.
142
+ disableCoreJs: false
143
+ };
144
+ var defaultOptions = {
145
+ entryPoint: paths.paths.entryPoint,
146
+ sourceFolders: paths.paths.sourceFolders,
147
+ postcssOptions: {},
148
+ toggleFlags: defaultToggleFlags
149
+ };
150
+ /**
151
+ * This is a factory function to create the default webpack config
152
+ * for a MC Application in `production` mode.
153
+ * The function requires the file path to the related application
154
+ * "entry point".
155
+ */
156
+
157
+ function createWebpackConfigForProduction() {
158
+ var _context, _context2, _context3, _context4, _context5, _context6;
159
+
160
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
161
+
162
+ var mergedOptions = _objectSpread(_objectSpread(_objectSpread({}, defaultOptions), options), {}, {
163
+ toggleFlags: _objectSpread(_objectSpread({}, defaultToggleFlags), options.toggleFlags)
164
+ });
165
+
166
+ return {
167
+ // Don't attempt to continue if there are any errors.
168
+ bail: true,
169
+ // https://webpack.js.org/concepts/#mode
170
+ mode: 'production',
171
+ // We generate sourcemaps in production. This is slow but gives good results.
172
+ // Sourcemaps are pushed to Google Storage and Sentry.
173
+ // https://webpack.js.org/configuration/devtool/#devtool
174
+ devtool: 'source-map',
175
+ // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
176
+ // https://medium.com/webpack/webpack-4-mode-and-optimization-5423a6bc597a
177
+ optimization: {
178
+ minimizer: _filterInstanceProperty__default["default"](_context = [new TerserPlugin__default["default"]({
179
+ terserOptions: {
180
+ parse: {
181
+ // we want terser to parse ecma 8 code. However, we don't want it
182
+ // to apply any minification steps that turns valid ecma 5 code
183
+ // into invalid ecma 5 code. This is why the 'compress' and 'output'
184
+ // sections only apply transformations that are ecma 5 safe
185
+ // https://github.com/facebook/create-react-app/pull/4234
186
+ ecma: 2018
187
+ },
188
+ compress: {
189
+ ecma: 5,
190
+ warnings: false,
191
+ // Disabled because of an issue with Uglify breaking seemingly valid code:
192
+ // https://github.com/facebook/create-react-app/issues/2376
193
+ // Pending further investigation:
194
+ // https://github.com/mishoo/UglifyJS2/issues/2011
195
+ comparisons: false,
196
+ // Disabled because of an issue with Terser breaking valid code:
197
+ // https://github.com/facebook/create-react-app/issues/5250
198
+ // Pending futher investigation:
199
+ // https://github.com/terser-js/terser/issues/120
200
+ inline: 2
201
+ },
202
+ mangle: {
203
+ safari10: true
204
+ },
205
+ // Added for profiling in devtools
206
+ keep_classnames: true,
207
+ keep_fnames: true,
208
+ output: {
209
+ ecma: 5,
210
+ comments: false,
211
+ // Turned on because emoji and regex is not minified properly using default
212
+ // https://github.com/facebook/create-react-app/issues/2488
213
+ ascii_only: true
214
+ }
215
+ },
216
+ // Use multi-process parallel running to improve the build speed
217
+ // Default number of concurrent runs: os.cpus().length - 1
218
+ parallel: mergedOptions.toggleFlags.parallelism
219
+ }), mergedOptions.toggleFlags.enableExtractCss && new CssMinimizerPlugin__default["default"]()]).call(_context, Boolean),
220
+ // Keep the runtime chunk separated to enable long term caching
221
+ runtimeChunk: {
222
+ name: 'runtime'
223
+ },
224
+ moduleIds: 'named',
225
+ chunkIds: 'deterministic'
226
+ },
227
+ resolve: {
228
+ // These are the reasonable defaults supported by the Node ecosystem.
229
+ // We also include JSX as a common component filename extension to support
230
+ // some tools, although we do not recommend using it, see:
231
+ // https://github.com/facebook/create-react-app/issues/290
232
+ // `web` extension prefixes have been added for better support
233
+ // for React Native Web.
234
+ extensions: _mapInstanceProperty__default["default"](_context2 = ['js', 'mjs', 'cjs', 'ts', 'tsx', 'json', 'jsx']).call(_context2, function (ext) {
235
+ return ".".concat(ext);
236
+ }),
237
+ // NOTE: this is meant to be a temporary list of fallback/polyfills for certain
238
+ // nodejs modules. With Webpack <5 these polyfills were included by default in Webpack,
239
+ // however now it's not the case anymore.
240
+ // See also related work in CRA: https://github.com/facebook/create-react-app/pull/11764
241
+ fallback: {
242
+ querystring: require.resolve('querystring-es3')
243
+ }
244
+ },
245
+ // In production, we only want to load the polyfills and the app code.
246
+ entry: {
247
+ app: _filterInstanceProperty__default["default"](_context3 = [require.resolve('@commercetools-frontend/mc-scripts/application-runtime'), !mergedOptions.toggleFlags.disableCoreJs && require.resolve('core-js/stable'), mergedOptions.entryPoint]).call(_context3, Boolean)
248
+ },
249
+ output: {
250
+ // Generated JS file names (with nested folders).
251
+ // There will be one main bundle, and one file per asynchronous chunk.
252
+ filename: '[name].[chunkhash].js',
253
+ chunkFilename: '[id].[name].[chunkhash].js',
254
+ // The build folder.
255
+ path: paths.paths.appBuild,
256
+ pathinfo: false,
257
+ // Will be injected on runtime. See `packages/application-shell/src/public-path.js`
258
+ publicPath: ''
259
+ },
260
+ plugins: _filterInstanceProperty__default["default"](_context4 = [// Allows to "assign" custom options to the `webpack` object.
261
+ // At the moment, this is used to share some props with `postcss.config`.
262
+ new webpack__default["default"].LoaderOptionsPlugin({
263
+ options: {
264
+ sourceFolders: mergedOptions.sourceFolders,
265
+ context: __dirname
266
+ }
267
+ }), // Makes some environment variables available to the JS code, for example:
268
+ // if (process.env.NODE_ENV === 'production') { ... }.
269
+ new webpack__default["default"].DefinePlugin({
270
+ __DEV__: 'false',
271
+ 'process.env': {
272
+ NODE_ENV: _JSON$stringify__default["default"]('production')
273
+ }
274
+ }), // Only keep locales that are available in the Merchant Center.
275
+ new MomentLocalesPlugin__default["default"]({
276
+ localesToKeep: momentLocalesToKeep
277
+ }), // Generate a `stats.json` file containing information and paths to
278
+ // the assets that webpack created.
279
+ // This is necessary to programmatically refer to the correct bundle path
280
+ // in the `index.html`.
281
+ new FinalStatsWriterPlugin({
282
+ outputPath: paths.paths.appBuild,
283
+ includeFields: ['entrypoints', 'assets', 'publicPath', 'time']
284
+ }), mergedOptions.toggleFlags.generateIndexHtml && new HtmlWebpackPlugin__default["default"]({
285
+ inject: false,
286
+ filename: 'index.html.template',
287
+ template: require.resolve('@commercetools-frontend/mc-html-template/webpack')
288
+ }), mergedOptions.toggleFlags.enableExtractCss && // Extracts CSS into one CSS file to mimic CSS order in dev
289
+ new MiniCssExtractPlugin__default["default"]({
290
+ filename: '[name].[chunkhash].css',
291
+ chunkFilename: '[id].[name].[chunkhash].css'
292
+ }), process.env.ANALYZE_BUNDLE === 'true' && new webpackBundleAnalyzer.BundleAnalyzerPlugin({
293
+ defaultSizes: 'gzip'
294
+ })]).call(_context4, Boolean),
295
+ module: {
296
+ // Makes missing exports an error instead of warning.
297
+ strictExportPresence: true,
298
+ rules: _filterInstanceProperty__default["default"](_context5 = [// For svg icons, we want to get them transformed into React components
299
+ // when we import them.
300
+ {
301
+ test: /\.react\.svg$/,
302
+ use: [{
303
+ loader: require.resolve('babel-loader'),
304
+ options: {
305
+ babelrc: false,
306
+ presets: [[require.resolve('@commercetools-frontend/babel-preset-mc-app'), {
307
+ runtime: hasJsxRuntime.hasJsxRuntime() ? 'automatic' : 'classic',
308
+ disableCoreJs: mergedOptions.toggleFlags.disableCoreJs
309
+ }]],
310
+ // This is a feature of `babel-loader` for webpack (not Babel itself).
311
+ // It enables caching results in ./node_modules/.cache/babel-loader/
312
+ // directory for faster rebuilds.
313
+ cacheDirectory: true,
314
+ highlightCode: true
315
+ }
316
+ }, {
317
+ loader: require.resolve('@svgr/webpack'),
318
+ options: {
319
+ icon: false,
320
+ svgoConfig: {
321
+ plugins: [{
322
+ // https://github.com/svg/svgo#default-preset
323
+ name: 'preset-default',
324
+ params: {
325
+ overrides: {
326
+ removeViewBox: false
327
+ }
328
+ }
329
+ }]
330
+ }
331
+ }
332
+ }]
333
+ }, // For normal svg files (not icons) we should load the file normally
334
+ // and simply use it as a `<img src/>`.
335
+ {
336
+ test: function testForNormalSvgFiles(fileName) {
337
+ return (// Use this only for plain SVG.
338
+ // For SVG as React components, see loader above.
339
+ _endsWithInstanceProperty__default["default"](fileName).call(fileName, '.svg') && !_endsWithInstanceProperty__default["default"](fileName).call(fileName, '.react.svg')
340
+ );
341
+ },
342
+ use: [{
343
+ loader: require.resolve('svg-url-loader')
344
+ }]
345
+ }, {
346
+ test: /\.png$/,
347
+ type: 'asset/resource'
348
+ }, // "postcss" loader applies autoprefixer to our CSS
349
+ // "css" loader resolves paths in CSS and adds assets as dependencies.
350
+ // "style" loader turns CSS into JS modules that inject <style> tags.
351
+ // In production, we use MiniCSSExtractPlugin to extract that CSS
352
+ // to a file, but in development "style" loader enables hot editing
353
+ // of CSS.
354
+ // By default we support CSS Modules with the extension `.mod.css` and `.module.css`.
355
+ {
356
+ test: /\.(mod|module)\.css$/,
357
+ include: mergedOptions.sourceFolders,
358
+ use: [mergedOptions.toggleFlags.enableExtractCss ? MiniCssExtractPlugin__default["default"].loader : require.resolve('style-loader'), {
359
+ loader: require.resolve('css-loader'),
360
+ options: {
361
+ modules: {
362
+ mode: 'local',
363
+ localIdentName: '[name]__[local]___[hash:base64:5]',
364
+ localIdentHashSalt: 'ct'
365
+ },
366
+ importLoaders: 1
367
+ }
368
+ }, {
369
+ loader: require.resolve('postcss-loader'),
370
+ options: {
371
+ postcssOptions: createPostcssConfig.createPostcssConfig(mergedOptions.postcssOptions)
372
+ }
373
+ }]
374
+ }, {
375
+ test: function testForNormalCssFiles(fileName) {
376
+ return (// Use this only for plain CSS.
377
+ // For css-modules, see loader above.
378
+ _endsWithInstanceProperty__default["default"](fileName).call(fileName, '.css') && !(_endsWithInstanceProperty__default["default"](fileName).call(fileName, '.mod.css') || _endsWithInstanceProperty__default["default"](fileName).call(fileName, '.module.css'))
379
+ );
380
+ },
381
+ // "postcss" loader applies autoprefixer to our CSS.
382
+ // "css" loader resolves paths in CSS and adds assets as dependencies.
383
+ // "MiniCssExtractPlugin" or "style" loader extracts css to one file per css file.
384
+ oneOf: [{
385
+ // Use "postcss" for all the included source folders.
386
+ include: mergedOptions.sourceFolders,
387
+ use: [mergedOptions.toggleFlags.enableExtractCss ? MiniCssExtractPlugin__default["default"].loader : require.resolve('style-loader'), {
388
+ loader: require.resolve('css-loader'),
389
+ options: {
390
+ modules: {
391
+ mode: 'icss'
392
+ },
393
+ importLoaders: 1
394
+ }
395
+ }, {
396
+ loader: require.resolve('postcss-loader'),
397
+ options: {
398
+ postcssOptions: createPostcssConfig.createPostcssConfig(mergedOptions.postcssOptions)
399
+ }
400
+ }]
401
+ }, {
402
+ // For all other vendor CSS, do not use "postcss" loader.
403
+ // But still use MiniCssExtractPlugin :)
404
+ include: /node_modules/,
405
+ use: [mergedOptions.toggleFlags.enableExtractCss ? MiniCssExtractPlugin__default["default"].loader : require.resolve('style-loader'), {
406
+ loader: require.resolve('css-loader'),
407
+ options: {
408
+ modules: {
409
+ mode: 'icss'
410
+ },
411
+ importLoaders: 1
412
+ }
413
+ }]
414
+ }]
415
+ }, // Fix for react-intl
416
+ // https://github.com/formatjs/formatjs/issues/143#issuecomment-518774786
417
+ {
418
+ test: /\.mjs$/,
419
+ type: 'javascript/auto',
420
+ resolve: {
421
+ // https://webpack.js.org/configuration/module/#resolvefullyspecified
422
+ fullySpecified: false
423
+ }
424
+ }, // Process application JavaScript with Babel.
425
+ {
426
+ test: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
427
+ use: [// This loader parallelizes code compilation, it is optional but
428
+ // improves compile time on larger projects
429
+ {
430
+ loader: require.resolve('thread-loader'),
431
+ options: _objectSpread({}, _Number$isInteger__default["default"](mergedOptions.toggleFlags.parallelism) ? {
432
+ workers: mergedOptions.toggleFlags.parallelism
433
+ } : {})
434
+ }, {
435
+ loader: require.resolve('babel-loader'),
436
+ options: {
437
+ babelrc: false,
438
+ configFile: false,
439
+ compact: false,
440
+ presets: [[require.resolve('@commercetools-frontend/babel-preset-mc-app'), {
441
+ runtime: hasJsxRuntime.hasJsxRuntime() ? 'automatic' : 'classic'
442
+ }]],
443
+ // This is a feature of `babel-loader` for webpack (not Babel itself).
444
+ // It enables caching results in ./node_modules/.cache/babel-loader/
445
+ // directory for faster rebuilds.
446
+ cacheDirectory: true,
447
+ highlightCode: true
448
+ }
449
+ }],
450
+ include: _concatInstanceProperty__default["default"](_context6 = mergedOptions.sourceFolders).call(_context6, vendorsToTranspile.vendorsToTranspile),
451
+ // Disable require.ensure as it's not a standard language feature.
452
+ parser: {
453
+ requireEnsure: false
454
+ }
455
+ }, // Allow to import `*.graphql` SDL files.
456
+ {
457
+ test: /\.graphql$/,
458
+ include: mergedOptions.sourceFolders,
459
+ exclude: /node_modules/,
460
+ use: [require.resolve('graphql-tag/loader')]
461
+ }]).call(_context5, Boolean)
462
+ },
463
+ // Turn off performance processing because we utilize
464
+ // our own hints via the FileSizeReporter
465
+ performance: false
466
+ };
467
+ }
468
+
469
+ exports.createWebpackConfigForProduction = createWebpackConfigForProduction;