-
Notifications
You must be signed in to change notification settings - Fork 40
/
vite.config.ts
104 lines (92 loc) · 2.58 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
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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react"; // BOLT-CEP_REACT-ONLY
import vue from "@vitejs/plugin-vue"; // BOLT-CEP_VUE-ONLY
import { svelte } from "@sveltejs/vite-plugin-svelte"; // BOLT-CEP_SVELTE-ONLY
import sveltePreprocess from "svelte-preprocess"; // BOLT-CEP_SVELTE-ONLY
import { cep, runAction } from "vite-cep-plugin";
import cepConfig from "./cep.config";
import path from "path";
import { extendscriptConfig } from "./vite.es.config";
const extensions = [".js", ".ts", ".tsx"];
const devDist = "dist";
const cepDist = "cep";
const src = path.resolve(__dirname, "src");
const root = path.resolve(src, "js");
const outDir = path.resolve(__dirname, "dist", "cep");
const debugReact = process.env.DEBUG_REACT === "true";
const isProduction = process.env.NODE_ENV === "production";
const isMetaPackage = process.env.ZIP_PACKAGE === "true";
const isPackage = process.env.ZXP_PACKAGE === "true" || isMetaPackage;
const isServe = process.env.SERVE_PANEL === "true";
const action = process.env.ACTION;
let input = {};
cepConfig.panels.map((panel) => {
input[panel.name] = path.resolve(root, panel.mainPath);
});
const config = {
cepConfig,
isProduction,
isPackage,
isMetaPackage,
isServe,
debugReact,
dir: `${__dirname}/${devDist}`,
cepDist: cepDist,
zxpDir: `${__dirname}/${devDist}/zxp`,
zipDir: `${__dirname}/${devDist}/zip`,
packages: cepConfig.installModules || [],
};
if (action) {
runAction(config, action);
process.exit();
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(), // BOLT-CEP_REACT-ONLY
vue(), // BOLT-CEP_VUE-ONLY
svelte({ preprocess: sveltePreprocess({ typescript: true }) }), // BOLT-CEP_SVELTE-ONLY
cep(config),
],
resolve: {
alias: [{ find: "@esTypes", replacement: path.resolve(__dirname, "src") }],
},
root,
clearScreen: false,
server: {
port: cepConfig.port,
},
preview: {
port: cepConfig.servePort,
},
build: {
sourcemap: isPackage ? cepConfig.zxp.sourceMap : cepConfig.build?.sourceMap,
watch: {
include: "src/jsx/**",
},
// commonjsOptions: {
// transformMixedEsModules: true,
// },
rollupOptions: {
input,
output: {
manualChunks: {},
// esModule: false,
preserveModules: false,
format: "cjs",
},
},
target: "chrome74",
outDir,
},
});
// rollup es3 build
const outPathExtendscript = path.join("dist", "cep", "jsx", "index.js");
extendscriptConfig(
`src/jsx/index.ts`,
outPathExtendscript,
cepConfig,
extensions,
isProduction,
isPackage
);