Files
radicle-explorer/vite.config.ts
T
Sebastian Martinez 7be0a366b3 Update dependencies
Includes the move from the `svelte-preprocess` package for preprocessing
to `@sveltejs/vite-plugin-svelte` which allows us to use Vite also for
preprocessing.

Also had to remove the `vite-plugin-rewrite-all` again since they don't
support vite@4. So I wrote the plugin myself and without the dependecies
used by `vite-plugin-rewrite-all`.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2022-12-12 10:46:42 +01:00

89 lines
2.2 KiB
TypeScript

/// <reference types="vitest" />
import type { ViteDevServer } from "vite";
import path from "path";
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
function defineConstants() {
const constants = {
VITEST: process.env.VITEST !== undefined,
PLAYWRIGHT: process.env.PLAYWRIGHT_TEST_BASE_URL !== undefined,
};
// Don't overwrite HASH_ROUTING in Playwright tests, so we can control it
// from within the tests.
if (process.env.PLAYWRIGHT_TEST_BASE_URL !== undefined) {
return constants;
} else {
// eslint-disable-next-line @typescript-eslint/naming-convention
return { ...constants, HASH_ROUTING: Boolean(process.env.HASH_ROUTING) };
}
}
export default defineConfig({
optimizeDeps: {
exclude: ["@pedrouid/environment", "@pedrouid/iso-crypto"],
},
test: {
deps: {
inline: ["@ethersproject/signing-key", "@ethersproject/basex"],
},
setupFiles: "./tests/support/setupVitest",
environment: "happy-dom",
include: ["tests/unit/**/*.test.ts"],
reporters: "verbose",
},
plugins: [
svelte({
compilerOptions: {
dev: process.env.NODE_ENV !== "production",
},
}),
pluginRewriteAll(),
],
server: {
// We have to set host here, otherwise CI binds to the ipv6 address and
// e2e tests don't work.
host: "127.0.0.1",
port: 3000,
},
resolve: {
alias: {
"@public": path.resolve("./public"),
"@app": path.resolve("./src"),
},
},
build: {
outDir: "build",
rollupOptions: {
output: {
manualChunks: {
ethers: ["ethers", "@ethersproject/abstract-provider"],
auth: ["siwe", "@walletconnect/client"],
cache: ["lru-cache", "@stardazed/streams"],
markdown: ["katex", "dompurify", "marked", "@radicle/gray-matter"],
dom: ["svelte", "pure-svg-code", "twemoji"],
},
},
},
},
define: defineConstants(),
});
function pluginRewriteAll() {
return {
name: "rewrite-all",
configureServer(server: ViteDevServer) {
return () => {
server.middlewares.use((req, _res, next) => {
req.url = "/index.html";
next();
});
};
},
};
}