view vite.config.ts @ 144:379c4294dd0f

patch api
author drewp@bigasterisk.com
date Mon, 08 May 2023 13:31:40 -0700
parents 2ad4784c0d6c
children c26538ee1d1d
line wrap: on
line source

import { defineConfig, Plugin, UserConfigExport } from "vite";
import terser from "@rollup/plugin-terser";
import rollupResolve from "@rollup/plugin-node-resolve";
import rollupCommonjs from "@rollup/plugin-commonjs";

import rollupAlias from "@rollup/plugin-alias";
const config: UserConfigExport = {
  server: {
    host: "0.0.0.0",
    port: 8001,
    hmr: { port: 8002, path: "hmr", protocol: "ws" },
    fs: {
      allow: ["src", "node_modules", "."],
    },
  },
  build: {
    target: "esnext",
    lib: {
      entry: "src/index.ts",
      formats: ["es", "cjs", "iife"],
      name: "streamedgraph",
    },
    rollupOptions: {
      // external: /^lit/,
      plugins: [
        rollupResolve({
          browser: true,
          preferBuiltins: false,
        }),
        // rollupCommonjs(),
        // terser({
        //   mangle: false,
        //   compress: false,
        //   format: {
        //     semicolons: false,
        //   },
        // }),
        // rollupAlias({
        //   entries: [{ find: "promises", replacement: "__my_promises__" }],
        // }),
      ],
    },
    minify: false,
  },
  // resolve: {
  //   alias: [{ find: "rdf-canonize-native", replacement: "" }],
  // },
  define: {
    //   global: {},
  },
};

export default defineConfig(({ command, mode }) => {
  if (command === "serve") {
    (config.define as any)["process"] = { env: {} };
    return config;
  } else if (command === "build") {
    return config;
  } else {
    throw new Error(command);
  }
});