Skip to content

Commit bb38bbf

Browse files
committed
perf: replace package info
1 parent cac1411 commit bb38bbf

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/build.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import isCore from 'is-core-module'
99
import type { Plugin, ResolvedConfig } from 'vite'
1010
import { createFilter } from '@rollup/pluginutils'
1111
import c from 'picocolors'
12-
import { name, version } from '../package.json'
1312
import { aliasMatches, transformWithEsbuild } from './compiler'
1413
import { viteDefine } from './define'
1514
import type { MockServerPluginOptions, ServerBuildOption } from './types'
1615
import { ensureProxies, lookupFile, normalizePath } from './utils'
1716

17+
declare const __PACKAGE_NAME__: string
18+
declare const __PACKAGE_VERSION__: string
19+
1820
type PluginContext<T = Plugin['buildEnd']> = T extends (
1921
this: infer R,
2022
...args: any[]
@@ -107,7 +109,7 @@ export async function generateMockServer(
107109

108110
function getMockDependencies(deps: Metafile['inputs'], alias: ResolvedConfig['resolve']['alias']): string[] {
109111
const list = new Set<string>()
110-
const excludeDeps = [name, 'connect', 'cors']
112+
const excludeDeps = [__PACKAGE_NAME__, 'connect', 'cors']
111113
const isAlias = (p: string) => alias.find(({ find }) => aliasMatches(find, p))
112114
Object.keys(deps).forEach((mPath) => {
113115
const imports = deps[mPath].imports
@@ -132,7 +134,7 @@ function generatePackageJson(pkg: any, mockDeps: string[]) {
132134
},
133135
dependencies: {
134136
'connect': '^3.7.0',
135-
'vite-plugin-mock-dev-server': `^${version}`,
137+
'vite-plugin-mock-dev-server': `^${__PACKAGE_VERSION__}`,
136138
'cors': '^2.8.5',
137139
} as Record<string, string>,
138140
pnpm: { peerDependencyRules: { ignoreMissing: ['vite'] } },

tsup.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from 'tsup'
2+
import { name, version } from './package.json'
23

34
export default defineConfig({
45
entry: ['src/index.ts'],
@@ -7,5 +8,9 @@ export default defineConfig({
78
dts: true,
89
splitting: false,
910
clean: true,
11+
define: {
12+
__PACKAGE_NAME__: JSON.stringify(name),
13+
__PACKAGE_VERSION__: JSON.stringify(version),
14+
},
1015
format: ['esm', 'cjs'],
1116
})

0 commit comments

Comments
 (0)