-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
114 lines (104 loc) · 2.66 KB
/
build.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import vue from '@vitejs/plugin-vue';
import { execSync } from 'child_process';
import * as fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { build, defineConfig } from 'vite';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
/**
* @type {import('vite').UserConfig}
*/
const commonConfig = {
plugins : [
vue(),
],
resolve : {
alias : {
'@idevelopthings/vue-class-stores/vue' : path.resolve(__dirname, './src/Lib/index.ts'),
'@idevelopthings/vue-class-stores/dev-tools' : path.resolve(__dirname, './src/DevTools/index.ts'),
'@idevelopthings/vue-class-stores/vite' : path.resolve(__dirname, './src/VitePlugin/index.ts'),
},
},
build : {
sourcemap : true,
rollupOptions : {
external : [
'vue',
'klona',
"typescript",
"fs-jetpack",
'path',
'@vue/devtools-api',
'@vue/compat',
'@vue/compiler-dom',
'@vue/compiler-sfc',
'@vue/runtime-core',
],
output : {
},
},
},
};
const libConfigs = {
'DevTools' : {
outDir : 'dist/DevTools',
lib : {
name : 'VueClassStoresDevTools',
entry : './src/DevTools/index.ts',
fileName : 'index',
formats : ['es', 'cjs', 'umd', 'iife'],
},
},
'Lib' : {
outDir : 'dist/Lib',
lib : {
name : 'VueClassStoresLib',
entry : './src/Lib/index.ts',
fileName : 'index',
formats : ['es', 'cjs', 'umd', 'iife'],
},
},
'Common' : {
outDir : 'dist/Common',
lib : {
name : 'VueClassStoresCommon',
entry : './src/Common/index.ts',
fileName : 'index',
formats : ['es', 'cjs', 'umd', 'iife'],
},
},
};
function forLib(key)
{
const config = {...commonConfig};
if (config.plugins?.length) {
config.plugins = config.plugins.concat(libConfigs[key].plugins ?? []);
}
config.root = __dirname;
config.build.lib = libConfigs[key].lib;
config.build.outDir = libConfigs[key].outDir;
return {
...defineConfig(config),
configFile : false,
};
}
for (let lib in libConfigs) {
console.log('Building', lib);
await build(forLib(lib));
console.log('Done with', lib);
}
execSync(`yarn run tsc:types:lib`, {stdio : 'inherit'});
execSync(`yarn run tsc:types:vite-pkg`, {stdio : 'inherit'});
if (process.platform === 'win32') {
execSync(`copy ".\\src\\VitePlugin\\package.json" ".\\dist\\VitePlugin\\package.json"`, {stdio : 'inherit'});
} else {
execSync(`cp src/VitePlugin/package.json dist/VitePlugin/package.json`, {stdio : 'inherit'});
}
fs.writeFileSync('./dist/index.d.ts', `\n
export * from './Lib';
`,
);
fs.writeFileSync('./dist/index.js', `\n
export * from './Lib';
`,
);