-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.js
42 lines (40 loc) · 1.11 KB
/
vite.config.js
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
import { resolve, join } from 'path'
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import fs from 'fs'
export default defineConfig({
plugins: [svelte(), rnCopyPlugin()],
resolve: {
alias: {
'@': resolve(__dirname, '/src')
}
},
build: {
//minify: false,
lib: {
entry: resolve(__dirname, 'src/index.ts'),
fileName: ()=>'highlight.js',
formats: ['cjs']
}
},
esbuild: {
legalComments: 'none',
// drop: ['console']
}
})
function rnCopyPlugin() {
return {
name: 'rn-copy-plugin',
generateBundle(options, bundle) {
for (const fileName in bundle) {
const file = bundle[fileName]
if (file.type != 'chunk' || !fileName.endsWith('.js')) continue
fs.writeFileSync(
join(options.dir, fileName.replace('.js', '.string.js')),
`export default ${JSON.stringify(file.code)}`,
'utf8'
)
}
}
}
}