@servicetitan/docs-uikit 30.3.0 → 31.0.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.
package/docs/startup.mdx DELETED
@@ -1,520 +0,0 @@
1
- ---
2
- title: Startup
3
- ---
4
-
5
- #### [CHANGELOG (@servicetitan/startup)](https://github.com/servicetitan/uikit/blob/master/packages/startup/CHANGELOG.md)
6
-
7
- [@servicetitan/startup](https://github.com/servicetitan/uikit/tree/master/packages/startup) is a command-line interface (CLI) to create multi-package Lerna projects with the support of TypeScript Project References and React. It offers a modern build setup with no configuration.
8
-
9
- ## Why use this package?
10
-
11
- #### Less to learn
12
-
13
- No need to learn and configure build, lint, and testing environment. Quick reloads help to focus on development. When it's time to deploy bundles are optimized automatically.
14
-
15
- #### Dependencies encapsulation
16
-
17
- It's overwhelming how many development dependencies are required to work with the modern web application, with [@servicetitan/startup](https://github.com/servicetitan/uikit/tree/master/packages/startup) everything is already pre-included.
18
-
19
- #### Easy to maintain
20
-
21
- Updating build tooling is typically a daunting and time-consuming task. When new versions of [@servicetitan/startup](https://github.com/servicetitan/uikit/tree/master/packages/startup) are released, you just need to bump its version.
22
-
23
- ## Commands
24
-
25
- :::caution
26
- Experimental flags don't follow semver. There might be breaking changes in minor versions of `@servicetitan/startup` when you opt-in to experimental flags.
27
- :::
28
-
29
- ### convert-eslint-config
30
-
31
- Convert an ESLint v8 configuration to v9 format.
32
-
33
- ```sh
34
- $ npx startup convert-eslint-config
35
- ```
36
-
37
- Use this command when upgrading from ESLint v8 to v9, to convert a v8 `.eslintrc.json` to the equivalent `eslint.config.mjs`. See [Upgrading to ESLint v9.x](/docs/frontend/upgrading-to-eslint-v9) for guidance on upgrading to ESLint v9.
38
-
39
- The command takes no arguments. Simply run it from a directory with `.eslintrc.json` and it creates `eslint.config.mjs` in the same location.
40
-
41
- :::caution
42
- Comments are not copied from the source `.eslintrc.json` to the output file.
43
- If the source file contains important comments, copy them manually to the output file.
44
- :::
45
-
46
- ### build
47
-
48
- Build packages for production to the `dist/bundle` folders. It bundles them in production mode and optimizes the build for the best performance. The builds are minified and the filenames include the hashes. Apps are ready to be deployed.
49
-
50
- #### Arguments
51
-
52
- - `--scope <glob>` - Include only packages with names matching the given glob.
53
- - `--ignore <glob>` - Exclude packages with names matching the given glob.
54
- - `--cdn-path <url>` - Specify the base path for all the assets within the application.
55
- - `--stat` - Generate bundle report with [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer). Starting `v22.3.0` works for [MFEs](/docs/frontend/micro-frontends) too.
56
- - `--esbuild` - Use [esbuild-loader](https://github.com/privatenumber/esbuild-loader) to process TypeScript files instead of ts-loader.
57
- - `--experimental-bundlers` - Use experimental build optimizations (alternative loaders and bundlers)
58
- - `--code-coverage` - Add [instrumentation](https://github.com/JS-DevTools/coverage-istanbul-loader) to bundled code in order to collect code coverage
59
-
60
- ### init
61
-
62
- Generates initial project structure. This command should be run via `npx` in an empty folder.
63
-
64
- ```sh
65
- $ npx -y @servicetitan/startup@latest init
66
- ```
67
-
68
- ### install
69
-
70
- Installs the package dependencies. This command should be run via `npx` before the build.
71
-
72
- See [package.json in the example project](https://github.com/search?q=repo%3Aservicetitan%2Ffrontend-example+path%3A**%2Fpackage.json+%22startup+install%22&type=code).
73
-
74
- ### kendo-ui-license
75
-
76
- Activates KendoReact components by installing the license key. The license key is only installed if the project depends on `@progress/kendo` components. Otherwise, this command has no effect.
77
-
78
- **Note:** The [build](#build) command automatically detects when a project uses KendoRect components and runs this command.
79
-
80
- Use it to install the license key separately from a build, or to override the default license key.
81
-
82
- ```sh
83
- $ npx startup kendo-ui-license
84
- ```
85
-
86
- To install a different license, set the KENDO_UI_LICENSE environment variable to the key to use.
87
-
88
- ```sh
89
- $ export KENDO_UI_LICENSE=<license-key>
90
- $ npx startup kendo-ui-license
91
- ```
92
-
93
- ### lint
94
-
95
- Runs ESLint and Stylelint for all codebase projects.
96
-
97
- To run ESLint and Stylelint on certain packages or subsystems it is possible to pass paths to specific directories as positional parameters.
98
-
99
- ```sh
100
- $ npx startup lint -- packages/desktop/app/modules/inventory/
101
- ```
102
-
103
- You can use multiple paths and your shell expressions which expand to directories.
104
-
105
- ```sh
106
- $ npx startup lint -- packages/desktop/app/modules/lead/ packages/desktop/app/modules/inventory/
107
- $ npx startup lint -- packages/desktop/app/modules/{lead,inventory}/
108
- ```
109
-
110
- #### Options
111
-
112
- - `--scope <glob>` - Include only packages with names matching the given glob.
113
- - `--ignore <glob>` - Exclude packages with names matching the given glob.
114
- - `--fix` - Fix linting issues.
115
-
116
- ### mfe-publish
117
-
118
- This is an umbrella command for both publishing and unpublishing (cleaning up) MFEs. This command allows publishing MFEs in a way that there is no risk of colliding package versions (a common issue with back-merging). See the `--build` option for more details.
119
-
120
- #### Publishing options
121
-
122
- | Option | Description |
123
- | :------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
124
- | `--build <glob>` | Optional build version that normally should not be specified. Defaults to `<branch_name>.<commit_hash>`. For example, if git commit `bdac90f5` is published from branch `next`, the build version is`next.bdac90f5`, and the full version is `0.0.0-next.bdac90f5`. This ensures each release has a unique version with no collisions. |
125
- | `--dry` | Invoke [npm publish --dry-run](https://docs.npmjs.com/cli/v7/commands/npm-publish#dry-run) instead of actually publishing anything. |
126
- | `--branch <string>` | Optional branch name. The current branch name is used if no value is specified. The branch name is used in constructing the build version in case `--build` is not specified. |
127
- | `--force` | Forces publishing the package when no configuration was found for the specified branch (`--branch` or current branch). |
128
- | `--tag <string>` | The [tag](https://docs.npmjs.com/cli/v7/commands/npm-publish#tag) to assign to the published version. Defaults to the tag associated with the branch from the custom [branch config](#branch-configs) or, if there is no custom branch config, from the [default branch config](https://github.com/servicetitan/uikit/blob/master/packages/startup/src/utils/get-branch-configs.ts#L3). For example, by default a package published from the `master` branch is tagged `prod`. Becasue NPM v11 requires pre-release versions to have a tag, if there is no custom or default tag for the branch, the package is tagged "latest". |
129
-
130
- #### Unpublishing options
131
-
132
- | Option | Descripiton |
133
- | :----------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- |
134
- | `--clean` | Instructs `mfe-publish` to remove old versions instead of publishing. |
135
- | `--count <number>` | The number of package versions to keep (e.g., if twelve versions are published, `--count 10` removes the two oldest). The default value is 5. |
136
- | `--branch <name>` | Remove old versions associated with the specified branch. Defaults to the current branch (i.e., `git branch --show-current`) |
137
- | `--all` | Remove old versions associated with all [recognized branches](#branch-configs). This overrides `--branch`. |
138
- | `--dry` | Log what the command would do without actually unpublishing anything. |
139
-
140
- #### Branch configs
141
-
142
- By default `mfe-publish` only publishes from a few [recognized branches](https://github.com/servicetitan/uikit/blob/master/packages/startup/src/utils/get-branch-configs.ts#L3) and you must use `--force` to publish from others.
143
-
144
- To customize the recognized branches for an MFE set `cli.web-component.branches` in the MFE's package.json to an object that maps branch names to the associated tag. For example,
145
-
146
- ```json
147
- "cli": {
148
- "web-component": {
149
- "branches": {
150
- "qa": { "publishTag": "qa" },
151
- "staging": { "publishTag": "staging" },
152
- "master": { "publishTag": "prod" }
153
- }
154
- }
155
- }
156
- ```
157
-
158
- - `publishTag: string` - Tag used when publishing package.
159
-
160
- ### start
161
-
162
- Runs package in the development mode. Applications will be hosted on sequential free ports starting from 8080. Pages will automatically reload on changes to the code.
163
-
164
- #### Arguments
165
-
166
- - `--scope <glob>` - Include only packages with names matching the given glob.
167
- - `--ignore <glob>` - Exclude packages with names matching the given glob.
168
- - `--esbuild` - Use [esbuild-loader](https://github.com/privatenumber/esbuild-loader) to process TypeScript files instead of ts-loader.
169
- - `--experimental-bundlers` - Use experimental build optimizations (alternative loaders and bundlers)
170
- - `--code-coverage` - Add [instrumentation](https://github.com/JS-DevTools/coverage-istanbul-loader) to bundled code in order to collect code coverage
171
-
172
- ### test
173
-
174
- Runs all existing tests in all packages.
175
-
176
- To run tests a subset of tests is possible to pass paths to specific directories or test files as positional parameters.
177
-
178
- ```sh
179
- $ npx startup test -- packages/desktop/app/modules/inventory/
180
- ```
181
-
182
- ## Build Steps
183
-
184
- The `build` command executes these steps:
185
-
186
- 1. For each non-webpack package, generate TypeScript definitions from CSS, LESS, and SASS modules, and copy assets and style files to the output folder. This step runs in parallel for each package.
187
- 1. Compile non-webpack packages in order (via [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html)).
188
- 1. Bundle webpack packages, in parallel.
189
-
190
- The `start` command executes the same steps then watches for changes and automatically reruns each step as needed.
191
-
192
- #### Important Note
193
-
194
- It doesn't support hierarchical watch because we are not maintaining hierarchy ourselves, so we have to build everything first and then run watch when order is no longer important. Also, it doesn't support dependencies between the Webpack bundles.
195
-
196
- ## Package Setup
197
-
198
- Because `startup` compiles and builds in separate steps, packages should export the compiled output instead of the TypeScript source files.
199
-
200
- For example, the Webpack documentation suggests a configuration that directs webpack to enter through `./src/index.ts` and load all `.ts` and `.tsx` files through `ts-loader`. However, because `startup` precompiles Typescript files, this is redundant and webpack should be configured to load the compiled Javascript.
201
-
202
- ```json title="package.json"
203
- {
204
- "main": "./dist/index.js",
205
- "typings": "./dist/index.d.ts"
206
- }
207
- ```
208
-
209
- And, [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html) should be used to describe the dependencies between components.
210
-
211
- ```json title="tsconfig.json"
212
- {
213
- "references": [
214
- { "path": "../component-a" },
215
- { "path": "../component-b" },
216
- { "path": "../component-c" }
217
- ]
218
- }
219
- ```
220
-
221
- ## CSS Modules
222
-
223
- This project supports [CSS Modules](https://github.com/css-modules/css-modules) alongside regular stylesheets using the `[name].module.{css,less,scss}` file naming convention. It allows the scoping of CSS by automatically creating a unique class name.
224
-
225
- ## SVG Transformation
226
-
227
- :::caution
228
- Type definitions are provided for the various ways of importing SVGs via the base tsconfig's
229
- `"files"` property within `startup`. If you override the `"files"` property
230
- within your tsconfig, you may lose access to these type definitions, and will need to add them
231
- manually.
232
- :::
233
-
234
- By default, SVGs are loaded as assets. Depending on the file size, the asset is converted to a base64 URI string, or emitted as separate file.
235
-
236
- ```tsx
237
- import MySVG from './my.svg';
238
- ...
239
- <img src={MySVG} />
240
- ```
241
-
242
- When importing SVGs from Anvil 2 (`@servicetitan/anvil2`), [SVGR](https://react-svgr.com/) is used to transform SVGs into React components.
243
-
244
- ```tsx
245
- import CheckIcon from '@servicetitan/anvil2/assets/icons/material/round/check.svg';
246
- ...
247
- <CheckIcon />
248
- ```
249
-
250
- In order to use SVGR with SVGs outside of Anvil 2, you can import them as components by passing the `?component` query to the important statement. For example:
251
-
252
- ```tsx
253
- import CheckIcon from './assets/check.svg?component';
254
- ...
255
- <CheckIcon />
256
- ```
257
-
258
- If you'd like to use SVGs imported from Anvil 2 as assets, you can pass the `?asset` query to the import statement. For example:
259
-
260
- ```tsx
261
- import CheckIcon from '@servicetitan/anvil2/assets/icons/material/round/check.svg?asset';
262
- ...
263
- <img src={CheckIcon} />
264
- ```
265
-
266
- ## Configuration Customization
267
-
268
- The zero-configuration approach is a good fit for most use cases, but sometimes applications need to extend or override configurations.
269
- Use the `cli` node in `package.json` to customize `startup` behavior.
270
-
271
- ### Project-wide settings
272
-
273
- Use the `cli` node in the root `package.json` to customize project-wide settings.
274
-
275
- #### Jest
276
-
277
- Use `test` to set or override Jest options. E.g.,
278
-
279
- ```json title="package.json"
280
- {
281
- "cli": {
282
- "test": {
283
- // Jest options (https://jestjs.io/docs/next/configuration)
284
- }
285
- }
286
- }
287
- ```
288
-
289
- #### Linting
290
-
291
- Use `lint` to set or override `ESLint` and `Stylelint` options. E.g,
292
-
293
- ```json title="package.json"
294
- {
295
- "cli": {
296
- "lint": {
297
- "eslint": {
298
- // ESLint options (https://eslint.org/docs/user-guide/configuring)
299
- },
300
- "stylelint": {
301
- // Stylelint options (https://stylelint.io/user-guide/configure)
302
- }
303
- }
304
- }
305
- }
306
- ```
307
-
308
- #### NODE_OPTIONS
309
-
310
- Use `NODE_OPTIONS` to set or override Node options for some or all commands. E.g.,
311
-
312
- :::info
313
- Note, `startup` runs all commands with `--max_old_space_size=8192` by default.
314
- :::
315
-
316
- ```json title="package.json"
317
- {
318
- "cli": {
319
- "NODE_OPTIONS": ["--max_old_space_size=4096"], // NODE_OPTIONS for all commands
320
- "lint": {
321
- "NODE_OPTIONS": [
322
- /* NODE_OPTIONS for lint command */
323
- ]
324
- },
325
- "test": {
326
- "NODE_OPTIONS": [
327
- /* NODE_OPTIONS for test command */
328
- ]
329
- }
330
- }
331
- }
332
- ```
333
-
334
- ### Package-specific settings
335
-
336
- To customize the settings for a specific package, use the `cli` node in its `package.jon`.
337
-
338
- ##### Non-application packages
339
-
340
- Set `webpack` to `false` to disable Webpack bundling for non-application NPM packages, such as component and utility libraries. E.g.,
341
-
342
- ```json title="package.json"
343
- {
344
- "cli": {
345
- "webpack": false
346
- }
347
- }
348
- ```
349
-
350
- ##### Microfrontends (MFEs)
351
-
352
- Set `web-component` to `true` to create the support files and `light` and `full` bundles for MFE applications. E.g.,
353
-
354
- ```json title="package.json"
355
- {
356
- "cli": {
357
- "web-component": true
358
- }
359
- }
360
- ```
361
-
362
- Or you can set an object with detailed configs:
363
-
364
- ```json title="package.json"
365
- {
366
- "cli": {
367
- "web-component": {
368
- "branches": {
369
- "qa": { "publishTag": "qa" }
370
- }
371
- }
372
- }
373
- }
374
- ```
375
-
376
- Or you can use relative path to a file that exports an object with detailed configs (useful to share configs between multiple MFEs in repo):
377
-
378
- ```json title="package.json"
379
- {
380
- "cli": {
381
- "web-component": "../../config/web-component.js"
382
- }
383
- }
384
- ```
385
-
386
- ###### Web component config options
387
-
388
- - `branches` - Set git branch specific configs, used for publishing. See [Branch configs](#branch-configs).
389
- - `legacyRoot` - Set to opt-out of automatic batching. See [Opting-out of automatic batching](/docs/frontend/react-18#opting-out-of-automatic-batching).
390
-
391
- See [MFE configuration](/docs/frontend/micro-frontends/#mfe-configuration) for detailed instructions on configuring MFE applications.
392
-
393
- ##### Minification
394
-
395
- By default `startup` configures webpack to minify production bundles conservatively,
396
- so that projects gain the benefits of reduced bundle sizes while retaining the highest
397
- fidelity for source map debugging.
398
-
399
- Set `minify.js` or `minify.css` to `false` to prevent webpack from minifying JS or CSS bundles.
400
-
401
- Startup uses [TerserWebpackPlugin](https://webpack.js.org/plugins/terser-webpack-plugin) to minify JS bundles
402
- and uses [CssMinimizerWebpackPlugin](https://webpack.js.org/plugins/css-minimizer-webpack-plugin)
403
- to minify CSS bundles.
404
-
405
- To override the default Terser options set `minify.js` to an object containing
406
- [`terserOptions`](https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptions).
407
- To override the default CssMinimizerWebpackPlugin options, set `minify.css` to an object containing
408
- [CssMinimizerWebpackPlugin options](https://webpack.js.org/plugins/css-minimizer-webpack-plugin/#options).
409
- E.g.,
410
-
411
- ```json title="package.json"
412
- {
413
- "cli": {
414
- "webpack": {
415
- "minify": {
416
- "js": {
417
- // terser-webpack-plugin terserOptions
418
- },
419
- "css": {
420
- // css-minimizer-webpack-plugin options
421
- }
422
- }
423
- }
424
- }
425
- }
426
- ```
427
-
428
- ##### Application Port
429
-
430
- Use `port` to set the port that `webpack-dev-server` uses for the application. E.g.,
431
-
432
- ```json title="package.json"
433
- {
434
- "cli": {
435
- "webpack": {
436
- "port": 8888
437
- }
438
- }
439
- }
440
- ```
441
-
442
- #### webpack-dev-server
443
-
444
- Use `webpack.devServer` to set or override `webpack-dev-server` options. E.g.,
445
-
446
- ```json title="package.json"
447
- {
448
- "cli": {
449
- "webpack": {
450
- "devServer": {
451
- // webpack-dev-server options (https://webpack.js.org/configuration/dev-server/#devserver)
452
- }
453
- }
454
- }
455
- }
456
- ```
457
-
458
- `webpack.devServer` can also be set to `false` in order to disable `webpack-dev-server` altogether.
459
-
460
- #### Webpack Configuration
461
-
462
- If you need to add additional rules or change the build output path or make any other customization of the Webpack configuration, you should create `webpack.{env}.config.js` files in the package's root folder. These files should call `createWebpackConfig` with the required configuration.
463
-
464
- ##### createWebpackConfig
465
-
466
- Accepts an object with two fields: `configuration` and `plugins` (currently only `ForkTsCheckerWebpackPlugin` and `HtmlWebpackPlugin` are supported, and `MiniCssExtractPlugin` is only supported for production builds) with settings overrides for Webpack and its plugins. Returns default Webpack configuration for provided `configuration.mode` with applied overrides.
467
-
468
- ```js title="webpack.dev.config.js"
469
- const path = require('path');
470
-
471
- const { createWebpackConfig } = require('@servicetitan/startup');
472
-
473
- module.exports = createWebpackConfig({
474
- configuration: {
475
- mode: 'development',
476
- output: { path: path.resolve(__dirname, '../../wwwroot') },
477
- },
478
- });
479
- ```
480
-
481
- ```js title="webpack.prod.config.js"
482
- const path = require('path');
483
-
484
- const { createWebpackConfig } = require('@servicetitan/startup');
485
-
486
- module.exports = createWebpackConfig({
487
- configuration: {
488
- mode: 'production',
489
- output: { path: path.resolve(__dirname, '../../wwwroot') },
490
- },
491
- });
492
- ```
493
-
494
- ##### MFE webpack config
495
-
496
- Since `v22.7.0` providing custom webpack configuration for MFEs is also supported. However, there is a caveat. You can't use the `createWebpackConfig` to create the configuration as MFEs exist in two variants: a full build (includes all dependencies of MFE) and a light build (has shared dependencies with the host app and does not bundle these deps). See the [discussion here](https://github.com/servicetitan/uikit/pull/1721#discussion_r1183007790) for more info. Below are examples of MFE webpack configs. These objects are then internally passed to `createWebpackConfig` (so the same limitation applies meaning only a few `plugins` can be specified in the config file, see the previous section on `createWebpackConfig`).
497
-
498
- ```js title="webpack.dev.config.js"
499
- const path = require('path');
500
-
501
- module.exports = {
502
- configuration: {
503
- mode: 'development',
504
- output: { path: path.resolve(__dirname, '../../wwwroot') },
505
- },
506
- plugins: [...]
507
- };
508
- ```
509
-
510
- ```js title="webpack.prod.config.js"
511
- const path = require('path');
512
-
513
- module.exports = {
514
- configuration: {
515
- mode: 'production',
516
- output: { path: path.resolve(__dirname, '../../wwwroot') },
517
- },
518
- plugins: [...]
519
- };
520
- ```