3.1 KB96 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import react from '@vitejs/plugin-react';
9import fs from 'node:fs';
10import path, {resolve} from 'node:path';
11import {defineConfig} from 'vite';
12import styleX from 'vite-plugin-stylex';
13import viteTsconfigPaths from 'vite-tsconfig-paths';
14
15// Normalize `c:\foo\index.html` to `c:/foo/index.html`.
16// This affects Rollup's `facadeModuleId` (which expects the `c:/foo/bar` format),
17// and is important for Vite to replace the script tags in HTML files.
18// See https://github.com/vitejs/vite/blob/7440191715b07a50992fcf8c90d07600dffc375e/packages/vite/src/node/plugins/html.ts#L804
19// Without this, building on Windows might produce HTML entry points with
20// missing `<script>` tags, resulting in a blank page.
21function normalizeInputPath(inputPath: string) {
22 return process.platform === 'win32' ? resolve(inputPath).replace(/\\/g, '/') : inputPath;
23}
24
25// TODO: this could be a glob on src/platform/*.html
26const platforms = {
27 main: normalizeInputPath('index.html'),
28 androidStudio: normalizeInputPath('androidStudio.html'),
29 androidStudioRemote: normalizeInputPath('androidStudioRemote.html'),
30 webview: normalizeInputPath('webview.html'),
31 chromelikeApp: normalizeInputPath('chromelikeApp.html'),
32 visualStudio: normalizeInputPath('visualStudio.html'),
33 obsidian: normalizeInputPath('obsidian.html'),
34};
35
36export default defineConfig({
37 base: '',
38 plugins: [
39 react({
40 babel: {
41 plugins: [
42 [
43 'jotai/babel/plugin-debug-label',
44 {
45 customAtomNames: [
46 'atomFamilyWeak',
47 'atomLoadableWithRefresh',
48 'atomWithOnChange',
49 'atomWithRefresh',
50 'atomLoadableWithRefresh',
51 'atomResetOnCwdChange',
52 'atomResetOnDepChange',
53 'configBackedAtom',
54 'jotaiAtom',
55 'lazyAtom',
56 'localStorageBackedAtom',
57 ],
58 },
59 ],
60 'jotai/babel/plugin-react-refresh',
61 ],
62 },
63 }),
64 styleX(),
65 viteTsconfigPaths(),
66 // The manifest vite generates doesn't include web worker js files.
67 // Just output a simple list of all files that are produced,
68 // and the server can serve those known files.
69 {
70 name: 'emit-file-list',
71 apply: 'build',
72 writeBundle(options: {dir: string | undefined}, bundle: Record<string, unknown>) {
73 const outputDir = options.dir || 'dist';
74 const fileList = Object.keys(bundle)
75 .filter(file => file !== '.vite/manifest.json')
76 .map(p => p.replace(/\\/g, '/'));
77 fs.writeFileSync(
78 path.join(outputDir, 'assetList.json'),
79 JSON.stringify(fileList, undefined, 2),
80 );
81 },
82 },
83 ],
84 build: {
85 outDir: 'build',
86 rollupOptions: {
87 input: platforms,
88 },
89 },
90 server: {
91 // No need to open the browser, it's opened by `yarn serve` in `isl-server`.
92 open: false,
93 port: 3000,
94 },
95});
96