@commercetools-frontend/mc-scripts 0.0.0-CRAFT-1791-20251006162610

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 (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +2 -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/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +7 -0
  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 +8 -0
  10. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +2 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +199 -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 +199 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +184 -0
  15. package/cli/package.json +4 -0
  16. package/config/create-webpack-config-for-development.js +8 -0
  17. package/config/create-webpack-config-for-production.js +8 -0
  18. package/config/vendors-to-transpile.js +6 -0
  19. package/dist/build-2a0a18bd.esm.js +155 -0
  20. package/dist/build-521f3f9f.cjs.prod.js +169 -0
  21. package/dist/build-988fc0f7.cjs.dev.js +169 -0
  22. package/dist/build-vite-16b1a575.cjs.dev.js +238 -0
  23. package/dist/build-vite-59e1f185.esm.js +208 -0
  24. package/dist/build-vite-5d317720.cjs.prod.js +238 -0
  25. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +2 -0
  26. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +29 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +29 -0
  29. package/dist/commercetools-frontend-mc-scripts.esm.js +21 -0
  30. package/dist/compile-html-025cd493.esm.js +34 -0
  31. package/dist/compile-html-50fd05ec.cjs.prod.js +42 -0
  32. package/dist/compile-html-f4ac88cc.cjs.dev.js +42 -0
  33. package/dist/config-sync-70a16916.cjs.dev.js +852 -0
  34. package/dist/config-sync-72c20d80.cjs.prod.js +846 -0
  35. package/dist/config-sync-bc895390.esm.js +830 -0
  36. package/dist/create-postcss-config-cb7be312.cjs.dev.js +81 -0
  37. package/dist/create-postcss-config-dde0ccf1.esm.js +75 -0
  38. package/dist/create-postcss-config-edca0c33.cjs.prod.js +81 -0
  39. package/dist/create-webpack-config-for-development-1aed1cc0.cjs.prod.js +465 -0
  40. package/dist/create-webpack-config-for-development-a95f3634.esm.js +440 -0
  41. package/dist/create-webpack-config-for-development-d003697b.cjs.dev.js +465 -0
  42. package/dist/create-webpack-config-for-production-15fbe7db.cjs.dev.js +523 -0
  43. package/dist/create-webpack-config-for-production-764c482f.cjs.prod.js +523 -0
  44. package/dist/create-webpack-config-for-production-9f42c336.esm.js +493 -0
  45. package/dist/credentials-storage-66c1e51f.cjs.prod.js +95 -0
  46. package/dist/credentials-storage-d001f726.esm.js +83 -0
  47. package/dist/credentials-storage-e7884d17.cjs.dev.js +95 -0
  48. package/dist/declarations/src/application-runtime.d.ts +1 -0
  49. package/dist/declarations/src/cli.d.ts +4 -0
  50. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  51. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  52. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  53. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  54. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  55. package/dist/declarations/src/index.d.ts +3 -0
  56. package/dist/declarations/src/postcss.d.ts +1 -0
  57. package/dist/declarations/src/types.d.ts +94 -0
  58. package/dist/declarations/src/version.d.ts +2 -0
  59. package/dist/declarations/src/webpack-loaders/i18n-message-compilation-loader.d.ts +3 -0
  60. package/dist/declarations/src/webpack.d.ts +2 -0
  61. package/dist/deployment-previews-set-17e8ed48.cjs.prod.js +202 -0
  62. package/dist/deployment-previews-set-3648972f.esm.js +191 -0
  63. package/dist/deployment-previews-set-37aef990.cjs.dev.js +202 -0
  64. package/dist/does-file-exist-32618334.esm.js +12 -0
  65. package/dist/does-file-exist-be53305d.cjs.prod.js +18 -0
  66. package/dist/does-file-exist-eb86baca.cjs.dev.js +18 -0
  67. package/dist/graphql-requests-6a47ad5b.esm.js +247 -0
  68. package/dist/graphql-requests-779b867b.cjs.dev.js +270 -0
  69. package/dist/graphql-requests-8086eba7.cjs.prod.js +270 -0
  70. package/dist/has-jsx-runtime-aa5d21ee.cjs.dev.js +15 -0
  71. package/dist/has-jsx-runtime-c3202df5.cjs.prod.js +15 -0
  72. package/dist/has-jsx-runtime-e3ecb09b.esm.js +13 -0
  73. package/dist/i18n-message-complilation-21d3b0aa.esm.js +15 -0
  74. package/dist/i18n-message-complilation-7311cb29.cjs.dev.js +23 -0
  75. package/dist/i18n-message-complilation-7762da61.cjs.prod.js +23 -0
  76. package/dist/login-0a728449.esm.js +229 -0
  77. package/dist/login-817a5a26.cjs.dev.js +270 -0
  78. package/dist/login-85c25393.cjs.prod.js +270 -0
  79. package/dist/optimizations-7789145e.cjs.dev.js +85 -0
  80. package/dist/optimizations-bf991634.esm.js +67 -0
  81. package/dist/optimizations-fb93514f.cjs.prod.js +85 -0
  82. package/dist/package-7e170dc4.cjs.dev.js +160 -0
  83. package/dist/package-940b0a2a.cjs.prod.js +160 -0
  84. package/dist/package-99e547a7.esm.js +158 -0
  85. package/dist/paths-39f22b8b.esm.js +36 -0
  86. package/dist/paths-7768b440.cjs.prod.js +44 -0
  87. package/dist/paths-b76fc753.cjs.dev.js +44 -0
  88. package/dist/serve-1036c2de.esm.js +55 -0
  89. package/dist/serve-50d33f0b.cjs.dev.js +64 -0
  90. package/dist/serve-8a506da6.cjs.prod.js +64 -0
  91. package/dist/start-1d677ad8.cjs.dev.js +177 -0
  92. package/dist/start-2a7ae03d.esm.js +164 -0
  93. package/dist/start-f56cb5f7.cjs.prod.js +177 -0
  94. package/dist/start-vite-068e9f73.cjs.dev.js +128 -0
  95. package/dist/start-vite-29078b3a.cjs.prod.js +128 -0
  96. package/dist/start-vite-7d1161e8.esm.js +116 -0
  97. package/dist/vendors-to-transpile-04a49d40.cjs.prod.js +5 -0
  98. package/dist/vendors-to-transpile-6ab4ea06.cjs.dev.js +5 -0
  99. package/dist/vendors-to-transpile-7dc84a72.esm.js +3 -0
  100. package/dist/vite-plugin-svgr-4034a834.cjs.prod.js +151 -0
  101. package/dist/vite-plugin-svgr-7d06f400.cjs.dev.js +151 -0
  102. package/dist/vite-plugin-svgr-de6ee7da.esm.js +125 -0
  103. package/package.json +156 -0
  104. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +2 -0
  105. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +12 -0
  106. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  107. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +12 -0
  108. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +4 -0
  109. package/postcss/package.json +4 -0
  110. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +2 -0
  111. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +57 -0
  112. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  113. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +57 -0
  114. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +48 -0
  115. package/webpack/package.json +4 -0
  116. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.d.ts +3 -0
  117. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +30 -0
  118. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.js +7 -0
  119. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +30 -0
  120. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +26 -0
  121. package/webpack-loaders/i18n-message-compilation-loader/package.json +4 -0
@@ -0,0 +1,169 @@
1
+ 'use strict';
2
+
3
+ var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
4
+ var path = require('path');
5
+ var chalk = require('chalk');
6
+ var fs = require('fs-extra');
7
+ var checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
8
+ var FileSizeReporter = require('react-dev-utils/FileSizeReporter');
9
+ var formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
10
+ var printBuildError = require('react-dev-utils/printBuildError');
11
+ var webpack = require('webpack');
12
+ var assets = require('@commercetools-frontend/assets');
13
+ var createWebpackConfigForProduction = require('./create-webpack-config-for-production-15fbe7db.cjs.dev.js');
14
+ var paths = require('./paths-b76fc753.cjs.dev.js');
15
+ var doesFileExist = require('./does-file-exist-eb86baca.cjs.dev.js');
16
+ require('@babel/runtime-corejs3/core-js-stable/object/keys');
17
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
18
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
19
+ require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
20
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
21
+ require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
22
+ require('@babel/runtime-corejs3/core-js-stable/object/define-property');
23
+ require('@babel/runtime-corejs3/helpers/defineProperty');
24
+ require('@babel/runtime-corejs3/core-js-stable/instance/filter');
25
+ require('@babel/runtime-corejs3/core-js-stable/instance/map');
26
+ require('@babel/runtime-corejs3/core-js-stable/json/stringify');
27
+ require('@babel/runtime-corejs3/core-js-stable/instance/ends-with');
28
+ require('@babel/runtime-corejs3/core-js-stable/number/is-integer');
29
+ require('@babel/runtime-corejs3/core-js-stable/instance/concat');
30
+ require('crypto');
31
+ require('css-minimizer-webpack-plugin');
32
+ require('html-webpack-plugin');
33
+ require('mini-css-extract-plugin');
34
+ require('moment-locales-webpack-plugin');
35
+ require('terser-webpack-plugin');
36
+ require('webpack-bundle-analyzer');
37
+ require('@babel/runtime-corejs3/helpers/classCallCheck');
38
+ require('@babel/runtime-corejs3/helpers/createClass');
39
+ require('@babel/runtime-corejs3/core-js-stable/instance/bind');
40
+ require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
41
+ require('@babel/runtime-corejs3/core-js-stable/object/assign');
42
+ require('fs');
43
+ require('./create-postcss-config-cb7be312.cjs.dev.js');
44
+ require('@babel/runtime-corejs3/helpers/slicedToArray');
45
+ require('./package-7e170dc4.cjs.dev.js');
46
+ require('./has-jsx-runtime-aa5d21ee.cjs.dev.js');
47
+ require('./optimizations-7789145e.cjs.dev.js');
48
+ require('@babel/runtime-corejs3/core-js-stable/object/entries');
49
+ require('@babel/runtime-corejs3/core-js-stable/instance/includes');
50
+ require('./vendors-to-transpile-6ab4ea06.cjs.dev.js');
51
+ require('@babel/runtime-corejs3/core-js-stable/instance/find');
52
+ require('node:fs');
53
+
54
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
55
+
56
+ var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
57
+ var path__default = /*#__PURE__*/_interopDefault(path);
58
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
59
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
60
+ var checkRequiredFiles__default = /*#__PURE__*/_interopDefault(checkRequiredFiles);
61
+ var FileSizeReporter__default = /*#__PURE__*/_interopDefault(FileSizeReporter);
62
+ var formatWebpackMessages__default = /*#__PURE__*/_interopDefault(formatWebpackMessages);
63
+ var printBuildError__default = /*#__PURE__*/_interopDefault(printBuildError);
64
+ var webpack__default = /*#__PURE__*/_interopDefault(webpack);
65
+
66
+ const measureFileSizesBeforeBuild = FileSizeReporter__default["default"].measureFileSizesBeforeBuild;
67
+ const printFileSizesAfterBuild = FileSizeReporter__default["default"].printFileSizesAfterBuild;
68
+
69
+ // These sizes are pretty large. We'll warn for bundles exceeding them.
70
+ const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
71
+ const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
72
+ async function run() {
73
+ const hasWebpackConfig = doesFileExist.doesFileExist(paths.paths.appWebpackConfig);
74
+
75
+ // Warn and crash if required files are missing
76
+ if (!checkRequiredFiles__default["default"]([])) {
77
+ process.exit(1);
78
+ }
79
+
80
+ // First, read the current file sizes in build directory.
81
+ // This lets us display how much they changed later.
82
+ const previousFileSizes = await measureFileSizesBeforeBuild(paths.paths.appBuild);
83
+
84
+ // Remove all content but keep the directory so that
85
+ // if you're in it, you don't end up in Trash
86
+ fs__default["default"].emptyDirSync(paths.paths.appBuild);
87
+ // Copy default files
88
+ copyDefaultFiles();
89
+ try {
90
+ // Start the webpack build
91
+ const result = await build();
92
+ if (result.warnings.length) {
93
+ console.log(chalk__default["default"].yellow('Compiled with warnings.\n'));
94
+ console.log(result.warnings.join('\n\n'));
95
+ console.log('\n');
96
+ } else {
97
+ console.log(chalk__default["default"].green('Compiled successfully.\n'));
98
+ }
99
+ console.log('File sizes after gzip:\n');
100
+ printFileSizesAfterBuild(result.stats, previousFileSizes, paths.paths.appBuild, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
101
+ console.log();
102
+ } catch (error) {
103
+ if (error instanceof Error) {
104
+ printBuildError__default["default"](error);
105
+ }
106
+ throw new Error(`Failed to compile`);
107
+ }
108
+
109
+ // Create the production build and print the deployment instructions.
110
+ async function build() {
111
+ console.log('Creating an optimized production build...');
112
+ const config = hasWebpackConfig ? require(paths.paths.appWebpackConfig) : createWebpackConfigForProduction.createWebpackConfigForProduction();
113
+ const compiler = webpack__default["default"](config);
114
+ if (!compiler) {
115
+ return _Promise__default["default"].reject(new Error('Failed to create webpack compiler'));
116
+ }
117
+ return new _Promise__default["default"]((resolve, reject) => {
118
+ compiler.run((err, stats) => {
119
+ let messages;
120
+ if (err) {
121
+ if (!err.message) {
122
+ return reject(err);
123
+ }
124
+ let errMessage = err.message;
125
+ // Add additional information for postcss errors
126
+ if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) {
127
+ errMessage += '\nCompileError: Begins at CSS selector ' +
128
+ // @ts-ignore
129
+ err['postcssNode'].selector;
130
+ }
131
+ messages = formatWebpackMessages__default["default"]({
132
+ // @ts-ignore
133
+ errors: [errMessage],
134
+ warnings: []
135
+ });
136
+ } else {
137
+ messages = formatWebpackMessages__default["default"](stats?.toJson({
138
+ all: false,
139
+ warnings: true,
140
+ errors: true
141
+ }));
142
+ }
143
+ if (messages.errors.length) {
144
+ // Only keep the first error. Others are often indicative
145
+ // of the same problem, but confuse the reader with noise.
146
+ if (messages.errors.length > 1) {
147
+ messages.errors.length = 1;
148
+ }
149
+ return reject(new Error(messages.errors.join('\n\n')));
150
+ }
151
+ if (process.env.CI && (typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') && messages.warnings.length) {
152
+ console.log(chalk__default["default"].yellow('\nTreating warnings as errors because process.env.CI = true.\n' + 'Most CI servers set it automatically.\n'));
153
+ return reject(new Error(messages.warnings.join('\n\n')));
154
+ }
155
+ return resolve({
156
+ stats: stats,
157
+ warnings: messages.warnings
158
+ });
159
+ });
160
+ });
161
+ }
162
+ function copyDefaultFiles() {
163
+ fs__default["default"].copySync(path__default["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
164
+ dereference: true
165
+ });
166
+ }
167
+ }
168
+
169
+ exports["default"] = run;
@@ -0,0 +1,238 @@
1
+ 'use strict';
2
+
3
+ var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
4
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
5
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
6
+ var path = require('path');
7
+ var pluginGraphql = require('@rollup/plugin-graphql');
8
+ var pluginReact = require('@vitejs/plugin-react');
9
+ var fs = require('fs-extra');
10
+ var rollupPluginVisualizer = require('rollup-plugin-visualizer');
11
+ var vite = require('vite');
12
+ var viteBundleAnalyzer = require('vite-bundle-analyzer');
13
+ var assets = require('@commercetools-frontend/assets');
14
+ var mcHtmlTemplate = require('@commercetools-frontend/mc-html-template');
15
+ var optimizations = require('./optimizations-7789145e.cjs.dev.js');
16
+ var paths = require('./paths-b76fc753.cjs.dev.js');
17
+ var cliLib = require('@formatjs/cli-lib');
18
+ var pluginutils = require('@rollup/pluginutils');
19
+ var i18nMessageComplilation = require('./i18n-message-complilation-7311cb29.cjs.dev.js');
20
+ var vitePluginSvgr = require('./vite-plugin-svgr-7d06f400.cjs.dev.js');
21
+ require('@babel/runtime-corejs3/helpers/defineProperty');
22
+ require('@babel/runtime-corejs3/helpers/slicedToArray');
23
+ require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
24
+ require('@babel/runtime-corejs3/core-js-stable/object/entries');
25
+ require('@babel/runtime-corejs3/core-js-stable/instance/includes');
26
+ require('@babel/runtime-corejs3/core-js-stable/object/keys');
27
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
28
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
29
+ require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
30
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
31
+ require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
32
+ require('@babel/runtime-corejs3/core-js-stable/object/define-property');
33
+ require('chalk');
34
+ require('@babel/runtime-corejs3/core-js-stable/instance/find');
35
+ require('fs');
36
+ require('./does-file-exist-eb86baca.cjs.dev.js');
37
+ require('node:fs');
38
+ require('@babel/runtime-corejs3/core-js-stable/object/values');
39
+ require('crypto');
40
+ require('@babel/runtime-corejs3/core-js/instance/match-all');
41
+
42
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
43
+
44
+ function _interopNamespace(e) {
45
+ if (e && e.__esModule) return e;
46
+ var n = Object.create(null);
47
+ if (e) {
48
+ Object.keys(e).forEach(function (k) {
49
+ if (k !== 'default') {
50
+ var d = Object.getOwnPropertyDescriptor(e, k);
51
+ Object.defineProperty(n, k, d.get ? d : {
52
+ enumerable: true,
53
+ get: function () { return e[k]; }
54
+ });
55
+ }
56
+ });
57
+ }
58
+ n["default"] = e;
59
+ return Object.freeze(n);
60
+ }
61
+
62
+ var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
63
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
64
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
65
+ var path__default = /*#__PURE__*/_interopDefault(path);
66
+ var pluginGraphql__default = /*#__PURE__*/_interopDefault(pluginGraphql);
67
+ var pluginReact__default = /*#__PURE__*/_interopDefault(pluginReact);
68
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
69
+
70
+ // Type guard to help with filtering arrays for nullish elements.
71
+ function nonNullable(value) {
72
+ return value !== null && value !== undefined;
73
+ }
74
+
75
+ // This script/function is injected into the `index.html` and used by Vite
76
+ // on runtime to build the assets URL (for example when using a separate CDN for the assets).
77
+ // Inspired by https://github.com/vitejs/vite/blob/main/playground/assets/vite.config-runtime-base.js
78
+ const dynamicBaseAssetsCode = `globalThis.__toCdnUrl = filePath => window.app.cdnUrl.replace(/\\/$/, '') + '/' + filePath;`;
79
+ function vitePluginDynamicBaseAssetsGlobals() {
80
+ return {
81
+ name: 'dynamic-base-assets-globals',
82
+ transformIndexHtml(html, ctx) {
83
+ if (ctx.bundle) {
84
+ // Only inject during build
85
+ return [{
86
+ tag: 'script',
87
+ attrs: {
88
+ type: 'module'
89
+ },
90
+ children: dynamicBaseAssetsCode
91
+ }];
92
+ }
93
+ return html;
94
+ }
95
+ };
96
+ }
97
+
98
+ function vitePluginI18nMessageCompilation() {
99
+ const filter = pluginutils.createFilter('**/i18n/data/*.json');
100
+ return {
101
+ name: 'vite-plugin-i18n-message-compilation',
102
+ enforce: 'pre',
103
+ async transform(code, id) {
104
+ if (!process.env.DISABLE_I18N_MESSAGE_COMPILATION && filter(id)) {
105
+ try {
106
+ const format = i18nMessageComplilation.getI18nMessageFormat(code);
107
+ const res = await cliLib.compile([id], {
108
+ ast: true,
109
+ format
110
+ });
111
+ return {
112
+ code: res,
113
+ map: null
114
+ };
115
+ } catch (error) {
116
+ i18nMessageComplilation.handleMessageCompilationError(id, error, this.warn);
117
+ }
118
+ }
119
+ return null;
120
+ }
121
+ };
122
+ }
123
+
124
+ async function run() {
125
+ var _context;
126
+ const CleanBuild = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('vite-plugin-clean-build')); })).default;
127
+ const DEFAULT_PORT = _parseInt__default["default"](String(process.env.HTTP_PORT), 10) || 3001;
128
+
129
+ // Ensure the `/public` folder exists.
130
+ fs__default["default"].mkdirSync(paths.paths.appBuild, {
131
+ recursive: true
132
+ });
133
+
134
+ // Generate `index.html` (template).
135
+ const appEntryPoint = path__default["default"].relative(paths.paths.appRoot, paths.paths.entryPoint);
136
+ const html = mcHtmlTemplate.generateTemplate({
137
+ // Define the module entry point (path relative from the `/public` folder).
138
+ // NOTE: that this is different from the development configuration.
139
+ scriptImports: [`<script type="module" src="/${appEntryPoint}" defer></script>`]
140
+ });
141
+ // Write `index.html` (template) into the `/public` folder.
142
+ fs__default["default"].writeFileSync(paths.paths.appIndexHtml, html, {
143
+ encoding: 'utf8'
144
+ });
145
+ const appDependencies = require(paths.paths.appPackageJson).dependencies;
146
+ await vite.build({
147
+ root: paths.paths.appRoot,
148
+ base: './',
149
+ // <-- Important to allow configuring the runtime base path.
150
+ define: {
151
+ 'process.env.DEBUG': _JSON$stringify__default["default"](false),
152
+ 'process.env.NODE_ENV': _JSON$stringify__default["default"]('production')
153
+ },
154
+ build: {
155
+ outDir: 'public',
156
+ // Outputs all build assets directly under the `/public` folder.
157
+ assetsDir: '',
158
+ rollupOptions: {
159
+ // This is necessary to instruct Vite that the `index.html` (template)
160
+ // is located in the `/public` folder.
161
+ // NOTE that after the build, Vite will write the `index.html` (template)
162
+ // at the `/public/public/index.html` location. See `fs.renameSync` below.
163
+ input: paths.paths.appIndexHtml,
164
+ output: {
165
+ manualChunks: optimizations.getViteCacheGroups(appDependencies)
166
+ },
167
+ // Reduce the memory footprint when building sourcemaps.
168
+ // https://github.com/vitejs/vite/issues/2433#issuecomment-1361094727
169
+ cache: false
170
+ },
171
+ sourcemap:
172
+ // Generating sourcemaps can increase the memory footprint of the build process,
173
+ // therefore it's an opt-in option.
174
+ // TODO: make it a CLI option when Vite support becomes stable.
175
+ process.env.ENABLE_EXPERIMENTAL_VITE_BUNDLER_SOURCEMAP === 'true'
176
+ },
177
+ server: {
178
+ port: DEFAULT_PORT
179
+ },
180
+ experimental: {
181
+ // https://vitejs.dev/guide/build.html#advanced-base-options
182
+ renderBuiltUrl(filename, _ref) {
183
+ let hostType = _ref.hostType;
184
+ if (hostType === 'html') {
185
+ return `__CDN_URL__${filename}`;
186
+ }
187
+ return {
188
+ runtime: `window.__toCdnUrl(${_JSON$stringify__default["default"](filename)})`
189
+ };
190
+ }
191
+ },
192
+ plugins: [vitePluginSvgr.vitePluginSvgr(), pluginGraphql__default["default"](), pluginReact__default["default"]({
193
+ jsxImportSource: '@emotion/react',
194
+ babel: {
195
+ plugins: _filterInstanceProperty__default["default"](_context = ['@emotion/babel-plugin', '@babel/plugin-proposal-do-expressions', process.env.ENABLE_BABEL_PLUGIN_FORMATJS === 'true' ? ['babel-plugin-formatjs', {
196
+ removeDefaultMessage:
197
+ // Remove default `formatjs` messages from bundles.
198
+ // TODO: make it a CLI option when Vite support becomes stable.
199
+ process.env.ENABLE_I18N_REMOVE_DEFAULT_MESSAGE === 'true',
200
+ ast:
201
+ // Enable pre-parse default `formatjs` messages into AST.
202
+ // TODO: make it a CLI option when Vite support becomes stable.
203
+ process.env.ENABLE_I18N_AST === 'true'
204
+ }] : undefined]).call(_context, nonNullable)
205
+ }
206
+ }),
207
+ // cleanbuild is needed to remove large svg assets
208
+ // that are not used after the build.
209
+ CleanBuild({
210
+ outputDir: paths.paths.appBuild,
211
+ patterns: ['*.react-*.svg'],
212
+ verbose: true // logs the files that are removed
213
+ }), vitePluginDynamicBaseAssetsGlobals(), vitePluginI18nMessageCompilation(), process.env.ANALYZE_BUNDLE === 'true' && viteBundleAnalyzer.analyzer({
214
+ defaultSizes: 'stat',
215
+ openAnalyzer: true
216
+ }), process.env.ANALYZE_BUNDLE_TREE === 'true' && rollupPluginVisualizer.visualizer({
217
+ open: true,
218
+ template: 'network'
219
+ })]
220
+ });
221
+
222
+ // Rename `/public/public/index.html` to `/public/index.html.template`
223
+ fs__default["default"].renameSync(
224
+ // Because of our custom entry point path (`/public/index.html`),
225
+ // Vite will write the `index.html` to `/public/public/index.html`.
226
+ // We need to move this file to the `/public` folder and rename it
227
+ // to `index.html.template` (as expected by the `compile-html` command).
228
+ path__default["default"].join(paths.paths.appBuild, 'public/index.html'), paths.paths.appIndexHtmlTemplate);
229
+ // Clean up nested folder
230
+ fs__default["default"].rmdirSync(path__default["default"].join(paths.paths.appBuild, 'public'));
231
+
232
+ // Copy public assets
233
+ fs__default["default"].copySync(path__default["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
234
+ dereference: true
235
+ });
236
+ }
237
+
238
+ exports["default"] = run;
@@ -0,0 +1,208 @@
1
+ import _parseInt from '@babel/runtime-corejs3/core-js-stable/parse-int';
2
+ import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
3
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
4
+ import path from 'path';
5
+ import pluginGraphql from '@rollup/plugin-graphql';
6
+ import pluginReact from '@vitejs/plugin-react';
7
+ import fs from 'fs-extra';
8
+ import { visualizer } from 'rollup-plugin-visualizer';
9
+ import { build } from 'vite';
10
+ import { analyzer } from 'vite-bundle-analyzer';
11
+ import { packageLocation } from '@commercetools-frontend/assets';
12
+ import { generateTemplate } from '@commercetools-frontend/mc-html-template';
13
+ import { a as getViteCacheGroups } from './optimizations-bf991634.esm.js';
14
+ import { p as paths } from './paths-39f22b8b.esm.js';
15
+ import { compile } from '@formatjs/cli-lib';
16
+ import { createFilter } from '@rollup/pluginutils';
17
+ import { g as getI18nMessageFormat, h as handleMessageCompilationError } from './i18n-message-complilation-21d3b0aa.esm.js';
18
+ import { v as vitePluginSvgr } from './vite-plugin-svgr-de6ee7da.esm.js';
19
+ import '@babel/runtime-corejs3/helpers/defineProperty';
20
+ import '@babel/runtime-corejs3/helpers/slicedToArray';
21
+ import '@babel/runtime-corejs3/core-js-stable/instance/reduce';
22
+ import '@babel/runtime-corejs3/core-js-stable/object/entries';
23
+ import '@babel/runtime-corejs3/core-js-stable/instance/includes';
24
+ import '@babel/runtime-corejs3/core-js-stable/object/keys';
25
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
26
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
27
+ import '@babel/runtime-corejs3/core-js-stable/instance/for-each';
28
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
29
+ import '@babel/runtime-corejs3/core-js-stable/object/define-properties';
30
+ import '@babel/runtime-corejs3/core-js-stable/object/define-property';
31
+ import 'chalk';
32
+ import '@babel/runtime-corejs3/core-js-stable/instance/find';
33
+ import 'fs';
34
+ import './does-file-exist-32618334.esm.js';
35
+ import 'node:fs';
36
+ import '@babel/runtime-corejs3/core-js-stable/object/values';
37
+ import 'crypto';
38
+ import '@babel/runtime-corejs3/core-js/instance/match-all';
39
+
40
+ // Type guard to help with filtering arrays for nullish elements.
41
+ function nonNullable(value) {
42
+ return value !== null && value !== undefined;
43
+ }
44
+
45
+ // This script/function is injected into the `index.html` and used by Vite
46
+ // on runtime to build the assets URL (for example when using a separate CDN for the assets).
47
+ // Inspired by https://github.com/vitejs/vite/blob/main/playground/assets/vite.config-runtime-base.js
48
+ const dynamicBaseAssetsCode = `globalThis.__toCdnUrl = filePath => window.app.cdnUrl.replace(/\\/$/, '') + '/' + filePath;`;
49
+ function vitePluginDynamicBaseAssetsGlobals() {
50
+ return {
51
+ name: 'dynamic-base-assets-globals',
52
+ transformIndexHtml(html, ctx) {
53
+ if (ctx.bundle) {
54
+ // Only inject during build
55
+ return [{
56
+ tag: 'script',
57
+ attrs: {
58
+ type: 'module'
59
+ },
60
+ children: dynamicBaseAssetsCode
61
+ }];
62
+ }
63
+ return html;
64
+ }
65
+ };
66
+ }
67
+
68
+ function vitePluginI18nMessageCompilation() {
69
+ const filter = createFilter('**/i18n/data/*.json');
70
+ return {
71
+ name: 'vite-plugin-i18n-message-compilation',
72
+ enforce: 'pre',
73
+ async transform(code, id) {
74
+ if (!process.env.DISABLE_I18N_MESSAGE_COMPILATION && filter(id)) {
75
+ try {
76
+ const format = getI18nMessageFormat(code);
77
+ const res = await compile([id], {
78
+ ast: true,
79
+ format
80
+ });
81
+ return {
82
+ code: res,
83
+ map: null
84
+ };
85
+ } catch (error) {
86
+ handleMessageCompilationError(id, error, this.warn);
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+ };
92
+ }
93
+
94
+ async function run() {
95
+ var _context;
96
+ const CleanBuild = (await import('vite-plugin-clean-build')).default;
97
+ const DEFAULT_PORT = _parseInt(String(process.env.HTTP_PORT), 10) || 3001;
98
+
99
+ // Ensure the `/public` folder exists.
100
+ fs.mkdirSync(paths.appBuild, {
101
+ recursive: true
102
+ });
103
+
104
+ // Generate `index.html` (template).
105
+ const appEntryPoint = path.relative(paths.appRoot, paths.entryPoint);
106
+ const html = generateTemplate({
107
+ // Define the module entry point (path relative from the `/public` folder).
108
+ // NOTE: that this is different from the development configuration.
109
+ scriptImports: [`<script type="module" src="/${appEntryPoint}" defer></script>`]
110
+ });
111
+ // Write `index.html` (template) into the `/public` folder.
112
+ fs.writeFileSync(paths.appIndexHtml, html, {
113
+ encoding: 'utf8'
114
+ });
115
+ const appDependencies = require(paths.appPackageJson).dependencies;
116
+ await build({
117
+ root: paths.appRoot,
118
+ base: './',
119
+ // <-- Important to allow configuring the runtime base path.
120
+ define: {
121
+ 'process.env.DEBUG': _JSON$stringify(false),
122
+ 'process.env.NODE_ENV': _JSON$stringify('production')
123
+ },
124
+ build: {
125
+ outDir: 'public',
126
+ // Outputs all build assets directly under the `/public` folder.
127
+ assetsDir: '',
128
+ rollupOptions: {
129
+ // This is necessary to instruct Vite that the `index.html` (template)
130
+ // is located in the `/public` folder.
131
+ // NOTE that after the build, Vite will write the `index.html` (template)
132
+ // at the `/public/public/index.html` location. See `fs.renameSync` below.
133
+ input: paths.appIndexHtml,
134
+ output: {
135
+ manualChunks: getViteCacheGroups(appDependencies)
136
+ },
137
+ // Reduce the memory footprint when building sourcemaps.
138
+ // https://github.com/vitejs/vite/issues/2433#issuecomment-1361094727
139
+ cache: false
140
+ },
141
+ sourcemap:
142
+ // Generating sourcemaps can increase the memory footprint of the build process,
143
+ // therefore it's an opt-in option.
144
+ // TODO: make it a CLI option when Vite support becomes stable.
145
+ process.env.ENABLE_EXPERIMENTAL_VITE_BUNDLER_SOURCEMAP === 'true'
146
+ },
147
+ server: {
148
+ port: DEFAULT_PORT
149
+ },
150
+ experimental: {
151
+ // https://vitejs.dev/guide/build.html#advanced-base-options
152
+ renderBuiltUrl(filename, _ref) {
153
+ let hostType = _ref.hostType;
154
+ if (hostType === 'html') {
155
+ return `__CDN_URL__${filename}`;
156
+ }
157
+ return {
158
+ runtime: `window.__toCdnUrl(${_JSON$stringify(filename)})`
159
+ };
160
+ }
161
+ },
162
+ plugins: [vitePluginSvgr(), pluginGraphql(), pluginReact({
163
+ jsxImportSource: '@emotion/react',
164
+ babel: {
165
+ plugins: _filterInstanceProperty(_context = ['@emotion/babel-plugin', '@babel/plugin-proposal-do-expressions', process.env.ENABLE_BABEL_PLUGIN_FORMATJS === 'true' ? ['babel-plugin-formatjs', {
166
+ removeDefaultMessage:
167
+ // Remove default `formatjs` messages from bundles.
168
+ // TODO: make it a CLI option when Vite support becomes stable.
169
+ process.env.ENABLE_I18N_REMOVE_DEFAULT_MESSAGE === 'true',
170
+ ast:
171
+ // Enable pre-parse default `formatjs` messages into AST.
172
+ // TODO: make it a CLI option when Vite support becomes stable.
173
+ process.env.ENABLE_I18N_AST === 'true'
174
+ }] : undefined]).call(_context, nonNullable)
175
+ }
176
+ }),
177
+ // cleanbuild is needed to remove large svg assets
178
+ // that are not used after the build.
179
+ CleanBuild({
180
+ outputDir: paths.appBuild,
181
+ patterns: ['*.react-*.svg'],
182
+ verbose: true // logs the files that are removed
183
+ }), vitePluginDynamicBaseAssetsGlobals(), vitePluginI18nMessageCompilation(), process.env.ANALYZE_BUNDLE === 'true' && analyzer({
184
+ defaultSizes: 'stat',
185
+ openAnalyzer: true
186
+ }), process.env.ANALYZE_BUNDLE_TREE === 'true' && visualizer({
187
+ open: true,
188
+ template: 'network'
189
+ })]
190
+ });
191
+
192
+ // Rename `/public/public/index.html` to `/public/index.html.template`
193
+ fs.renameSync(
194
+ // Because of our custom entry point path (`/public/index.html`),
195
+ // Vite will write the `index.html` to `/public/public/index.html`.
196
+ // We need to move this file to the `/public` folder and rename it
197
+ // to `index.html.template` (as expected by the `compile-html` command).
198
+ path.join(paths.appBuild, 'public/index.html'), paths.appIndexHtmlTemplate);
199
+ // Clean up nested folder
200
+ fs.rmdirSync(path.join(paths.appBuild, 'public'));
201
+
202
+ // Copy public assets
203
+ fs.copySync(path.join(packageLocation, 'html-page'), paths.appBuild, {
204
+ dereference: true
205
+ });
206
+ }
207
+
208
+ export { run as default };