-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvite.shared.config.js
More file actions
46 lines (41 loc) · 1.46 KB
/
vite.shared.config.js
File metadata and controls
46 lines (41 loc) · 1.46 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
import path from 'node:path';
import { readFileSync } from 'node:fs';
import { defineConfig } from 'vite';
import browserslistToEsbuild from 'browserslist-to-esbuild';
import { SHARED_RUNTIME_BUILD_CONFIGS } from './config/shared-runtime.js';
const rootDir = process.cwd();
const publicDir = path.resolve(rootDir, 'public');
const sharedRuntimeDir = path.resolve(publicDir, 'shared');
const packageJson = JSON.parse(readFileSync(path.resolve(rootDir, 'package.json'), 'utf8'));
const target = browserslistToEsbuild(packageJson.browserslist);
export default defineConfig(({ mode }) => {
const sharedRuntimeBuild = SHARED_RUNTIME_BUILD_CONFIGS[mode];
if (!sharedRuntimeBuild) {
throw new Error(`Unknown shared runtime build mode: ${ mode }`);
}
return {
publicDir: false,
build: {
target,
sourcemap: 'hidden',
emptyOutDir: false,
minify: 'esbuild',
outDir: sharedRuntimeDir,
lib: {
entry: path.resolve(rootDir, sharedRuntimeBuild.entry),
formats: ['es'],
fileName: () => sharedRuntimeBuild.fileName.replace(/\.js$/, ''),
},
rollupOptions: {
external: sharedRuntimeBuild.externalModules || [],
output: {
inlineDynamicImports: true,
paths: sharedRuntimeBuild.paths || {},
entryFileNames: sharedRuntimeBuild.fileName,
chunkFileNames: sharedRuntimeBuild.fileName,
assetFileNames: '[name][extname]',
},
},
},
};
});