budibase/packages/builder/vite.config.mjs

152 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

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