forked from technowledgy/vue-h5p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
95 lines (91 loc) · 2.01 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
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
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'path'
import { defineConfig } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2'
import copy from 'rollup-plugin-copy'
import del from 'rollup-plugin-delete'
const repoDir = dirname(fileURLToPath(import.meta.url))
const frameConfig = defineConfig({
build: {
target: 'es2015',
lib: {
entry: resolve(repoDir, 'src/frame.js'),
formats: ['cjs'],
fileName: 'script'
},
minify: false,
outDir: resolve(repoDir, 'frame')
},
plugins: [
{
generateBundle (opts, bundle) {
bundle['script.cjs'].code = bundle['script.cjs'].code.replaceAll('</script>', '<\\/script>')
}
},
copy({
targets: [
{ src: 'frame/style.css', dest: 'frame', rename: 'style' }
],
hook: 'writeBundle'
})
],
resolve: {
alias: [
{
find: /^h5p/,
replacement: resolve(repoDir, 'vendor/h5p')
}
]
}
})
const defaultConfig = defineConfig({
build: {
commonjsOptions: { include: [] },
emptyOutDir: true,
lib: {
entry: resolve(repoDir, 'src/index.js'),
formats: ['es', 'cjs']
},
minify: false,
outDir: resolve(repoDir, 'dist'),
rollupOptions: {
external: ['toposort-class'],
output: {
entryFileNames: '[format]/vue-h5p.js',
exports: 'named'
}
},
sourcemap: true
},
optimizeDeps: {
disabled: false
},
plugins: [
createVuePlugin(),
copy({
targets: [
{ src: 'package.json.cjs', dest: 'dist/cjs', rename: 'package.json' }
],
hook: 'writeBundle'
}),
del({
targets: ['dist/h5p'],
hook: 'writeBundle',
verbose: true
})
],
publicDir: resolve(repoDir, 'example/public'),
resolve: {
alias: [
{
find: /^@\//,
replacement: resolve(repoDir, 'src') + '/'
}
]
},
root: 'example'
})
export default ({ mode }) => {
if (mode === 'frame') return frameConfig
return defaultConfig
}