-
Notifications
You must be signed in to change notification settings - Fork 177
/
vite.config.ts
74 lines (71 loc) · 1.72 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
import { type Plugin, mergeConfig } from 'vite'
import dts from 'vite-plugin-dts'
import base from './vite.preview.config'
import fs from 'node:fs'
import path from 'node:path'
const genStub: Plugin = {
name: 'gen-stub',
apply: 'build',
generateBundle() {
this.emitFile({
type: 'asset',
fileName: 'ssr-stub.js',
source: `module.exports = {}`,
})
},
}
/**
* Patch generated entries and import their corresponding CSS files.
* Also normalize MonacoEditor.css
*/
const patchCssFiles: Plugin = {
name: 'patch-css',
apply: 'build',
writeBundle() {
// inject css imports to the files
const outDir = path.resolve('dist')
;['vue-repl', 'monaco-editor', 'codemirror-editor'].forEach((file) => {
const filePath = path.resolve(outDir, file + '.js')
const content = fs.readFileSync(filePath, 'utf-8')
fs.writeFileSync(filePath, `import './${file}.css'\n${content}`)
})
},
}
export default mergeConfig(base, {
plugins: [
dts({
rollupTypes: true,
}),
genStub,
patchCssFiles,
],
optimizeDeps: {
// avoid late discovered deps
include: [
'typescript',
'monaco-editor-core/esm/vs/editor/editor.worker',
'vue/server-renderer',
],
},
base: './',
build: {
target: 'esnext',
minify: false,
lib: {
entry: {
'vue-repl': './src/index.ts',
'monaco-editor': './src/editor/MonacoEditor.vue',
'codemirror-editor': './src/editor/CodeMirrorEditor.vue',
},
formats: ['es'],
fileName: () => '[name].js',
},
cssCodeSplit: true,
rollupOptions: {
output: {
chunkFileNames: 'chunks/[name]-[hash].js',
},
external: ['vue', 'vue/compiler-sfc'],
},
},
})