-
Notifications
You must be signed in to change notification settings - Fork 0
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
143 changed files
with
9,889 additions
and
9,812 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,86 @@ | ||
import { resolve } from "path"; | ||
import { | ||
type PluginOption, | ||
type UserConfig, | ||
searchForWorkspaceRoot, | ||
type PluginOption, | ||
type UserConfig, | ||
searchForWorkspaceRoot, | ||
} from "vite"; | ||
import tsconfigPaths from "vite-tsconfig-paths"; | ||
|
||
export interface AppConfig { | ||
enableBaseHref?: boolean; | ||
buildWithPlaceHolder?: boolean; | ||
enableBaseHref?: boolean; | ||
buildWithPlaceHolder?: boolean; | ||
} | ||
|
||
export const app = ( | ||
appName: string, | ||
appConfig: AppConfig = {}, | ||
appName: string, | ||
appConfig: AppConfig = {}, | ||
): PluginOption[] => { | ||
(process.env as any).APP_VERSION = "__VERSION__"; | ||
|
||
const viteConfigRoot = searchForWorkspaceRoot("."); | ||
|
||
let userConfig: UserConfig; | ||
|
||
return [ | ||
{ | ||
name: "vite-presets/app", | ||
config(c, { command }) { | ||
userConfig = c; | ||
|
||
c.base = appConfig.enableBaseHref | ||
? appConfig.buildWithPlaceHolder && command === "build" | ||
? "/__APP_BASE_HREF__/" | ||
: `/${appName}/` | ||
: "/"; | ||
|
||
c.publicDir = appConfig.enableBaseHref ? c.base : false; | ||
|
||
c.root = resolve(viteConfigRoot, `./webapp/${appName}`); | ||
|
||
c.build = c.build ?? {}; | ||
|
||
c.build.outDir = resolve(viteConfigRoot, `./public/${appName}`); | ||
c.build.emptyOutDir = true; | ||
|
||
c.build.rollupOptions = c.build.rollupOptions ?? {}; | ||
c.build.rollupOptions.external = c.build.rollupOptions.external ?? [ | ||
"csstype", | ||
]; | ||
|
||
c.build.assetsDir = c.build.assetsDir ?? "__built__"; | ||
|
||
// to avoid some filename starts with _ | ||
c.build.rollupOptions.output = { | ||
assetFileNames: `${c.build.assetsDir}/[name].[hash][extname]`, | ||
entryFileNames: `${c.build.assetsDir}/[name].[hash].entry.js`, | ||
chunkFileNames: `${c.build.assetsDir}/[name].[hash].chunk.js`, | ||
}; | ||
|
||
c.resolve = c.resolve ?? {}; | ||
c.resolve.alias = c.resolve.alias ?? ({} as Record<string, string>); | ||
|
||
c.esbuild = { | ||
jsxDev: c.mode !== "production", | ||
}; | ||
}, | ||
|
||
transformIndexHtml(html: string) { | ||
return { | ||
html: html, | ||
tags: [ | ||
{ | ||
tag: "base", | ||
attrs: { | ||
href: userConfig.base ?? "/", | ||
}, | ||
}, | ||
], | ||
}; | ||
}, | ||
}, | ||
tsconfigPaths({}) as PluginOption, | ||
]; | ||
(process.env as any).APP_VERSION = "__VERSION__"; | ||
|
||
const viteConfigRoot = searchForWorkspaceRoot("."); | ||
|
||
let userConfig: UserConfig; | ||
|
||
return [ | ||
{ | ||
name: "vite-presets/app", | ||
config(c, { command }) { | ||
userConfig = c; | ||
|
||
c.base = appConfig.enableBaseHref | ||
? appConfig.buildWithPlaceHolder && command === "build" | ||
? "/__APP_BASE_HREF__/" | ||
: `/${appName}/` | ||
: "/"; | ||
|
||
c.publicDir = appConfig.enableBaseHref ? c.base : false; | ||
|
||
c.root = resolve(viteConfigRoot, `./webapp/${appName}`); | ||
|
||
c.build = c.build ?? {}; | ||
|
||
c.build.outDir = resolve( | ||
viteConfigRoot, | ||
c.build.outDir ?? `./public/${appName}`, | ||
); | ||
c.build.emptyOutDir = true; | ||
|
||
c.build.rollupOptions = c.build.rollupOptions ?? {}; | ||
c.build.rollupOptions.external = c.build.rollupOptions.external ?? [ | ||
"csstype", | ||
]; | ||
|
||
c.build.assetsDir = c.build.assetsDir ?? "__built__"; | ||
|
||
// to avoid some filename starts with _ | ||
c.build.rollupOptions.output = { | ||
assetFileNames: `${c.build.assetsDir}/[name].[hash][extname]`, | ||
entryFileNames: `${c.build.assetsDir}/[name].[hash].entry.js`, | ||
chunkFileNames: `${c.build.assetsDir}/[name].[hash].chunk.js`, | ||
}; | ||
|
||
c.resolve = c.resolve ?? {}; | ||
c.resolve.alias = c.resolve.alias ?? ({} as Record<string, string>); | ||
|
||
c.esbuild = { | ||
jsxDev: c.mode !== "production", | ||
}; | ||
}, | ||
|
||
transformIndexHtml(html: string) { | ||
return { | ||
html: html, | ||
tags: [ | ||
{ | ||
tag: "base", | ||
attrs: { | ||
href: userConfig.base ?? "/", | ||
}, | ||
}, | ||
], | ||
}; | ||
}, | ||
}, | ||
tsconfigPaths({}) as PluginOption, | ||
]; | ||
}; |
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
Oops, something went wrong.