forked from vbenjs/vue-vben-admin
-
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.
Merge branch 'main' into gavin/v4-dev-customrouter
* main: (48 commits) fix(LockModal): Cannot unlock (vbenjs#3143) Pr/code editor boardered (vbenjs#3142) chore: fix type:check error (vbenjs#3139) fix(customExport): Failure to export (vbenjs#3137) fix(full-screen): dom fullscreen status text (vbenjs#3130) fix(BasicForm): type instantiation is excessively deep and possibly infinite. (vbenjs#3128) chore: fix type:check error (vbenjs#3126) fix: #2744tabs选项卡渲染问题,以及完善路由中affix=true时处理逻辑。 (vbenjs#3127) chore: update `unplugin-config` (vbenjs#3120) chore(demo): 修正表单增删示例类型错误 fix(demo): useForm中DatePicker,RangePicker 日期控件位置不对 fix(Editor): ts类型错误 chore(MenuItem): watch回调参数类型不一致 fix(SimpleMenuTag): SimpleMenuTag的引用都改为动态组件引用,以消除打包警告.close vbenjs#3121 chore(demo): 消除ts类型错误 fix: ScrollContainer的一个问题 vbenjs#3046 (vbenjs#3119) fix(StrengthMeter): change事件应随handleChange一起抛出。close vbenjs#3118 Revert "chore: update `unplugin-config` (vbenjs#3116)" (vbenjs#3117) chore: update `unplugin-config` (vbenjs#3116) fix(EditCellTable): 表格编辑行在使用Switch,checkedValue为数字时无法切换开关.close vbenjs#2560 ... # Conflicts: # pnpm-lock.yaml # src/components/Form/src/BasicForm.vue # src/components/Form/src/components/ApiSelect.vue # src/components/Form/src/hooks/useForm.ts # src/layouts/default/header/MultipleHeader.vue # src/views/demo/form/UseForm.vue
- Loading branch information
Showing
97 changed files
with
2,289 additions
and
6,231 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 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 |
---|---|---|
@@ -1,104 +1,31 @@ | ||
import colors from 'picocolors'; | ||
import { readPackageJSON } from 'pkg-types'; | ||
import GenerateConfig from 'unplugin-config/vite'; | ||
import { type PluginOption } from 'vite'; | ||
|
||
import { getEnvConfig } from '../utils/env'; | ||
import { createContentHash } from '../utils/hash'; | ||
import { strToHex } from '../utils/hash'; | ||
|
||
const GLOBAL_CONFIG_FILE_NAME = '_app.config.js'; | ||
const PLUGIN_NAME = 'app-config'; | ||
|
||
async function createAppConfigPlugin({ | ||
root, | ||
isBuild, | ||
}: { | ||
root: string; | ||
isBuild: boolean; | ||
}): Promise<PluginOption> { | ||
let publicPath: string; | ||
let source: string; | ||
if (!isBuild) { | ||
return { | ||
name: PLUGIN_NAME, | ||
}; | ||
} | ||
const { version = '' } = await readPackageJSON(root); | ||
|
||
return { | ||
name: PLUGIN_NAME, | ||
async configResolved(_config) { | ||
const appTitle = _config?.env?.VITE_GLOB_APP_TITLE ?? ''; | ||
// appTitle = appTitle.replace(/\s/g, '_').replace(/-/g, '_'); | ||
publicPath = _config.base; | ||
source = await getConfigSource(appTitle); | ||
// This constant sets the output directory for the Vite package | ||
const OUTPUT_DIR = 'dist'; | ||
export async function createConfigPluginConfig( | ||
shouldGenerateConfig: boolean, | ||
): Promise<PluginOption> { | ||
const config = await getEnvConfig(); | ||
// LINK /src/utils/env.ts -> getVariableName | ||
const APP_NAME = strToHex(config?.VITE_GLOB_APP_TITLE ?? '__APP'); | ||
// https://github.com/kirklin/unplugin-config | ||
return GenerateConfig({ | ||
appName: APP_NAME, | ||
envVariables: { | ||
prefix: 'VITE_GLOB_', | ||
}, | ||
async transformIndexHtml(html) { | ||
publicPath = publicPath.endsWith('/') ? publicPath : `${publicPath}/`; | ||
|
||
const appConfigSrc = `${ | ||
publicPath || '/' | ||
}${GLOBAL_CONFIG_FILE_NAME}?v=${version}-${createContentHash(source)}`; | ||
|
||
return { | ||
html, | ||
tags: [ | ||
{ | ||
tag: 'script', | ||
attrs: { | ||
src: appConfigSrc, | ||
}, | ||
}, | ||
], | ||
}; | ||
configFile: { | ||
generate: shouldGenerateConfig, | ||
fileName: GLOBAL_CONFIG_FILE_NAME, | ||
outputDir: OUTPUT_DIR, | ||
}, | ||
async generateBundle() { | ||
try { | ||
this.emitFile({ | ||
type: 'asset', | ||
fileName: GLOBAL_CONFIG_FILE_NAME, | ||
source, | ||
}); | ||
|
||
console.log(colors.cyan(`✨configuration file is build successfully!`)); | ||
} catch (error) { | ||
console.log( | ||
colors.red('configuration file configuration file failed to package:\n' + error), | ||
); | ||
} | ||
htmlInjection: { | ||
decodeEntities: true, | ||
}, | ||
}; | ||
}); | ||
} | ||
|
||
/** | ||
* Get the configuration file variable name | ||
* @param env | ||
*/ | ||
const getVariableName = (title: string) => { | ||
function strToHex(str: string) { | ||
const result: string[] = []; | ||
for (let i = 0; i < str.length; ++i) { | ||
const hex = str.charCodeAt(i).toString(16); | ||
result.push(('000' + hex).slice(-4)); | ||
} | ||
return result.join('').toUpperCase(); | ||
} | ||
return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, ''); | ||
}; | ||
|
||
async function getConfigSource(appTitle: string) { | ||
const config = await getEnvConfig(); | ||
const variableName = getVariableName(appTitle); | ||
const windowVariable = `window.${variableName}`; | ||
// Ensure that the variable will not be modified | ||
let source = `${windowVariable}=${JSON.stringify(config)};`; | ||
source += ` | ||
Object.freeze(${windowVariable}); | ||
Object.defineProperty(window, "${variableName}", { | ||
configurable: false, | ||
writable: false, | ||
}); | ||
`.replace(/\s/g, ''); | ||
return source; | ||
} | ||
|
||
export { createAppConfigPlugin }; |
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
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
Oops, something went wrong.