feat: 移除getDependenciesVersion自定义方法

This commit is contained in:
XiaoDaiGua-Ray 2024-03-17 15:36:10 +08:00
parent 3bf297d81c
commit c21df42187
4 changed files with 2 additions and 42 deletions

View File

@ -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",

View File

@ -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 }) {

View File

@ -1,5 +1,3 @@
import type pkg from '../package.json'
export interface VitePluginCompression {
/**
*
@ -129,5 +127,3 @@ export interface ImpConfig {
*/
transpileDependencies?: boolean | Array<string | RegExp>
}
export type DependenciesKey = keyof (typeof pkg)['dependencies']

View File

@ -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 必须保持当前顺序加载,否则会出现加载错误问题