generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
101 lines (94 loc) · 2.88 KB
/
vite.config.ts
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
import { existsSync } from 'node:fs'
import { copyFile, rename, writeFile } from 'node:fs/promises'
import { builtinModules } from 'node:module'
import { join, resolve } from 'node:path'
import process from 'node:process'
import { univerPlugin } from '@univerjs/vite-plugin'
import dotenv from 'dotenv'
import { defineConfig } from 'vite'
import pkg from './package.json'
dotenv.config()
let buildDir = process.env.DIST_DIR ?? 'dist'
function generate(isDev?: boolean) {
if (!isDev)
buildDir = 'dist'
return {
name: 'obsidian',
async writeBundle() {
await writeFile(resolve(buildDir, 'manifest.json'), `${JSON.stringify({
id: pkg.name,
name: 'Univer',
version: pkg.version,
minAppVersion: '1.5.11',
description: pkg.description,
author: pkg.author,
authorUrl: 'https://github.com/dream-num',
fundingUrl: 'https://opencollective.com/univer',
isDesktopOnly: true,
}, null, 2)}\n`)
await copyFile(resolve(buildDir, 'manifest.json'), join(process.cwd(), 'manifest.json'))
rename(resolve(buildDir, 'style.css'), resolve(buildDir, 'styles.css'))
// eslint-disable-next-line no-console
console.log('build!')
},
}
}
const exchangeWasm = resolve(__dirname, './node_modules/@univerjs-pro/exchange-wasm/package.json')
if (!existsSync(exchangeWasm)) {
// eslint-disable-next-line no-console
console.log('exchange-wasm not found, using mock exchange-wasm')
}
export default defineConfig((_) => {
const dev = process.argv.includes('--watch')
return {
plugins: [
generate(dev),
univerPlugin(),
],
resolve: {
alias: {
'@': resolve(__dirname, './src'),
'@univerjs-pro/exchange-wasm': existsSync(exchangeWasm) ? resolve(__dirname, './node_modules/@univerjs-pro/exchange-wasm') : resolve(__dirname, './src/mock'),
},
},
build: {
outDir: buildDir,
lib: {
entry: './src/main.ts',
name: 'main',
fileName: () => 'main.js',
formats: [
'cjs',
],
},
emptyOutDir: true,
sourcemap: dev ? 'inline' : false,
target: 'es2018',
rollupOptions: {
output: {
dynamicImportInCjs: false,
inlineDynamicImports: true,
globals: {
obsidian: 'obsidian',
},
},
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtinModules,
],
},
},
}
})