-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
97 lines (84 loc) · 2.42 KB
/
vite.config.js
File metadata and controls
97 lines (84 loc) · 2.42 KB
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
import { readFileSync } from "fs";
import yaml from "js-yaml";
import { resolve } from "path";
import { defineConfig } from "vite";
// Read version from package.yml (single source of truth)
function getVersionFromPackageYml() {
try {
const packageYmlPath = resolve(__dirname, "package.yml");
const packageYmlContent = readFileSync(packageYmlPath, "utf8");
const packageData = yaml.load(packageYmlContent);
return packageData.version || "1.0.0";
} catch (error) {
console.warn(
"Warning: Could not read version from package.yml:",
error.message,
);
return "1.0.0";
}
}
const ADDON_VERSION = getVersionFromPackageYml();
console.log(`🏷️ Building Module Preview v${ADDON_VERSION}`);
export default defineConfig({
// Root directory for source files
root: "./assets-src",
// Base path for assets
base: "./",
// Build configuration
build: {
// Output directory relative to project root
outDir: "../assets",
// Empty output directory before building
emptyOutDir: true,
// Minify output
// minify: 'terser',
// Generate source maps for development
sourcemap: true,
// Rollup options
rollupOptions: {
input: {
// Main bundle (CSS + backend JS)
BlockPeekCSS: resolve(__dirname, "assets-src/BlockPeek.css"),
BlockPeek: resolve(__dirname, "assets-src/BlockPeek.js"),
BlockPeekPoster: resolve(__dirname, "assets-src/BlockPeekPoster.js"),
},
output: {
// Naming pattern for assets
assetFileNames: (assetInfo) => {
const info = assetInfo.name.split(".");
const ext = info[info.length - 1];
if (ext === "css") {
if (assetInfo.name === "BlockPeekCSS.css") {
return "BlockPeek.css";
}
return `[name].css`;
}
return `[name].[ext]`;
},
entryFileNames: "[name].js",
chunkFileNames: "[name]-[hash].js",
},
// External dependencies (don't bundle these)
external: (id) => {
// Don't bundle jQuery and Bootstrap as they're provided by REDAXO backend
return ["jquery", "bootstrap"].some((dep) => id.includes(dep));
},
},
// Target browsers (modern browsers for backend, wider support for client)
target: ["es2017", "chrome60", "firefox60", "safari11"],
},
// CSS preprocessing
css: {
postcss: "./postcss.config.js",
},
// Development server (if needed)
server: {
host: "localhost",
port: 3000,
open: false,
},
// Define global constants
define: {
__VERSION__: JSON.stringify(ADDON_VERSION),
},
});