-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
127 lines (122 loc) · 4.97 KB
/
vite.config.ts
File metadata and controls
127 lines (122 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import {defineConfig} from 'vite'
import path from "path"
import react, {reactCompilerPreset} from '@vitejs/plugin-react'
import babel from '@rolldown/plugin-babel'
import externalize from "vite-plugin-externalize-dependencies";
import wasm from "vite-plugin-wasm"
import {unifySrcJsUrlsPlugin} from './vite-plugins/unifySrcJsUrls'
// import noBundlePlugin from 'vite-plugin-no-bundle';
type RollupLogLike = {
code?: string
id?: string
loc?: {
file?: string
}
message: string
}
const isDashjsCommonjsVariableWarning = (log: RollupLogLike) => {
if (log.code !== 'COMMONJS_VARIABLE_IN_ESM') return false
return [log.id, log.loc?.file, log.message].some(value =>
value?.includes('node_modules/dashjs/dist/modern/esm/dash.all.min.js'),
)
}
// https://vite.dev/config/
export default defineConfig(({command}) => {
const isDev = command === 'serve';
const base = process.env.APP_BASE_PATH?.trim() || '/';
return ({
base,
plugins: [
react(),
babel({presets: [reactCompilerPreset()]}),
wasm(),
externalize({
externals: [
'react', // Externalize "react", and all of its subexports (react/*), such as react/jsx-runtime
'react-dom',
],
}),
{
name: 'only-main-entry',
/**
* Reason for this is that when we have preserveModules, Vite will for some reason will inject
* script tags for all the modules in the project.
* Which is probably not an issue generally, but if we externalize react and react-dom, this results in
* tags that point at /react and don't resolve via import maps.
*
* Keep the actual entry script regardless of whether the app is deployed at / or under a subpath.
* Vite may emit a small index.js entry wrapper which imports src/main.js.
*/
transformIndexHtml(html: string) {
return html.replace(/<script\s+type="module" crossorigin .*?src="([^"]*)".*?><\/script>\s*/g, (match, src) => {
return /(^|\/)(index|src\/main)\.js(?:$|[?#])/.test(src) ? match : '';
})
},
},
// See vite-plugins/unifySrcJsUrls.ts for the full rationale.
// Tests in vite-plugins/test/unifySrcJsUrls.test.ts.
isDev && unifySrcJsUrlsPlugin(),
].filter(Boolean),
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
// Resolve the kernel's import of the wire-protocol schemas
// to the agent-cli source. The schemas live in the
// publishable package; the kernel uses them at runtime
// (bridge.ts validates incoming JSON with
// knownAgentCommandSchema.safeParse) and at type time
// (commands.ts narrows on the discriminated union).
'@knowledge-medium/agent-cli/protocol': path.resolve(
__dirname,
'./packages/agent-cli/src/protocol.ts',
),
},
},
optimizeDeps: {
exclude: [
'@journeyapps/wa-sqlite',
'@powersync/common',
'@powersync/react',
'@powersync/web',
],
},
worker: {
format: 'es',
},
build: {
rollupOptions: {
onLog(level, log, defaultHandler) {
if (isDashjsCommonjsVariableWarning(log)) return
defaultHandler(level, log)
},
// // Mark react and react-dom as external to rely on the import map
external: [
'react',
'react/compiler-runtime',
'react/jsx-dev-runtime',
'react/jsx-runtime',
'react-dom',
'react-dom/client',
],
// input: '/src/main.tsx',
// input: {
// index: path.resolve(__dirname, 'index.html'),
// If you need to also specify your main file explicitly:
// main: path.resolve(__dirname, 'src/main.tsx'),
// },
output: {
preserveModules: true, // Preserves the module structure
preserveModulesRoot: process.cwd(),
// Set file naming without hashes.
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
assetFileNames: '[name][extname]',
},
preserveEntrySignatures: 'strict', // Preserves the signature of the entry point
},
sourcemap: true,
minify: false,
target: 'esnext',
},
})
})