@servicetitan/docs-uikit 36.3.0 → 36.4.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/BREAKING_CHANGES.mdx +1 -1
- package/docs/ai-marketplace.mdx +5 -4
- package/docs/datadog-rum.mdx +302 -40
- package/docs/install.mdx +10 -6
- package/docs/lazy-module.mdx +1 -1
- package/docs/microfrontends/hosting.mdx +6 -4
- package/docs/microfrontends/sharing-dependencies.mdx +15 -17
- package/docs/startup/build/build.mdx +199 -0
- package/docs/startup/build/vite.mdx +274 -0
- package/docs/startup/build/webpack.mdx +117 -0
- package/docs/startup/start/start.mdx +48 -0
- package/docs/startup/start/vite.mdx +90 -0
- package/docs/startup/start/webpack.mdx +39 -0
- package/docs/startup/startup.mdx +40 -5
- package/package.json +2 -2
- package/docs/startup/build.mdx +0 -310
- package/docs/startup/start.mdx +0 -73
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: build
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
`startup` supports two bundlers: [Webpack](./webpack) (default) and [Vite](./vite) (opt-in via `--use-vite`).
|
|
8
|
+
|
|
9
|
+
## Options
|
|
10
|
+
|
|
11
|
+
| Option | Webpack | Vite | Description |
|
|
12
|
+
| :----------------- | :------ | :------ | :------------------------------------------------------------------------ |
|
|
13
|
+
| `--scope <glob>` | Yes | Yes | Include only packages with names matching the given glob. |
|
|
14
|
+
| `--ignore <glob>` | Yes | Yes | Exclude packages with names matching the given glob. |
|
|
15
|
+
| `--cdn-path <url>` | Yes | Planned | Specify the base path for all the assets within the application. |
|
|
16
|
+
| `--stat` | Yes | Planned | Generate bundle analysis report. |
|
|
17
|
+
| `--code-coverage` | Yes | Planned | Add instrumentation to bundled code in order to collect code coverage. |
|
|
18
|
+
| `--use-tsc` | Yes | Yes | Use TSC for TypeScript compilation. |
|
|
19
|
+
| `--use-vite` | No | Yes | ✨ **36.4.0** Use Vite instead of webpack. |
|
|
20
|
+
| `--preview` | No | Yes | ✨ **36.4.0** Preview production build locally via a static server. |
|
|
21
|
+
| `--config <path>` | Yes | No | Custom config file path. Vite uses convention-based config files instead. |
|
|
22
|
+
|
|
23
|
+
## Build Steps
|
|
24
|
+
|
|
25
|
+
The `build` command executes these steps:
|
|
26
|
+
|
|
27
|
+
1. Activate Kendo UI license.
|
|
28
|
+
1. Run package **precompile** scripts, if any.
|
|
29
|
+
1. Compile Typescript.
|
|
30
|
+
1. Generate TypeScript definitions from CSS, LESS, and SASS modules, and copy assets and style files to the output folder.
|
|
31
|
+
1. Run type check via [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html).
|
|
32
|
+
1. Bundle application and MFE packages.
|
|
33
|
+
|
|
34
|
+
### Precompile Script
|
|
35
|
+
|
|
36
|
+
✨ New in **v34.0.0** ✨
|
|
37
|
+
|
|
38
|
+
The `build` command runs the `precompile` script defined in each package's `package.json` before compiling TypeScript. This allows packages to execute custom setup tasks during the build process. If a package doesn't define a `precompile` script, this step is skipped.
|
|
39
|
+
|
|
40
|
+
## Package Setup
|
|
41
|
+
|
|
42
|
+
Because `startup` compiles and builds in separate steps, packages must export compiled Javascript instead of the TypeScript source files. E.g.,
|
|
43
|
+
|
|
44
|
+
```json title="package.json"
|
|
45
|
+
{
|
|
46
|
+
"exports": "./dist/index.js",
|
|
47
|
+
"main": "./dist/index.js",
|
|
48
|
+
"typings": "./dist/index.d.ts"
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
And, to ensure packages are compiled in the correct order, [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html) must accurately describe the dependencies between packages. E.g.,
|
|
53
|
+
|
|
54
|
+
```json title="tsconfig.json"
|
|
55
|
+
{
|
|
56
|
+
"references": [
|
|
57
|
+
{ "path": "../component-a" },
|
|
58
|
+
{ "path": "../component-b" },
|
|
59
|
+
{ "path": "../component-c" }
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## CSS Modules
|
|
65
|
+
|
|
66
|
+
`Startup` supports [CSS Modules](https://github.com/css-modules/css-modules) alongside regular stylesheets using the `[name].module.{css,less,scss}` file naming convention. CSS Modules provide locally scoped class names that prevent global CSS collisions, making styles more predictable and easier to refactor.
|
|
67
|
+
|
|
68
|
+
## SVG Transformation
|
|
69
|
+
|
|
70
|
+
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. E.g.,
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import MySVG from './my.svg';
|
|
74
|
+
|
|
75
|
+
function MyImage() {
|
|
76
|
+
return <img src={MySVG} />;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Importing SVGs as React Components
|
|
81
|
+
|
|
82
|
+
By default `startup` imports SVGs from `@servicetitan/anvil2` as React components. E.g.,
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { Button } from '@servicetitan/anvil2';
|
|
86
|
+
import CheckIcon from '@servicetitan/anvil2/assets/icons/material/round/check.svg';
|
|
87
|
+
|
|
88
|
+
export function CheckButton() {
|
|
89
|
+
return <Button icon={CheckIcon} />;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
To import SVGs from other sources as React components, append `?component` to the import statement. E.g.,
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { Button } from '@servicetitan/anvil2';
|
|
97
|
+
import CheckIcon from './assets/check.svg?component';
|
|
98
|
+
|
|
99
|
+
export function CheckButton() {
|
|
100
|
+
return <Button icon={CheckIcon} />;
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Importing Anvil 2 SVGs as Assets
|
|
105
|
+
|
|
106
|
+
By default `startup` imports SVGs from `@servicetitan/anvil2` as React components.
|
|
107
|
+
To import an Anvil 2 SVG as an asset, append `?asset` to the import statement. E.g.,
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
import CheckIcon from '@servicetitan/anvil2/assets/icons/material/round/check.svg?asset';
|
|
111
|
+
|
|
112
|
+
function CheckImage() {
|
|
113
|
+
return <img src={CheckIcon} />;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Configuration
|
|
118
|
+
|
|
119
|
+
### Library Packages
|
|
120
|
+
|
|
121
|
+
Set `cli.webpack` or `cli.vite` to `false` to disable bundling for non-application packages, such as component and utility libraries.
|
|
122
|
+
|
|
123
|
+
```json title="package.json"
|
|
124
|
+
{
|
|
125
|
+
"cli": {
|
|
126
|
+
"webpack": false
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Type Checking
|
|
132
|
+
|
|
133
|
+
Use package-specific `tsconfig.json` and `tsconfig.build.json` files to set or override type checking options. E.g.,
|
|
134
|
+
|
|
135
|
+
```json title="tsconfig.json"
|
|
136
|
+
{
|
|
137
|
+
"extends": "@servicetitan/startup/tsconfig/base",
|
|
138
|
+
"compilerOptions": {
|
|
139
|
+
"outDir": "dist",
|
|
140
|
+
"rootDir": "src"
|
|
141
|
+
// Other type checking options (https://www.typescriptlang.org/tsconfig/)
|
|
142
|
+
},
|
|
143
|
+
"include": ["src/**/*"]
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Use `tsconfig.build.json` that extends from `tsconfig.json` to exclude tests, stories, and mocks from type checking. E.g.,
|
|
148
|
+
|
|
149
|
+
```json title="tsconfig.build.json"
|
|
150
|
+
{
|
|
151
|
+
"extends": "./tsconfig.json",
|
|
152
|
+
"exclude": ["**/__tests__/*", "**/*.test.*", "**/__mocks__/*", "**/*.stories.*"],
|
|
153
|
+
"references": [
|
|
154
|
+
{ "path": "../feature-a" },
|
|
155
|
+
{ "path": "../feature-b" },
|
|
156
|
+
{ "path": "../feature-c" }
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
:::caution
|
|
162
|
+
Project references must be duplicated in `tsconfig.build.json` because [references are not inherited](https://github.com/microsoft/TypeScript/issues/27098).
|
|
163
|
+
:::
|
|
164
|
+
|
|
165
|
+
### TypeScript Compilation (SWC)
|
|
166
|
+
|
|
167
|
+
:::info
|
|
168
|
+
`Startup` only maps a subset of TypeScript settings from `tsconfig.json` to SWC options. See [cliOptions](https://github.com/search?q=repo%3Aservicetitan%2Fuikit+%22cliOptions%3A%22+-path%3A**%2F*.test.ts&type=code) and [swcOptions](https://github.com/search?q=repo%3Aservicetitan%2Fuikit+%22swcOptions%3A%22+-path%3A**%2F*.test.ts&type=code) for the details.
|
|
169
|
+
:::
|
|
170
|
+
|
|
171
|
+
Use `cli.swc-compile-package` to set or override SWC options. E.g.,
|
|
172
|
+
|
|
173
|
+
```json title="package.json"
|
|
174
|
+
{
|
|
175
|
+
"cli": {
|
|
176
|
+
"swc-compile-package": {
|
|
177
|
+
"cliOptions": {
|
|
178
|
+
// CLI options (https://swc.rs/docs/usage/cli)
|
|
179
|
+
},
|
|
180
|
+
"swcOptions": {
|
|
181
|
+
// Compilation options (https://swc.rs/docs/configuration/compilation)
|
|
182
|
+
// Module options (https://swc.rs/docs/configuration/modules)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### TypeScript Compilation (TSC)
|
|
190
|
+
|
|
191
|
+
:::caution
|
|
192
|
+
Compilation via TSC is deprecated.
|
|
193
|
+
:::
|
|
194
|
+
|
|
195
|
+
Use package-specific `tsconfig.json` and `tsconfig.build.json` files to set or override compiler options. See [Type checking](#type-checking) for more information.
|
|
196
|
+
|
|
197
|
+
### Bundler-Specific Configuration
|
|
198
|
+
|
|
199
|
+
See [Webpack](./webpack) or [Vite](./vite) for bundler-specific configuration options, including minimization, custom config files, and plugin overrides.
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Vite
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
✨ New in **36.4.0** ✨
|
|
6
|
+
|
|
7
|
+
Vite is an alternative bundler for `startup build`, enabled with the `--use-vite` flag. It uses [Vite](https://vite.dev/) with the [Rolldown](https://rolldown.rs/) bundler and [OXC](https://oxc.rs/) minifier/transformer.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npx startup build --use-vite
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
:::tip
|
|
14
|
+
For dev server configuration (port, proxy, HMR), see [Vite start](../start/vite).
|
|
15
|
+
:::
|
|
16
|
+
|
|
17
|
+
## Configuration Priority
|
|
18
|
+
|
|
19
|
+
Vite configuration comes from three sources, merged in order (later wins):
|
|
20
|
+
|
|
21
|
+
1. **Startup defaults**: base config built by startup
|
|
22
|
+
2. **`cli.vite` in package.json**: serializable overrides
|
|
23
|
+
3. **Config file** (`vite.dev.config.ts` / `vite.prod.config.ts`): full Vite config via [`defineConfig`](#config-files-defineconfig)
|
|
24
|
+
|
|
25
|
+
## Configuration Shortcuts
|
|
26
|
+
|
|
27
|
+
Shortcuts are convenience options available in both `cli.vite` (package.json) and config files. They map to multiple Vite config values internally.
|
|
28
|
+
|
|
29
|
+
| Shortcut | Type | Description |
|
|
30
|
+
| :---------------- | :-------------------------------- | :------------------------------------ |
|
|
31
|
+
| `omitDefault` | `string[]` | Remove default config keys or plugins |
|
|
32
|
+
| `minify` | `{ js?: boolean, css?: boolean }` | Toggle JS/CSS minification |
|
|
33
|
+
| `pluginOverrides` | `{ html?, svgr? }` | Override default plugin options |
|
|
34
|
+
|
|
35
|
+
### `omitDefault`
|
|
36
|
+
|
|
37
|
+
List of config keys or plugin names to remove from startup's defaults. Plugin names are prefixed with `plugins.`.
|
|
38
|
+
|
|
39
|
+
```json title="package.json"
|
|
40
|
+
{
|
|
41
|
+
"cli": {
|
|
42
|
+
"vite": {
|
|
43
|
+
"omitDefault": ["plugins.svgr", "css"]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### `minify`
|
|
50
|
+
|
|
51
|
+
Boolean toggle for JS and CSS minification. Defaults to minimizing with [OXC](https://oxc.rs/docs/guide/usage/minifier) in production, unminified in development.
|
|
52
|
+
|
|
53
|
+
```json title="package.json"
|
|
54
|
+
{
|
|
55
|
+
"cli": {
|
|
56
|
+
"vite": {
|
|
57
|
+
"minify": {
|
|
58
|
+
"js": false,
|
|
59
|
+
"css": false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
To customize minification, configure Vite directly in `vite.prod.config.ts` (or `cli.vite.config`). For example, to use Terser instead, set `build.minify: 'terser'` and pass options via `build.terserOptions`:
|
|
67
|
+
|
|
68
|
+
```ts title="vite.prod.config.ts"
|
|
69
|
+
import { defineConfig } from '@servicetitan/startup/vite';
|
|
70
|
+
|
|
71
|
+
export default defineConfig({
|
|
72
|
+
config: {
|
|
73
|
+
build: {
|
|
74
|
+
minify: 'terser',
|
|
75
|
+
terserOptions: { compress: { drop_console: true } },
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
See Vite's [`build.minify`](https://vite.dev/config/build-options.html#build-minify) for the full minifier reference.
|
|
82
|
+
|
|
83
|
+
### `pluginOverrides`
|
|
84
|
+
|
|
85
|
+
Override options for startup's built-in plugins.
|
|
86
|
+
|
|
87
|
+
#### `html`
|
|
88
|
+
|
|
89
|
+
| Option | Type | Default | Description |
|
|
90
|
+
| :--------- | :------- | :------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
91
|
+
| `title` | `string` | `'ServiceTitan'` | Page title in `<title>` tag |
|
|
92
|
+
| `favicon` | `string` | `'/favicon.ico'` if present in [`publicDir`](https://vite.dev/config/shared-options.html#publicdir), otherwise none | Favicon URL for the `<link rel="icon">` tag. Use `/filename` for files in [`publicDir`](https://vite.dev/config/shared-options.html#publicdir), or a path relative to the package root. |
|
|
93
|
+
| `template` | `string` | `index.ejs` or `index.html` in the package source directory, otherwise the built-in template | Path to a custom HTML template using eta template syntax. Both `.ejs` and `.html` extensions are accepted. |
|
|
94
|
+
|
|
95
|
+
#### `svgr`
|
|
96
|
+
|
|
97
|
+
| Option | Type | Description |
|
|
98
|
+
| :------------ | :--------------------------------------------------- | :--------------------------------- |
|
|
99
|
+
| `include` | `string \| string[]` | Glob patterns to include for SVGR |
|
|
100
|
+
| `exclude` | `string \| string[]` | Glob patterns to exclude from SVGR |
|
|
101
|
+
| `svgrOptions` | [`SvgrConfig`](https://react-svgr.com/docs/options/) | Options passed to SVGR transformer |
|
|
102
|
+
|
|
103
|
+
## Vite Config (`cli.vite.config`)
|
|
104
|
+
|
|
105
|
+
For direct Vite configuration, use `cli.vite.config` in package.json. It accepts Vite's [`UserConfig`](https://vite.dev/config/) shape, minus `plugins` (not serializable in JSON).
|
|
106
|
+
|
|
107
|
+
```json title="package.json"
|
|
108
|
+
{
|
|
109
|
+
"cli": {
|
|
110
|
+
"vite": {
|
|
111
|
+
"config": {
|
|
112
|
+
"build": {
|
|
113
|
+
"target": "es2020"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Config Files (`defineConfig`)
|
|
122
|
+
|
|
123
|
+
For advanced configuration, create `vite.dev.config.ts` (development) or `vite.prod.config.ts` (production) in the package root. Config files support full Vite `UserConfig` including `plugins`.
|
|
124
|
+
|
|
125
|
+
Import `defineConfig` from `@servicetitan/startup/vite` for type safety:
|
|
126
|
+
|
|
127
|
+
```ts title="vite.prod.config.ts"
|
|
128
|
+
import { defineConfig } from '@servicetitan/startup/vite';
|
|
129
|
+
|
|
130
|
+
export default defineConfig({
|
|
131
|
+
config: {
|
|
132
|
+
build: {
|
|
133
|
+
target: 'es2020',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
pluginOverrides: {
|
|
137
|
+
html: {
|
|
138
|
+
title: 'My App',
|
|
139
|
+
favicon: '/brand.ico',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Dynamic Config with Build Context
|
|
146
|
+
|
|
147
|
+
Pass a function to `defineConfig` to access the build context:
|
|
148
|
+
|
|
149
|
+
```ts title="vite.prod.config.ts"
|
|
150
|
+
import { defineConfig } from '@servicetitan/startup/vite';
|
|
151
|
+
|
|
152
|
+
export default defineConfig(context => {
|
|
153
|
+
// context.build — { name, isProduction, light, headless }
|
|
154
|
+
// context.package — { destination, isWebComponent, sharedDependencies, ... }
|
|
155
|
+
// context.options (coming soon)
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
config: { ... },
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
:::tip
|
|
164
|
+
`.js` config files are also supported (`vite.dev.config.js` / `vite.prod.config.js`).
|
|
165
|
+
:::
|
|
166
|
+
|
|
167
|
+
:::tip
|
|
168
|
+
For full mutation access to the resolved config, add a Vite plugin with `enforce: 'post'` and a `config` hook as an escape hatch.
|
|
169
|
+
|
|
170
|
+
```ts title="vite.prod.config.ts"
|
|
171
|
+
import { defineConfig } from '@servicetitan/startup/vite';
|
|
172
|
+
|
|
173
|
+
export default defineConfig({
|
|
174
|
+
config: {
|
|
175
|
+
plugins: [
|
|
176
|
+
{
|
|
177
|
+
name: 'custom-config-override',
|
|
178
|
+
enforce: 'post',
|
|
179
|
+
config(resolved) {
|
|
180
|
+
resolved.build ??= {};
|
|
181
|
+
resolved.build.chunkSizeWarningLimit = 1000;
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
:::
|
|
190
|
+
|
|
191
|
+
## Custom HTML Templates
|
|
192
|
+
|
|
193
|
+
The HTML plugin uses [eta](https://eta.js.org/) as the template engine. By default it picks up `index.ejs` (or `index.html`) from the package source directory, matching webpack's `HtmlWebpackPlugin` convention, and falls back to the built-in template when neither file exists. Eta renders `.ejs` and `.html` files identically, so apps migrating from webpack keep their existing template without renaming it.
|
|
194
|
+
|
|
195
|
+
To use a template in a different location, or with a different name, configure its path via `pluginOverrides.html.template`:
|
|
196
|
+
|
|
197
|
+
```json title="package.json"
|
|
198
|
+
{
|
|
199
|
+
"cli": {
|
|
200
|
+
"vite": {
|
|
201
|
+
"pluginOverrides": {
|
|
202
|
+
"html": {
|
|
203
|
+
"title": "My App",
|
|
204
|
+
"favicon": "/brand.ico",
|
|
205
|
+
"template": "./config/host.html"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Example eta template:
|
|
214
|
+
|
|
215
|
+
```html title="src/index.ejs"
|
|
216
|
+
<!doctype html>
|
|
217
|
+
<html>
|
|
218
|
+
<head>
|
|
219
|
+
<meta charset="utf-8" />
|
|
220
|
+
<title><%= it.title %></title>
|
|
221
|
+
<link rel="icon" href="<%= it.favicon %>" />
|
|
222
|
+
<% it.css.forEach(function(item) { %>
|
|
223
|
+
<link href="./<%= item %>" rel="stylesheet" />
|
|
224
|
+
<% }); %> <% it.js.forEach(function(item) { %>
|
|
225
|
+
<script src="./<%= item %>"></script>
|
|
226
|
+
<% }); %>
|
|
227
|
+
</head>
|
|
228
|
+
<body>
|
|
229
|
+
<div id="root"></div>
|
|
230
|
+
<script type="module">
|
|
231
|
+
import './dist/index';
|
|
232
|
+
</script>
|
|
233
|
+
</body>
|
|
234
|
+
</html>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
:::tip
|
|
238
|
+
See [startup's default template](https://github.com/servicetitan/uikit/blob/master/packages/startup/src/vite/index.html) for a full working example, including MFE self-hosting and custom-element rendering.
|
|
239
|
+
:::
|
|
240
|
+
|
|
241
|
+
Available template variables:
|
|
242
|
+
|
|
243
|
+
| Variable | Type | Description |
|
|
244
|
+
| :--------------- | :--------- | :---------------------------------------------------------- |
|
|
245
|
+
| `title` | `string` | Page title from `pluginOverrides.html.title` |
|
|
246
|
+
| `favicon` | `string` | Favicon URL (explicit or auto-detected); may be `undefined` |
|
|
247
|
+
| `css` | `string[]` | Stylesheet entry paths to inject as `<link>` tags |
|
|
248
|
+
| `js` | `string[]` | Script entry paths to inject as `<script>` tags |
|
|
249
|
+
| `name` | `string` | Package/MFE name |
|
|
250
|
+
| `isProduction` | `boolean` | True for production builds |
|
|
251
|
+
| `isWebComponent` | `boolean` | True when building an MFE (web component) |
|
|
252
|
+
|
|
253
|
+
Use `<%= %>` for escaped output and `<%~ %>` for unescaped. See the [Eta docs](https://eta.js.org/) for the full template language reference, including conditionals, loops, and partials.
|
|
254
|
+
|
|
255
|
+
## Preview Server
|
|
256
|
+
|
|
257
|
+
Use the `--preview` flag to start preview servers for all bundled packages after a production build. Each package serves its built bundle from its output directory on its configured dev server port, opening the browser automatically.
|
|
258
|
+
|
|
259
|
+
Unlike `startup start`, preview servers serve only the built static assets: no source transformation, no hot reloading.
|
|
260
|
+
|
|
261
|
+
```sh
|
|
262
|
+
npx startup build --use-vite --preview
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
The preview server is useful for validating production builds locally before deploying.
|
|
266
|
+
|
|
267
|
+
## Not Yet Supported
|
|
268
|
+
|
|
269
|
+
The following features are planned but not yet available with the Vite bundler:
|
|
270
|
+
|
|
271
|
+
- `--stat`: bundle analysis report
|
|
272
|
+
- `--code-coverage`: code instrumentation for coverage
|
|
273
|
+
- `--cdn-path`: CDN public path
|
|
274
|
+
- Storybook configuration
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Webpack
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Webpack is the default bundler for `startup build`.
|
|
6
|
+
|
|
7
|
+
## Minimization
|
|
8
|
+
|
|
9
|
+
By default `startup` configures webpack to minimize production bundles conservatively,
|
|
10
|
+
so that projects gain the benefits of reduced bundle sizes while retaining the highest
|
|
11
|
+
fidelity for source map debugging.
|
|
12
|
+
It uses [TerserWebpackPlugin](https://webpack.js.org/plugins/terser-webpack-plugin) to minimize JS bundles
|
|
13
|
+
and [CssMinimizerWebpackPlugin](https://webpack.js.org/plugins/css-minimizer-webpack-plugin)
|
|
14
|
+
to minimize CSS bundles.
|
|
15
|
+
|
|
16
|
+
- To turn off minimizing, set `cli.webpack.minify.js` or `cli.webpack.minify.css`, or both, to `false`.
|
|
17
|
+
- To override the default Terser options set `cli.webpack.minify.js` to an object containing
|
|
18
|
+
[`terserOptions`](https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptions).
|
|
19
|
+
- To override the default CssMinimizerWebpackPlugin options, set `cli.webpack.minify.css` to an object containing
|
|
20
|
+
[CssMinimizerWebpackPlugin options](https://webpack.js.org/plugins/css-minimizer-webpack-plugin/#options).
|
|
21
|
+
|
|
22
|
+
For example,
|
|
23
|
+
|
|
24
|
+
```json title="package.json"
|
|
25
|
+
{
|
|
26
|
+
"cli": {
|
|
27
|
+
"webpack": {
|
|
28
|
+
"minify": {
|
|
29
|
+
"js": {
|
|
30
|
+
// terser-webpack-plugin terserOptions
|
|
31
|
+
// https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptions
|
|
32
|
+
},
|
|
33
|
+
"css": {
|
|
34
|
+
// css-minimizer-webpack-plugin options
|
|
35
|
+
// https://webpack.js.org/plugins/css-minimizer-webpack-plugin/#options
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Custom Configuration
|
|
44
|
+
|
|
45
|
+
To further customize Webpack settings, create files named `webpack.*.config.js` in the package's root directory (the directory with its `package.json`).
|
|
46
|
+
|
|
47
|
+
Use `webpack.dev.config.js` to customize development builds and use `webpack.prod.config.js` to customize production builds. In the config file,
|
|
48
|
+
|
|
49
|
+
- Import `createWebpackConfig` from `@servicetitan/startup`.
|
|
50
|
+
- Call it with the custom Webpack options.
|
|
51
|
+
- Return the result as the default export.
|
|
52
|
+
|
|
53
|
+
For example, to customize the Webpack's **output** path,
|
|
54
|
+
|
|
55
|
+
```js title="webpack.dev.config.js"
|
|
56
|
+
const path = require('path');
|
|
57
|
+
const { createWebpackConfig } = require('@servicetitan/startup');
|
|
58
|
+
|
|
59
|
+
module.exports = createWebpackConfig({
|
|
60
|
+
configuration: {
|
|
61
|
+
mode: 'development',
|
|
62
|
+
output: { path: path.resolve(__dirname, '../../wwwroot') },
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
:::caution
|
|
68
|
+
For MFEs the approach is slightly different, see [Customizing Webpack for MFEs](#customizing-webpack-for-mfes)
|
|
69
|
+
:::
|
|
70
|
+
|
|
71
|
+
### createWebpackConfig
|
|
72
|
+
|
|
73
|
+
`createWebpackConfig` takes an object with two fields, `configuration` and `plugins`.
|
|
74
|
+
|
|
75
|
+
| Field | Description |
|
|
76
|
+
| :-------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
77
|
+
| `configuration` | Merged with the defaults to produce the final webpack configuration. For production builds, **configuration.mode** must be set to "production". For development builds, set it to "development". |
|
|
78
|
+
| `plugins` | `HtmlWebpackPlugin` and `MiniCssExtractPlugin` subkeys are merged with the default configurations for the corresponding plugins. |
|
|
79
|
+
|
|
80
|
+
For example,
|
|
81
|
+
|
|
82
|
+
```js title="webpack.prod.config.js"
|
|
83
|
+
const { createWebpackConfig } = require('@servicetitan/startup');
|
|
84
|
+
|
|
85
|
+
module.exports = createWebpackConfig({
|
|
86
|
+
configuration: {
|
|
87
|
+
mode: 'production',
|
|
88
|
+
},
|
|
89
|
+
plugins: {
|
|
90
|
+
HtmlWebpackPlugin: {
|
|
91
|
+
favicon: './favicon.ico',
|
|
92
|
+
title: 'Enterprise Hub',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
:::caution
|
|
99
|
+
Remember, you must set `configuration.mode` to "production" in `webpack.prod.config.js`.
|
|
100
|
+
:::
|
|
101
|
+
|
|
102
|
+
### Customizing Webpack for MFEs
|
|
103
|
+
|
|
104
|
+
Because `startup` runs Webpack multiple times to create MFEs bundles, a slightly different approach is required for MFEs.
|
|
105
|
+
Don't call `createWebpackConfig` and just return an object with the same `configuration` and `plugins` fields described [above](#createwebpackconfig).
|
|
106
|
+
E.g.,
|
|
107
|
+
|
|
108
|
+
```js title="webpack.dev.config.js"
|
|
109
|
+
const path = require('path');
|
|
110
|
+
|
|
111
|
+
module.exports = {
|
|
112
|
+
configuration: {
|
|
113
|
+
mode: 'development',
|
|
114
|
+
output: { path: path.resolve(__dirname, '../../wwwroot') },
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: start
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Serves applications and [MFEs](../../microfrontends) during development, watches source files, and automatically reloads pages on changes.
|
|
6
|
+
|
|
7
|
+
`startup` supports two bundlers for development: [Webpack](./webpack) (default) and [Vite](./vite) (opt-in via `--use-vite`).
|
|
8
|
+
|
|
9
|
+
:::tip
|
|
10
|
+
To serve an application without `start`, [build](../build) it, then point any static http server to the output **bundle** directory, where the browser will find `index.html`. For example, to serve with [`http-server`](https://www.npmjs.com/package/http-server)
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npx -yes http-server packages/application/dist/bundle
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
:::
|
|
17
|
+
|
|
18
|
+
## Options
|
|
19
|
+
|
|
20
|
+
| Option | Webpack | Vite | Description |
|
|
21
|
+
| :---------------- | :------ | :------ | :--------------------------------------------------------------------- |
|
|
22
|
+
| `--scope <glob>` | Yes | Yes | Include only packages with names matching the given glob. |
|
|
23
|
+
| `--ignore <glob>` | Yes | Yes | Exclude packages with names matching the given glob. |
|
|
24
|
+
| `--code-coverage` | Yes | Planned | Add instrumentation to bundled code in order to collect code coverage. |
|
|
25
|
+
| `--use-tsc` | Yes | Yes | Use TSC for TypeScript compilation. |
|
|
26
|
+
| `--use-vite` | No | Yes | ✨ **36.4.0** Use Vite instead of webpack. |
|
|
27
|
+
|
|
28
|
+
## Start Steps
|
|
29
|
+
|
|
30
|
+
The `start` command executes the same steps as the `build` command, then watches for changes and automatically reruns each step as needed.
|
|
31
|
+
|
|
32
|
+
See [Build Steps](../build#build-steps).
|
|
33
|
+
|
|
34
|
+
## Port
|
|
35
|
+
|
|
36
|
+
The dev server port can be configured per-bundler in `package.json`. See [Webpack](./webpack#port) or [Vite](./vite#port) for details.
|
|
37
|
+
|
|
38
|
+
✨ New in **v35.2.0** ✨
|
|
39
|
+
|
|
40
|
+
You can also override the port at runtime using the `PORT` environment variable. This takes precedence over bundler-specific port configuration and is useful for tools like .NET Aspire that need to assign dynamic ports.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
PORT=3000 npm start
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
See [Webpack](./webpack) or [Vite](./vite) for bundler-specific dev server configuration.
|