-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathvite.config.js
More file actions
144 lines (140 loc) · 3.95 KB
/
Copy pathvite.config.js
File metadata and controls
144 lines (140 loc) · 3.95 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { defineConfig } from 'vite';
import preact from '@preact/preset-vite';
import legacy from '@vitejs/plugin-legacy';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
import { readFileSync } from 'fs';
const __dirname = dirname(fileURLToPath(import.meta.url));
function getCommitHash() {
try {
return execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
} catch (error) {
return 'unknown';
}
}
// @zenuml/core's package.json `exports` only exposes the root entry, so
// `import '@zenuml/core/dist/zenuml?url'` in src/utils.js is rejected by both
// node-style resolution and Vite's alias + dep-optimizer pipeline. This plugin
// intercepts that one specifier and resolves it to the bundle's URL.
//
// Dev (serve) and build must differ:
// - serve: return Vite's `/@fs/<abs>` URL — the dev server streams the file.
// - build: a `/@fs/<abs>` URL is dev-server-only and 404s once the build is
// served statically (Firebase Hosting), so the diagram never renders. We
// must emit the file as a real hashed asset and reference it by its built
// URL. Guarded by e2e/tests/production-build.spec.js.
let zenumlShimIsBuild = false;
const zenumlAssetUrlShim = {
name: 'zenuml-core-asset-url-shim',
enforce: 'pre',
configResolved(config) {
zenumlShimIsBuild = config.command === 'build';
},
resolveId(source) {
if (source === '@zenuml/core/dist/zenuml?url') {
return '\0zenuml-core-asset-url';
}
return null;
},
load(id) {
if (id === '\0zenuml-core-asset-url') {
const filePath = resolve(
__dirname,
'node_modules/@zenuml/core/dist/zenuml.js',
);
if (zenumlShimIsBuild) {
const referenceId = this.emitFile({
type: 'asset',
name: 'zenuml.js',
source: readFileSync(filePath),
});
return `export default import.meta.ROLLUP_FILE_URL_${referenceId};`;
}
return `export default ${JSON.stringify('/@fs' + filePath)};`;
}
return null;
},
};
export default defineConfig({
plugins: [
zenumlAssetUrlShim,
preact({
devToolsEnabled: true,
}),
legacy({
targets: ['defaults', 'not IE 11'],
}),
],
root: 'src',
publicDir: '../static',
build: {
outDir: '../dist',
emptyOutDir: true,
assetsDir: 'assets',
},
define: {
__COMMITHASH__: JSON.stringify(getCommitHash()),
},
resolve: {
alias: {
react: 'preact/compat',
'react-dom': 'preact/compat',
},
},
esbuild: {
loader: 'jsx',
include: [
// src
/src\/.*\.[jt]sx?$/,
// node_modules
/node_modules\/.*\.jsx$/,
],
},
optimizeDeps: {
esbuildOptions: {
loader: {
'.js': 'jsx',
},
},
},
css: {
postcss: './postcss.config.js',
},
server: {
host: true,
port: 3000,
proxy: {
'/create-share': {
target: 'http://127.0.0.1:5002',
changeOrigin: true,
rewrite: (path) => `/staging-zenuml-27954/us-central1/create_share`
},
'/get-shared-item': {
target: 'http://127.0.0.1:5002/staging-zenuml-27954/us-central1',
changeOrigin: true,
rewrite: (path) => path.replace('/get-shared-item', '/get_shared_item')
},
'/sync-diagram': {
target: 'http://127.0.0.1:5002',
changeOrigin: true,
rewrite: (path) => `/staging-zenuml-27954/us-central1/sync_diagram`
},
'/authenticate': {
target: 'http://127.0.0.1:5002',
changeOrigin: true,
rewrite: (path) => `/staging-zenuml-27954/us-central1/authenticate`
},
'/track': {
target: 'http://127.0.0.1:5002',
changeOrigin: true,
rewrite: (path) => `/staging-zenuml-27954/us-central1/track`
},
'/info': {
target: 'http://127.0.0.1:5002',
changeOrigin: true,
rewrite: (path) => `/staging-zenuml-27954/us-central1/info`
},
}
},
});