Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 4, 2024
1 parent 02c406e commit 518a435
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 158 deletions.
83 changes: 0 additions & 83 deletions craco.config.js

This file was deleted.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
"lint-staged": {
"src/**/*.{js,ts,jsx,tsx,json,css,scss,htm,html,md,mdx}": [
"prettier --write"
],
"vite.config.ts": [
"prettier --write"
],
"package.json": [
"prettier --write"
]
}
}
152 changes: 77 additions & 75 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { fileURLToPath, URL } from 'url';
import { fileURLToPath, URL } from "url";
import { resolve } from "path";
import { readFileSync, existsSync } from "node:fs";
import { defineConfig, loadEnv, Plugin, createFilter, transformWithEsbuild } from "vite";
import {
defineConfig,
loadEnv,
Plugin,
createFilter,
transformWithEsbuild,
} from "vite";
import react from "@vitejs/plugin-react";
import setupProxy from "./src/setupProxy";
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";
import environment from 'vite-plugin-environment';
import dotenv from 'dotenv';
import environment from "vite-plugin-environment";
import dotenv from "dotenv";

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
return {
build: {
outDir: "build",
emptyOutDir: true,
},
build: {
outDir: "build",
emptyOutDir: true,
},
plugins: [
react(),
environment("all", { prefix: "CANISTER_" }),
Expand All @@ -25,23 +31,23 @@ export default defineConfig(({ mode }) => {
devServerPlugin(),
sourcemapPlugin(),
svgrPlugin(),

setupProxyPlugin(),
],
worker: {
format: "es",
},
publicDir: 'public',
resolve: {
alias: [
{
find: "declarations",
replacement: fileURLToPath(
new URL("./src/declarations", import.meta.url)
),
},
],
},
worker: {
format: "es",
},
publicDir: "public",
resolve: {
alias: [
{
find: "declarations",
replacement: fileURLToPath(
new URL("./src/declarations", import.meta.url),
),
},
],
},
};
});

Expand All @@ -51,50 +57,48 @@ export default defineConfig(({ mode }) => {
// https://vitejs.dev/config/server-options.html#server-https
// https://vitejs.dev/config/server-options.html#server-port
function devServerPlugin(): Plugin {
return {
name: "dev-server-plugin",
config(_, { mode }) {
const { HOST, PORT, HTTPS, SSL_CRT_FILE, SSL_KEY_FILE } = loadEnv(
mode,
".",
["HOST", "PORT", "HTTPS", "SSL_CRT_FILE", "SSL_KEY_FILE"],
);
const https = HTTPS === "true";
return {
server: {
host: HOST || "0.0.0.0",
port: parseInt(PORT || "3000", 10),
open: true,
...(https &&
SSL_CRT_FILE &&
SSL_KEY_FILE && {
https: {
cert: readFileSync(resolve(SSL_CRT_FILE)),
key: readFileSync(resolve(SSL_KEY_FILE)),
},
}),
},
};
},
};
return {
name: "dev-server-plugin",
config(_, { mode }) {
const { HOST, PORT, HTTPS, SSL_CRT_FILE, SSL_KEY_FILE } = loadEnv(
mode,
".",
["HOST", "PORT", "HTTPS", "SSL_CRT_FILE", "SSL_KEY_FILE"],
);
const https = HTTPS === "true";
return {
server: {
host: HOST || "0.0.0.0",
port: parseInt(PORT || "3000", 10),
open: true,
...(https &&
SSL_CRT_FILE &&
SSL_KEY_FILE && {
https: {
cert: readFileSync(resolve(SSL_CRT_FILE)),
key: readFileSync(resolve(SSL_KEY_FILE)),
},
}),
},
};
},
};
}

// Migration guide: Follow the guide below
// https://vitejs.dev/config/build-options.html#build-sourcemap
function sourcemapPlugin(): Plugin {
return {
name: "sourcemap-plugin",
config(_, { mode }) {
const { GENERATE_SOURCEMAP } = loadEnv(mode, ".", [
"GENERATE_SOURCEMAP",
]);
return {
build: {
sourcemap: GENERATE_SOURCEMAP === "true",
},
};
},
};
return {
name: "sourcemap-plugin",
config(_, { mode }) {
const { GENERATE_SOURCEMAP } = loadEnv(mode, ".", ["GENERATE_SOURCEMAP"]);
return {
build: {
sourcemap: GENERATE_SOURCEMAP === "true",
},
};
},
};
}

// In Create React App, SVGs can be imported directly as React components. This is achieved by svgr libraries.
Expand Down Expand Up @@ -134,23 +138,21 @@ function svgrPlugin(): Plugin {
};
}


// Configuring the Proxy Manually
// https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually
// https://vitejs.dev/guide/api-plugin.html#configureserver
// Migration guide: Follow the guide below and remove src/setupProxy
// https://vitejs.dev/config/server-options.html#server-proxy
function setupProxyPlugin(): Plugin {
return {
name: "setup-proxy-plugin",
config() {
return {
server: { proxy: {} },
};
},
configureServer(server) {
setupProxy(server.middlewares);
},
};
return {
name: "setup-proxy-plugin",
config() {
return {
server: { proxy: {} },
};
},
configureServer(server) {
setupProxy(server.middlewares);
},
};
}

0 comments on commit 518a435

Please sign in to comment.