forked from radiantearth/stac-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
161 lines (150 loc) · 4.26 KB
/
Copy pathvite.config.js
File metadata and controls
161 lines (150 loc) · 4.26 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
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
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import path from "path";
import { readFileSync } from "fs";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";
import Components from "unplugin-vue-components/vite";
import { FileSystemIconLoader } from "unplugin-icons/loaders";
import { BootstrapVueNextResolver } from "bootstrap-vue-next/resolvers";
import { ViteEjsPlugin } from "vite-plugin-ejs";
import { visualizer } from "rollup-plugin-visualizer";
import yargs from "yargs";
// Read JSON files using fs instead of require
const configSchema = JSON.parse(
readFileSync(new URL("./config.schema.json", import.meta.url), "utf-8")
);
const package_ = JSON.parse(
readFileSync(new URL("./package.json", import.meta.url), "utf-8")
);
const optionsForType = (type) =>
Object.entries(configSchema.properties)
.filter(
([, schema]) => Array.isArray(schema.type) && schema.type.includes(type)
)
.map(([key]) => key);
const env = yargs()
.parserConfiguration({ "camel-case-expansion": false })
.env("SB")
.boolean(optionsForType("boolean"))
.number(optionsForType("number").concat(optionsForType("integer")))
.array(optionsForType("array"))
.option(
Object.fromEntries(
optionsForType("object").map((k) => [k, { coerce: JSON.parse }])
)
).argv;
delete env._;
delete env.$0;
// For config.js, you need to use dynamic import
const configFilePath = "file://" + path.resolve(env.CONFIG ? env.CONFIG : "./config.js");
// Note: This makes the config async - you'll need to handle this
let configFromFile;
try {
// Dynamic import for the config file
const configModule = await import(configFilePath);
configFromFile = configModule.default || configModule;
} catch (error) {
console.error(`Failed to load config from ${configFilePath}:`, error);
configFromFile = {};
}
const config = Object.assign(configFromFile, env);
export default defineConfig(({ mode }) => ({
base: config.pathPrefix,
build: {
sourcemap: mode !== "minimal",
rollupOptions: {
external: ["fs/promises"],
},
},
css: {
preprocessorOptions: {
scss: {
api: "modern-compiler",
// todo: remove in STAC Browser V6 or if resolved by bootstrap-vue-next.
silenceDeprecations: ["color-functions", "global-builtin", "import", "if-function"],
},
},
},
define: {
STAC_BROWSER_VERSION: JSON.stringify(package_.version),
CONFIG: JSON.stringify(config),
},
plugins: [
vue({
template: {
compilerOptions: {
// Preserve whitespace behavior from Vue 2
whitespace: "preserve",
},
},
}),
ViteEjsPlugin(config),
Components({
dirs: [],
globs: [],
resolvers: [
BootstrapVueNextResolver({
components: {
BContainer: true,
BRow: true,
BCol: true,
BAlert: true,
BButton: true,
BButtonGroup: true,
BBadge: true,
BForm: true,
BFormGroup: true,
BFormInput: true,
BFormSelect: true,
BFormCheckbox: true,
BFormRadio: true,
BFormRadioGroup: true,
BInputGroup: true,
BListGroup: true,
BListGroupItem: true,
BSpinner: true,
},
}), // Auto-register Bootstrap components
IconsResolver({
prefix: false,
enabledCollections: ["bi"],
alias: {
"b-icon": "bi",
},
customCollections: ["share"],
}),
],
}),
Icons({
compiler: "vue3",
customCollections: {
share: FileSystemIconLoader("./src/media/"),
},
}),
nodePolyfills({
include: ["buffer", "path", "process"],
globals: {
Buffer: true,
process: true,
},
}),
mode === "report" &&
visualizer({
filename: "./dist/report.html",
gzipSize: true,
brotliSize: true,
open: true,
}),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
server: {
port: 8080,
},
}));