-
-
Notifications
You must be signed in to change notification settings - Fork 427
/
vite.config.dev.js
100 lines (95 loc) · 2.67 KB
/
vite.config.dev.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
96
97
98
99
100
import {defineConfig,build} from 'vite'
import * as fs from 'fs/promises';
import * as path from 'path';
import basicSsl from '@vitejs/plugin-basic-ssl'
const outDir = 'dist-dev'
const moduleConfig={
mode: 'development',
assetsInclude:'**/*.html',
base:'./',
plugins:[
basicSsl()
],
build: {
outDir: outDir,
emptyOutDir:false,
sourcemap:'inline' ,
lib: {
fileName:"[name]",
entry:'index.js',
formats:['es']
},
rollupOptions:{
external:(id)=>(id==='three'||id.includes('three/examples/jsm/')||id.includes('three/addons/')),
input:{
'mindar-image': './src/image-target/index.js',
'mindar-image-three': './src/image-target/three.js',
'mindar-face': './src/face-target/index.js',
'mindar-face-three': './src/face-target/three.js',
}
},
},
resolve:{
alias:{
'three/addons/':'three/examples/jsm/'
}
}
};
const faceAframeConfig=defineConfig({
mode: 'development',
build: {
outDir: outDir,
emptyOutDir:false,
sourcemap:'inline' ,
minify: false,
lib: {
name:"MINDAR",
fileName:"[name]",
entry:'index.js',
formats:['iife']
},
rollupOptions:{
input:{
'mindar-face-aframe': './src/face-target/aframe.js',
},
}
}
})
/** @type {import('vite').UserConfig} */
const imageAframeConfig=defineConfig({
mode: 'development',
build: {
outDir: outDir,
emptyOutDir:false,
sourcemap:'inline' ,
minify: false,
lib: {
name:"MINDAR",
fileName:"[name]",
entry:'index.js',
formats:['iife'],
},
rollupOptions:{
input:{
'mindar-image-aframe': './src/image-target/aframe.js'
}
}
}
})
export default defineConfig(async ({ command, mode }) => {
await fs.rm(outDir,{recursive:true,force:true});
if (command === 'build') {
await build(imageAframeConfig);
await build(faceAframeConfig);
const files=await fs.readdir(outDir);
//rename the aframe builds
await Promise.all(files.map(async (filename)=>{
if(filename.includes(".iife.js")){
const newName=filename.replace(".iife.js",".js");
console.log(filename,"->",newName)
await fs.rename(path.join(outDir,filename),path.join(outDir,newName));
}
}));
}
return moduleConfig
})