forked from hiukim/mind-ar-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.prod.js
93 lines (88 loc) · 2.53 KB
/
vite.config.prod.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
import {defineConfig,build} from 'vite'
import * as fs from 'fs/promises';
import * as path from 'path';
const outDir = 'dist'
/** @type {import('vite').UserConfig} */
const moduleConfig= defineConfig({
mode: 'production',
publicDir:false,
base:'./',
build: {
outDir:outDir,
emptyOutDir:false,
copyPublicDir:false,
lib: {
fileName:"[name].prod",
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: 'production',
build: {
outDir: outDir,
emptyOutDir:false,
lib: {
name:"MINDAR",
fileName:"[name].prod",
entry:'index.js',
formats:['iife']
},
rollupOptions:{
input:{
'mindar-face-aframe': './src/face-target/aframe.js',
},
}
}
})
/** @type {import('vite').UserConfig} */
const imageAframeConfig=defineConfig({
mode: 'production',
build: {
outDir: outDir,
emptyOutDir:false,
lib: {
name:"MINDAR",
fileName:"[name].prod",
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
})