fix pnpm build:ui (#116)

This commit is contained in:
acyza 2023-04-15 11:30:07 +08:00 committed by GitHub
parent 2293bde8b7
commit 3f0adf5dbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 28 deletions

View File

@ -3,4 +3,6 @@ runtime
dist-vue2/
dist-vue3/
node_modules
examples/docs/public/assets/map/js
examples/docs/public/assets/map/js
packages/dist2
packages/dist3

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ dist3/
allDist/
packages/**/runtime
coverage/
esbuild-kit/
/packages/vue-icon-saas/src
/packages/vue-icon-saas/index.ts

View File

@ -7,7 +7,8 @@ import dtsPlugin from 'vite-plugin-dts'
import vue3SvgPlugin from 'vite-svg-loader'
import { getAlias, pathFromWorkspaceRoot } from '../../config/vite.js'
import * as config from '../../shared/config.js'
import { getAllIcons, getAllModules, getByName, Module } from '../../shared/module-utils.js'
import type { Module } from '../../shared/module-utils.js'
import { getAllIcons, getAllModules, getByName } from '../../shared/module-utils.js'
import * as utils from '../../shared/utils.js'
import generatePackageJsonPlugin from './rollup/generate-package-json.js'
import inlineChunksPlugin from './rollup/inline-chunks.js'
@ -63,33 +64,33 @@ export const getBaseConfig = ({ vueVersion, dtsInclude, dts, buildTarget, themeV
...getVuePlugins(vueVersion),
dts
? dtsPlugin({
root: pathFromWorkspaceRoot(),
tsConfigFilePath: `tsconfig.vue${vueVersion}.json`,
aliasesExclude: [/@opentiny\/vue.+/],
compilerOptions: {
paths: {
...compilerOptions.paths,
// 一定要映射到 packages/vue 下对应的 vue 版本和 @vue/composition-api 才能正确生成 dts
'vue': [`packages/vue/node_modules/vue${vueVersion}`],
'@vue/runtime-core': ['packages/vue/node_modules/@vue/runtime-core'],
'@vue/runtime-dom': ['packages/vue/node_modules/@vue/runtime-dom'],
'@vue/composition-api': ['packages/vue/node_modules/@vue/composition-api']
}
},
include: [...dtsInclude, 'packages/vue/*.d.ts'],
// 忽略类型检查错误,保证生成不会阻断
skipDiagnostics: true,
beforeWriteFile: (filePath, content) => {
return {
// "vue/src/alert/index.d.ts" ==> "alert/index.d.ts"
filePath: filePath.replace('/vue/src', '').replace('\\vue\\src', ''),
content: content
// vue 2.7 还不能正常识别 vue-common
.replace(/import\('[./]+vue-common.+'\)/, 'import("vue")')
.replace(/\("vue[1-9\.]+/g, '("vue')
}
root: pathFromWorkspaceRoot(),
tsConfigFilePath: `tsconfig.vue${vueVersion}.json`,
aliasesExclude: [/@opentiny\/vue.+/],
compilerOptions: {
paths: {
...compilerOptions.paths,
// 一定要映射到 packages/vue 下对应的 vue 版本和 @vue/composition-api 才能正确生成 dts
'vue': [`packages/vue/node_modules/vue${vueVersion}`],
'@vue/runtime-core': ['packages/vue/node_modules/@vue/runtime-core'],
'@vue/runtime-dom': ['packages/vue/node_modules/@vue/runtime-dom'],
'@vue/composition-api': ['packages/vue/node_modules/@vue/composition-api']
}
})
},
include: [...dtsInclude, 'packages/vue/*.d.ts'],
// 忽略类型检查错误,保证生成不会阻断
skipDiagnostics: true,
beforeWriteFile: (filePath, content) => {
return {
// "vue/src/alert/index.d.ts" ==> "alert/index.d.ts"
filePath: filePath.replace('/vue/src', '').replace('\\vue\\src', ''),
content: content
// vue 2.7 还不能正常识别 vue-common
.replace(/import\('[./]+vue-common.+'\)/, 'import("vue")')
.replace(/\("vue[1-9\.]+/g, '("vue')
}
}
})
: undefined,
inlineChunksPlugin({ deleteInlinedFiles: true }),
generatePackageJsonPlugin({
@ -189,6 +190,9 @@ async function batchBuildAll({ vueVersion, tasks, formats, message, emptyOutDir,
if (tasks.length === 0) return
utils.logGreen(`====== 开始构建 ${message} ======`)
const entry = toEntry(tasks)
const entryPathSet = new Set(Object.values(entry))
const dtsInclude = toTsInclude(tasks)
await build({
configFile: false,
@ -208,6 +212,12 @@ async function batchBuildAll({ vueVersion, tasks, formats, message, emptyOutDir,
return false
}
// 模块作为入口时不需要通过external分离
const srcPath = path.resolve(importer, '..', source.split('?')[0])
if (entryPathSet.has(srcPath)) {
return false
}
// 图标入口排除子图标
if (/vue-icon\/(index|lowercase)/.test(importer)) {
return /^\.\//.test(source)