-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
674 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { resolve } from "node:path"; | ||
import { readPackageJSON } from "pkg-types"; | ||
import type { UserConfig } from "vite"; | ||
import { loadEnv } from "vite"; | ||
import { configVitePlugins } from "../plugins"; | ||
import { configureProxy, formatToDateTime, updateEnvVariables } from "../utils"; | ||
|
||
export async function createApplicationViteConfig(command, mode, cwd) { | ||
const root = cwd; | ||
const isProductionBuild = command === "build"; | ||
const env: Recordable<string> = loadEnv(mode, root); | ||
const defineData = await createDefineData(root); | ||
const viteEnv = updateEnvVariables(env); | ||
const { | ||
VITE_PORT, | ||
VITE_PROXY, | ||
VITE_USE_HTTPS, | ||
VITE_PUBLIC_PATH, | ||
VITE_DROP_CONSOLE, | ||
} = viteEnv; | ||
const plugins = configVitePlugins(root, viteEnv, isProductionBuild); | ||
const pathResolve = (pathname: string) => resolve(root, ".", pathname); | ||
|
||
const applicationConfig: UserConfig = { | ||
root, | ||
base: VITE_PUBLIC_PATH, | ||
|
||
resolve: { | ||
alias: { | ||
"vue-i18n": "vue-i18n/dist/vue-i18n.esm-bundler.js", | ||
"~/": `${pathResolve("src")}/`, | ||
}, | ||
}, | ||
server: { | ||
// Listening on all local IPs | ||
host: VITE_USE_HTTPS, | ||
port: VITE_PORT, | ||
open: true, | ||
https: false, | ||
proxy: !VITE_USE_HTTPS ? configureProxy(VITE_PROXY) : {}, | ||
}, | ||
esbuild: { | ||
pure: VITE_DROP_CONSOLE ? ["console.log", "debugger"] : [], | ||
}, | ||
define: defineData, | ||
build: { | ||
target: "es2015", | ||
minify: "terser", | ||
cssTarget: "chrome80", | ||
rollupOptions: { | ||
output: { | ||
chunkFileNames: "assets/js/[name]-[hash].js", | ||
entryFileNames: "assets/js/[name]-[hash].js", | ||
assetFileNames: "assets/[ext]/[name]-[hash].[ext]", | ||
manualChunks: { | ||
vue: ["vue", "pinia", "vue-router"], | ||
echarts: ["echarts", "vue-echarts"], | ||
celerisComponents: ["@celeris/components", "@celeris/ca-components"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
css: { | ||
preprocessorOptions: { | ||
scss: { | ||
additionalData: ` | ||
@import "~/styles/variables.scss"; | ||
`, | ||
javascriptEnabled: true, | ||
}, | ||
}, | ||
}, | ||
// https://github.com/vitest-dev/vitest | ||
test: { | ||
environment: "jsdom", | ||
}, | ||
plugins, | ||
}; | ||
return applicationConfig; | ||
} | ||
|
||
async function createDefineData(root: string) { | ||
try { | ||
const pkgJson = await readPackageJSON(root); | ||
const { dependencies, devDependencies, name, version } = pkgJson; | ||
|
||
const __APP_INFO__ = { | ||
pkg: { dependencies, devDependencies, name, version }, | ||
lastBuildTime: formatToDateTime(new Date()), | ||
}; | ||
return { | ||
__APP_INFO__: JSON.stringify(__APP_INFO__), | ||
}; | ||
} catch (error) { | ||
return {}; | ||
} | ||
} |
Oops, something went wrong.