-
Notifications
You must be signed in to change notification settings - Fork 115
/
vite.config.ts
55 lines (53 loc) · 1.32 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import copy from 'rollup-plugin-copy'
import CleanCSS from 'clean-css'
import type { RollupOptions } from 'rollup'
export const rollupOptions: RollupOptions = {
external: ['pdfjs-dist', 'vue'],
output: {
globals: {
'pdfjs-dist': 'pdfjsLib',
vue: 'Vue',
},
compact: true,
inlineDynamicImports: true,
},
}
export default defineConfig({
plugins: [
copy({
hook: 'writeBundle',
targets: Object.entries({
textLayer: [
[2936, 2945],
[441, 568],
],
annotationLayer: [
[2936, 2945],
[569, 933],
],
}).map(([key, ranges]) => ({
src: 'node_modules/pdfjs-dist/web/pdf_viewer.css',
dest: 'dist/styles',
rename: `${key}.css`,
transform: (contents) => {
const lines = contents.toString().split('\n')
const css = ranges.reduce((acc, [start, end]) => {
return acc + lines.slice(start, end).join('\n')
}, '')
return new CleanCSS().minify(css).styles + '\n'
},
})),
}),
vue(),
],
build: {
lib: {
entry: new URL('./src/index.ts', import.meta.url).pathname,
name: 'VuePdfEmbed',
fileName: 'index',
},
rollupOptions,
},
})