-
Notifications
You must be signed in to change notification settings - Fork 12
/
vite.config.ts
183 lines (159 loc) · 7.63 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright (c) 2024. Selldone® Business OS™
*
* Author: M.Pajuhaan
* Web: https://selldone.com
* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
*
* All rights reserved. In the weave of time, where traditions and innovations intermingle, this content was crafted.
* From the essence of thought, through the corridors of creativity, each word, and sentiment has been molded.
* Not just to exist, but to inspire. Like an artist's stroke or a sculptor's chisel, every nuance is deliberate.
* Our journey is not just about reaching a destination, but about creating a masterpiece.
* Tread carefully, for you're treading on dreams.
*/
import {defineConfig, loadEnv} from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import vitePluginRequire from "vite-plugin-require";
import basicSsl from "@vitejs/plugin-basic-ssl";
const manifest = require("./manifest.json");
//import vuetify from 'vite-plugin-vuetify'
/**
* Storefront layout version. This unique identifier is used for naming each app version published on Selldone.
* @type {string}
*/
const VERSION_DIR = manifest.version;
let IS_PRODUCTION: boolean;
let DEV_HOST: string;
let DEV_PORT: number;
let IS_HTTPS: boolean;
// ▃▃▃▃▃▃▃▃▃▃▃▃ Storefront Web App ▃▃▃▃▃▃▃▃▃▃▃▃
export default ({mode}: any) => {
const env = loadEnv(mode, process.cwd());
IS_PRODUCTION = mode === "production";
DEV_HOST = env.VITE_APP_DEV_SERVER_HOST || "localhost";
DEV_PORT = env.VITE_APP_DEV_SERVER_PORT
? parseInt(env.VITE_APP_DEV_SERVER_PORT)
: 8080;
IS_HTTPS =
!!env.VITE_APP_DEV_SERVER_HTTPS && env.VITE_APP_DEV_SERVER_HTTPS === "TRUE";
// Calculate base URL
const baseURL = IS_PRODUCTION
? fixPath(
`${manifest.deploy_server}/${manifest.deploy_path}/${manifest.package}/${manifest.version}`,
)
: `${IS_HTTPS ? "https" : "http"}://${DEV_HOST}:${DEV_PORT}/`;
console.log("Build base URL:", baseURL);
printDevServerConfig();
return defineConfig({
base: baseURL,
plugins: [
vue(),
// vuetify({ autoImport: true }), tree shaking problem in dynamic components in page builder (vSheet works but v-sheet not!)
//@ts-ignore
vitePluginRequire.default(),
...(IS_HTTPS
? [
basicSsl({name: "selldone-test-cert"}), // Enable if you want to use https
]
: []),
],
resolve: {
alias: {
// ━━━━━━━━━━━━ Define fix path for modules ━━━━━━━━━━━━
"@app-storefront": path.resolve(__dirname, ""),
"@app-vendor": path.resolve(__dirname, "src/Applications/Vendor/"),
'@selldone/core-js': path.resolve(__dirname, 'node_modules/@selldone/core-js'),
'@selldone/components-vue': path.resolve(__dirname, 'node_modules/@selldone/components-vue'),
'@selldone/page-builder': path.resolve(__dirname, 'node_modules/@selldone/page-builder'),
'@selldone/translate': path.resolve(__dirname, 'node_modules/@selldone/translate'),
'@selldone/sdk-storefront': path.resolve(__dirname, 'node_modules/@selldone/sdk-storefront'),
'@selldone/sdk-community': path.resolve(__dirname, 'node_modules/@selldone/sdk-community'),
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
},
},
server: {
// open: `${root}/index.html`,
origin: `http://${DEV_HOST}:${DEV_PORT}`, // Ensure this matches your Vite server
// Additional Vite server configuration...
host: "localhost",
port: DEV_PORT as number,
cors: true, // Enable CORS
fs: {
strict: false, // Load files from nested packages inside node-modules
// Allow all folders under the project root
allow: [
// Use path.resolve with an empty string to resolve to the project root directory
path.resolve(""),
],
},
},
build: {
outDir: "dist/",
rollupOptions: {
input: {
shop: "index.html",
},
output: {
// Entry and chunk naming patterns
entryFileNames: `${VERSION_DIR}/[name].js`,
chunkFileNames: `${VERSION_DIR}/js/[name].[hash].js`,
// For assets
assetFileNames: (assetInfo) => {
if (assetInfo!.name!.endsWith(".css")) {
return ["shop.css"].includes(assetInfo.name!)
? `${VERSION_DIR}/[name].[ext]`
: `${VERSION_DIR}/css/[name].[hash].[ext]`;
}
return `${VERSION_DIR}/assets/[name].[hash].[ext]`;
},
},
},
},
assetsInclude: ["**/*.m4v"],
});
};
function fixPath(str: string) {
return str.replace(/\/{2,}/g, "/");
}
function printDevServerConfig() {
console.log("");
console.log(
"███████╗███████╗██╗ ██╗ ██████╗ ██████╗ ███╗ ██╗███████╗",
);
console.log(
"██╔════╝██╔════╝██║ ██║ ██╔══██╗██╔═══██╗████╗ ██║██╔════╝",
);
console.log(
"███████╗█████╗ ██║ ██║ ██║ ██║██║ ██║██╔██╗ ██║█████╗ ",
);
console.log(
"╚════██║██╔══╝ ██║ ██║ ██║ ██║██║ ██║██║╚██╗██║██╔══╝ ",
);
console.log(
"███████║███████╗███████╗███████╗██████╔╝╚██████╔╝██║ ╚████║███████╗",
);
console.log(
"╚══════╝╚══════╝╚══════╝╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝",
);
console.log("");
console.log("▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆");
console.log("⬤ Vue Build Selldone® Business OS™ Storefront Project ⬤ ");
console.log("The #1 operating system for fast-growing companies.");
console.log("▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆");
console.log("");
const tableRow = (key: string, value: any) =>
`┃ ${key.padEnd(20)} ┃ ${value.toString().padEnd(20)} ┃`;
console.log("┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓");
console.log("┃ Configuration ┃ Value ┃");
console.log("┣━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━┫");
console.log(tableRow("ENVIRONMENT", process.env.NODE_ENV));
if (IS_PRODUCTION) {
} else {
console.log(tableRow("DEV_HOST", DEV_HOST));
console.log(tableRow("DEV_PORT", DEV_PORT));
console.log(tableRow("IS_HTTPS", IS_HTTPS));
}
console.log("┗━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━┛");
console.log("");
}