forked from hrynko/vue-pdf-embed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
67 lines (65 loc) · 1.6 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
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',
},
assetFileNames: (assetInfo) => {
switch (assetInfo.name) {
case 'style.css':
return 'style/index.css'
default:
return assetInfo.name as string
}
},
compact: true,
inlineDynamicImports: true,
},
}
export default defineConfig({
plugins: [
copy({
hook: 'writeBundle',
targets: Object.entries({
textLayer: [
[1323, 1348],
[2543, 2553],
[231, 349],
[1362, 1373],
],
annotationLayer: [
[1323, 1348],
[2543, 2553],
[350, 712],
],
}).map(([key, ranges]) => ({
src: 'node_modules/pdfjs-dist/web/pdf_viewer.css',
dest: 'dist/style',
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',
},
minify: false,
rollupOptions,
},
})