mirror of
https://github.com/outline/outline.git
synced 2026-12-03 10:00:13 +03:00
94 lines
2.3 KiB
TypeScript
94 lines
2.3 KiB
TypeScript
import path from "path";
|
||
import react from "@vitejs/plugin-react";
|
||
import browserslistToEsbuild from "browserslist-to-esbuild";
|
||
import { webpackStats } from "rollup-plugin-webpack-stats";
|
||
import { defineConfig } from "vite";
|
||
import { viteStaticCopy } from "vite-plugin-static-copy";
|
||
import generateServiceWorker from "./vite/generateServiceWorker";
|
||
|
||
export default () => {
|
||
return defineConfig({
|
||
root: "./",
|
||
publicDir: "./server/static",
|
||
base: "/static/",
|
||
server: {
|
||
port: 3001,
|
||
host: true,
|
||
},
|
||
plugins: [
|
||
// https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme
|
||
react({
|
||
babel: {
|
||
parserOpts: {
|
||
plugins: ["decorators-legacy", "classProperties"],
|
||
},
|
||
},
|
||
}),
|
||
generateServiceWorker({
|
||
cdnUrl: process.env.CDN_URL || "/",
|
||
}),
|
||
viteStaticCopy({
|
||
targets: [
|
||
{
|
||
src: "./public/images",
|
||
dest: "./",
|
||
},
|
||
],
|
||
}),
|
||
],
|
||
optimizeDeps: {
|
||
esbuildOptions: {
|
||
keepNames: true,
|
||
define: {
|
||
global: "globalThis",
|
||
},
|
||
},
|
||
},
|
||
resolve: {
|
||
alias: {
|
||
"~": path.resolve(__dirname, "./app"),
|
||
"@shared": path.resolve(__dirname, "./shared"),
|
||
},
|
||
},
|
||
build: {
|
||
outDir: "./build/app",
|
||
manifest: true,
|
||
minify: "terser",
|
||
target: browserslistToEsbuild(),
|
||
reportCompressedSize: false,
|
||
terserOptions: {
|
||
keep_classnames: true,
|
||
keep_fnames: true,
|
||
},
|
||
rollupOptions: {
|
||
/**
|
||
* Regular assets can be hosted on a CDN.
|
||
* But the Service Worker code must not be hosted on a CDN.
|
||
* That’s why we need to separate the code:
|
||
*/
|
||
input: {
|
||
index: "./app/index.tsx",
|
||
sw: "./app/sw/sw.ts",
|
||
registerSW: "./app/sw/registerSW.ts",
|
||
},
|
||
output: [
|
||
{
|
||
entryFileNames: (chunkInfo) => {
|
||
const isServiceWorker = ["sw", "registerSW"].includes(
|
||
chunkInfo.name
|
||
);
|
||
|
||
if (chunkInfo.isEntry && isServiceWorker) {
|
||
return `sw/[name].js`;
|
||
}
|
||
|
||
return `[name]-[hash].js`;
|
||
},
|
||
},
|
||
],
|
||
plugins: [webpackStats()],
|
||
},
|
||
},
|
||
});
|
||
};
|