diff --git a/tsconfig.json b/tsconfig.json index c5a50185..06785d89 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -35,7 +35,7 @@ "include": [ "vite.config.ts", "vite-helper/index.ts", - "vite-helper/type.ts", + "vite-helper/types.ts", "vite.custom.config.ts", "package.json", "vite-env.d.ts", diff --git a/vite-helper/index.ts b/vite-helper/index.ts index 36220f2b..187ca63e 100644 --- a/vite-helper/index.ts +++ b/vite-helper/index.ts @@ -1,8 +1,5 @@ -import pkg from '../package.json' import { defineResolve } from 'vite-plugin-cdn2/resolve' -import type { DependenciesKey } from './type' - /** * * @param title 浏览器 title 名称 @@ -40,32 +37,6 @@ export const mixinCSSPlugin = (options?: string[]) => { return mixinString as string } -/** - * - * @param dependenciesKey 依赖包名称 - * - * @returns 依赖包版本号 - * - * @description - * 获取 package.json 文件中的依赖包版本号,如果不存在则抛出异常。 - * - * @example - * const vueVersion = getDependenciesVersion('vue') // vue version - * const unknownVersion = getDependenciesVersion('unknown package') // Error - */ -export const getDependenciesVersion = (dependenciesKey: DependenciesKey) => { - const { dependencies } = pkg - const result = dependencies[dependenciesKey] - - if (!result) { - throw Error( - `[getDependenciesVersion]: The ${dependenciesKey} does not exist in the package.json file!`, - ) - } - - return result.replace(/^[^\w\s]+/, '') -} - export const cdnResolve = defineResolve({ name: 'RayTemplateCdnResolve', setup({ extra }) { diff --git a/vite-helper/type.ts b/vite-helper/types.ts similarity index 96% rename from vite-helper/type.ts rename to vite-helper/types.ts index ffcec487..1c0d243c 100644 --- a/vite-helper/type.ts +++ b/vite-helper/types.ts @@ -1,5 +1,3 @@ -import type pkg from '../package.json' - export interface VitePluginCompression { /** * @@ -129,5 +127,3 @@ export interface ImpConfig { */ transpileDependencies?: boolean | Array } - -export type DependenciesKey = keyof (typeof pkg)['dependencies'] diff --git a/vite.plugin.config.ts b/vite.plugin.config.ts index 226d93f5..5b53024d 100644 --- a/vite.plugin.config.ts +++ b/vite.plugin.config.ts @@ -26,14 +26,13 @@ import mockDevServerPlugin from 'vite-plugin-mock-dev-server' import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' import unpluginViteComponents from 'unplugin-vue-components/vite' import { cdn as viteCDNPlugin } from 'vite-plugin-cdn2' -import { getDependenciesVersion, cdnResolve } from './vite-helper' +import { cdnResolve } from './vite-helper' import { NaiveUiResolver } from 'unplugin-vue-components/resolvers' import config from './vite.custom.config' import type { PluginOption } from 'vite' -import type { DependenciesKey } from './vite-helper/type' // 仅适用于报告模式(report) function onlyReportOptions(mode: string): PluginOption[] { @@ -51,12 +50,6 @@ function onlyReportOptions(mode: string): PluginOption[] { // 仅适用于构建模式(任何构建模式:preview、build、report...) function onlyBuildOptions(mode: string): PluginOption[] { - const cdnBaseUrl = 'https://cdnjs.cloudflare.com/ajax/libs' - - const resolve = (dependenciesKey: DependenciesKey) => { - return `${cdnBaseUrl}/${dependenciesKey}/${getDependenciesVersion(dependenciesKey)}` - } - return [ viteCDNPlugin({ // modules 顺序 vue, vue-demi 必须保持当前顺序加载,否则会出现加载错误问题