2021-11-18 07:04:16 +13:00
|
|
|
import { svelte } from "@sveltejs/vite-plugin-svelte"
|
2021-04-01 04:14:56 +13:00
|
|
|
import replace from "@rollup/plugin-replace"
|
2022-08-16 21:26:23 +12:00
|
|
|
import { defineConfig, loadEnv } from "vite"
|
2023-06-15 01:54:27 +12:00
|
|
|
import { viteStaticCopy } from "vite-plugin-static-copy"
|
2021-04-01 04:14:56 +13:00
|
|
|
import path from "path"
|
|
|
|
|
2023-02-01 08:34:32 +13:00
|
|
|
const ignoredWarnings = [
|
|
|
|
"unused-export-let",
|
|
|
|
"css-unused-selector",
|
|
|
|
"module-script-reactive-declaration",
|
|
|
|
"a11y-no-onchange",
|
|
|
|
"a11y-click-events-have-key-events",
|
|
|
|
]
|
|
|
|
|
2023-06-17 01:46:34 +12:00
|
|
|
const copyFonts = dest =>
|
|
|
|
viteStaticCopy({
|
|
|
|
targets: [
|
|
|
|
{
|
|
|
|
src: "../../node_modules/@fontsource/source-sans-pro",
|
|
|
|
dest,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: "../../node_modules/remixicon/fonts/*",
|
|
|
|
dest,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
|
2022-08-16 21:26:23 +12:00
|
|
|
export default defineConfig(({ mode }) => {
|
2021-04-01 04:14:56 +13:00
|
|
|
const isProduction = mode === "production"
|
2022-08-16 21:26:23 +12:00
|
|
|
const env = loadEnv(mode, process.cwd())
|
2023-06-17 01:46:34 +12:00
|
|
|
|
|
|
|
// Plugins to only run in dev
|
|
|
|
const devOnlyPlugins = [
|
|
|
|
// Copy fonts to an additional path so that svelte's automatic
|
|
|
|
// prefixing of the base URL path can still resolve assets
|
|
|
|
copyFonts("builder/fonts"),
|
2024-09-07 01:53:26 +12:00
|
|
|
]
|
2023-06-17 01:46:34 +12:00
|
|
|
|
2021-04-01 04:14:56 +13:00
|
|
|
return {
|
2023-04-19 01:37:29 +12:00
|
|
|
test: {
|
|
|
|
setupFiles: ["./vitest.setup.js"],
|
|
|
|
globals: true,
|
|
|
|
environment: "jsdom",
|
|
|
|
},
|
2021-11-18 08:12:54 +13:00
|
|
|
server: {
|
|
|
|
fs: {
|
|
|
|
strict: false,
|
|
|
|
},
|
2022-08-16 21:26:23 +12:00
|
|
|
hmr: {
|
2022-08-17 20:21:36 +12:00
|
|
|
protocol: env.VITE_HMR_PROTOCOL || "ws",
|
2022-08-16 21:26:23 +12:00
|
|
|
clientPort: env.VITE_HMR_CLIENT_PORT || 3000,
|
2022-08-17 03:27:03 +12:00
|
|
|
path: env.VITE_HMR_PATH || "/",
|
|
|
|
},
|
2022-08-19 22:49:11 +12:00
|
|
|
port: 3000,
|
2021-11-18 08:12:54 +13:00
|
|
|
},
|
2021-05-07 19:17:21 +12:00
|
|
|
base: "/builder/",
|
2021-04-01 04:14:56 +13:00
|
|
|
build: {
|
|
|
|
minify: isProduction,
|
2021-04-01 07:58:30 +13:00
|
|
|
outDir: "../server/builder",
|
2022-02-15 22:23:51 +13:00
|
|
|
sourcemap: !isProduction,
|
2021-04-01 04:14:56 +13:00
|
|
|
},
|
|
|
|
plugins: [
|
2021-04-01 07:12:28 +13:00
|
|
|
svelte({
|
|
|
|
hot: !isProduction,
|
|
|
|
emitCss: true,
|
2023-02-01 08:34:32 +13:00
|
|
|
onwarn: (warning, handler) => {
|
|
|
|
// Ignore some warnings
|
|
|
|
if (!ignoredWarnings.includes(warning.code)) {
|
|
|
|
handler(warning)
|
|
|
|
}
|
|
|
|
},
|
2021-04-01 07:12:28 +13:00
|
|
|
}),
|
2021-04-01 04:14:56 +13:00
|
|
|
replace({
|
|
|
|
preventAssignment: true,
|
|
|
|
"process.env.NODE_ENV": JSON.stringify(
|
|
|
|
isProduction ? "production" : "development"
|
|
|
|
),
|
|
|
|
"process.env.POSTHOG_TOKEN": JSON.stringify(process.env.POSTHOG_TOKEN),
|
|
|
|
}),
|
2023-06-17 01:46:34 +12:00
|
|
|
copyFonts("fonts"),
|
2024-09-07 02:37:09 +12:00
|
|
|
...(isProduction ? [] : devOnlyPlugins),
|
2021-04-01 04:14:56 +13:00
|
|
|
],
|
|
|
|
optimizeDeps: {
|
2024-07-04 22:28:49 +12:00
|
|
|
exclude: ["@roxi/routify", "fsevents"],
|
2021-04-01 04:14:56 +13:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
dedupe: ["@roxi/routify"],
|
|
|
|
alias: [
|
2021-05-25 03:19:29 +12:00
|
|
|
{
|
|
|
|
find: "assets",
|
|
|
|
replacement: path.resolve("./assets"),
|
|
|
|
},
|
2021-04-01 04:14:56 +13:00
|
|
|
{
|
|
|
|
find: "components",
|
|
|
|
replacement: path.resolve("./src/components"),
|
|
|
|
},
|
2024-02-06 01:08:45 +13:00
|
|
|
{
|
|
|
|
find: "pages",
|
|
|
|
replacement: path.resolve("./src/pages"),
|
|
|
|
},
|
2021-04-01 04:14:56 +13:00
|
|
|
{
|
2024-02-01 22:55:30 +13:00
|
|
|
find: "templates",
|
|
|
|
replacement: path.resolve("./src/templates"),
|
2021-04-01 04:14:56 +13:00
|
|
|
},
|
2021-04-01 22:29:47 +13:00
|
|
|
{
|
|
|
|
find: "stores",
|
|
|
|
replacement: path.resolve("./src/stores"),
|
|
|
|
},
|
2024-02-06 00:59:54 +13:00
|
|
|
{
|
|
|
|
find: "dataBinding",
|
|
|
|
replacement: path.resolve("./src/dataBinding.js"),
|
|
|
|
},
|
2022-01-21 07:42:30 +13:00
|
|
|
{
|
|
|
|
find: "api",
|
2022-01-25 05:38:36 +13:00
|
|
|
replacement: path.resolve("./src/api.js"),
|
2022-01-21 07:42:30 +13:00
|
|
|
},
|
2021-04-01 04:14:56 +13:00
|
|
|
{
|
|
|
|
find: "constants",
|
|
|
|
replacement: path.resolve("./src/constants"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
find: "analytics",
|
|
|
|
replacement: path.resolve("./src/analytics"),
|
|
|
|
},
|
2021-05-07 00:58:42 +12:00
|
|
|
{
|
|
|
|
find: "actions",
|
|
|
|
replacement: path.resolve("./src/actions"),
|
|
|
|
},
|
2021-05-07 03:39:34 +12:00
|
|
|
{
|
|
|
|
find: "helpers",
|
|
|
|
replacement: path.resolve("./src/helpers"),
|
|
|
|
},
|
2023-08-09 20:40:54 +12:00
|
|
|
{
|
|
|
|
find: "@budibase/types",
|
|
|
|
replacement: path.resolve("../types/src"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
find: "@budibase/shared-core",
|
|
|
|
replacement: path.resolve("../shared-core/src"),
|
|
|
|
},
|
2023-10-28 10:38:11 +13:00
|
|
|
{
|
|
|
|
find: "@budibase/bbui",
|
|
|
|
replacement: path.resolve("../bbui/src"),
|
|
|
|
},
|
2021-04-01 04:14:56 +13:00
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
2022-08-16 21:26:23 +12:00
|
|
|
})
|