or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

build-system.mdconfiguration.mdcss-processing.mddev-server.mdhmr.mdindex.mdmodule-resolution.mdplugin-system.mdssr.mdutilities.md

build-system.mddocs/

0

# Build System

1

2

Vite's build system provides production-ready builds powered by Rollup with advanced optimizations, code splitting, and comprehensive asset processing. It supports both application and library builds with extensive customization options.

3

4

## Capabilities

5

6

### Build Function

7

8

Execute a production build with comprehensive optimization and bundling.

9

10

```typescript { .api }

11

/**

12

* Execute production build

13

* @param config - Inline configuration options

14

* @returns Promise resolving to Rollup output(s) or watcher

15

*/

16

function build(config?: InlineConfig): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;

17

```

18

19

**Usage Examples:**

20

21

```typescript

22

import { build } from "vite";

23

24

// Basic build

25

const output = await build({

26

build: {

27

outDir: 'dist',

28

sourcemap: true,

29

minify: 'terser'

30

}

31

});

32

33

// Library build

34

await build({

35

build: {

36

lib: {

37

entry: './src/index.ts',

38

name: 'MyLib',

39

formats: ['es', 'cjs', 'umd']

40

},

41

rollupOptions: {

42

external: ['vue', 'react'],

43

output: {

44

globals: {

45

vue: 'Vue',

46

react: 'React'

47

}

48

}

49

}

50

}

51

});

52

```

53

54

### Create Builder

55

56

Create a reusable builder instance for multiple builds.

57

58

```typescript { .api }

59

/**

60

* Create a reusable builder instance

61

* @param config - Inline configuration options

62

* @returns Promise resolving to ViteBuilder instance

63

*/

64

function createBuilder(config?: InlineConfig): Promise<ViteBuilder>;

65

66

interface ViteBuilder {

67

/** Execute build with optional builder-specific options */

68

build(builderOptions?: BuilderOptions): Promise<RollupOutput | RollupOutput[]>;

69

/** Close builder and cleanup resources */

70

close(): Promise<void>;

71

}

72

```

73

74

### Build Options

75

76

Configure build behavior, output format, and optimization settings.

77

78

```typescript { .api }

79

interface BuildOptions {

80

/** Build target environment */

81

target?: 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext' | string[];

82

/** Build polyfills */

83

polyfillModulePreload?: boolean;

84

/** Output directory */

85

outDir?: string;

86

/** Assets directory */

87

assetsDir?: string;

88

/** Assets inline threshold */

89

assetsInlineLimit?: number;

90

/** CSS code splitting */

91

cssCodeSplit?: boolean;

92

/** CSS target */

93

cssTarget?: string | string[];

94

/** CSS minify options */

95

cssMinify?: boolean | 'esbuild' | 'lightningcss';

96

/** Generate sourcemaps */

97

sourcemap?: boolean | 'inline' | 'hidden';

98

/** Rollup options */

99

rollupOptions?: RollupOptions;

100

/** Library build options */

101

lib?: LibraryOptions;

102

/** Manifest generation */

103

manifest?: boolean | string;

104

/** SSR manifest */

105

ssrManifest?: boolean | string;

106

/** SSR emit assets */

107

ssrEmitAssets?: boolean;

108

/** Minification */

109

minify?: boolean | 'terser' | 'esbuild';

110

/** Terser options */

111

terserOptions?: TerserOptions;

112

/** Write bundle to disk */

113

write?: boolean;

114

/** Empty output directory */

115

emptyOutDir?: boolean | null;

116

/** Report compressed size */

117

reportCompressedSize?: boolean;

118

/** Chunk size warning limit */

119

chunkSizeWarningLimit?: number;

120

/** Watch mode */

121

watch?: RollupWatchOptions | null;

122

/** Module preload options */

123

modulePreload?: ModulePreloadOptions;

124

/** Copy public directory */

125

copyPublicDir?: boolean;

126

}

127

128

interface ResolvedBuildOptions extends Required<Omit<BuildOptions, 'rollupOptions' | 'lib'>> {

129

rollupOptions: RollupOptions;

130

lib: LibraryOptions | false;

131

}

132

```

133

134

### Library Build

135

136

Build libraries with multiple output formats and customization options.

137

138

```typescript { .api }

139

interface LibraryOptions {

140

/** Entry point */

141

entry: string | string[] | Record<string, string>;

142

/** Library name for UMD builds */

143

name?: string;

144

/** Output formats */

145

formats?: LibraryFormats[];

146

/** Custom file names */

147

fileName?: string | ((format: LibraryFormats, entryName: string) => string);

148

}

149

150

type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife' | 'system';

151

```

152

153

### Module Preload

154

155

Configure module preloading for optimal loading performance.

156

157

```typescript { .api }

158

interface ModulePreloadOptions {

159

/** Resolve module preload dependencies */

160

resolveDependencies?: ResolveModulePreloadDependenciesFn;

161

/** Module preload polyfill */

162

polyfill?: boolean;

163

}

164

165

interface ResolvedModulePreloadOptions {

166

resolveDependencies: ResolveModulePreloadDependenciesFn;

167

polyfill: boolean;

168

}

169

170

/**

171

* Function to resolve module preload dependencies

172

* @param filename - Source filename

173

* @param deps - Array of dependency imports

174

* @param context - Preload context

175

* @returns Array of dependencies to preload

176

*/

177

type ResolveModulePreloadDependenciesFn = (

178

filename: string,

179

deps: string[],

180

context: {

181

importer: string;

182

}

183

) => string[];

184

```

185

186

### Asset URL Rendering

187

188

Customize how built asset URLs are rendered in the output.

189

190

```typescript { .api }

191

/**

192

* Function to render built asset URLs

193

* @param filename - Asset filename

194

* @param type - Asset type ('asset' | 'public')

195

* @param hostId - Host module ID

196

* @param hostType - Host type ('js' | 'css' | 'html')

197

* @returns Rendered asset URL

198

*/

199

type RenderBuiltAssetUrl = (

200

filename: string,

201

type: 'asset' | 'public',

202

hostId: string,

203

hostType: 'js' | 'css' | 'html'

204

) => string | { relative?: boolean; runtime?: string } | undefined;

205

```

206

207

### Build Environment

208

209

Environment-specific build configuration and execution.

210

211

```typescript { .api }

212

interface BuildEnvironmentOptions {

213

/** Output directory for this environment */

214

outDir?: string;

215

/** Asset handling */

216

assetsInclude?: string | RegExp | (string | RegExp)[];

217

/** Copy public dir */

218

copyPublicDir?: boolean;

219

/** Environment-specific Rollup options */

220

rollupOptions?: RollupOptions;

221

}

222

223

interface ResolvedBuildEnvironmentOptions extends Required<BuildEnvironmentOptions> {

224

/** Resolved Rollup options */

225

rollupOptions: RollupOptions;

226

}

227

228

class BuildEnvironment {

229

/** Environment name */

230

name: string;

231

/** Build configuration */

232

config: ResolvedConfig;

233

/** Execute build for this environment */

234

build(): Promise<RollupOutput>;

235

}

236

```

237

238

### Builder Options

239

240

Options for builder instances and build execution.

241

242

```typescript { .api }

243

interface BuilderOptions {

244

/** Force rebuild */

245

force?: boolean;

246

/** Inline config overrides */

247

inlineConfig?: InlineConfig;

248

}

249

250

type BuildAppHook = (

251

name: string

252

) => {

253

buildApp: (builder: ViteBuilder) => Promise<void>;

254

} | Promise<{

255

buildApp: (builder: ViteBuilder) => Promise<void>;

256

}>;

257

```

258

259

## Build Types

260

261

```typescript { .api }

262

type RollupOutput = rollup.RollupOutput;

263

type RollupOptions = rollup.RollupOptions;

264

type RollupWatchOptions = rollup.RollupWatchOptions;

265

type RollupWatcher = rollup.RollupWatcher;

266

267

interface Manifest {

268

[file: string]: ManifestChunk;

269

}

270

271

interface ManifestChunk {

272

file: string;

273

name?: string;

274

src?: string;

275

isEntry?: boolean;

276

isDynamicEntry?: boolean;

277

imports?: string[];

278

dynamicImports?: string[];

279

css?: string[];

280

assets?: string[];

281

}

282

```