Skip to content

Commit

Permalink
refactor: 根据检视意见,将脚本函数的参数整改为对象,并把目录值迁移到参数默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
rhlin committed May 11, 2024
1 parent dc1ad0f commit 707a075
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 43 deletions.
6 changes: 3 additions & 3 deletions packages/design-core/scripts/localCdnFile/copyBundleDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export function replaceBundleCdnLink(bundle, fileMap) {
})
}

export function copyBundleDeps(
export function copyBundleDeps({
bundleFile,
targetBundleFile,
originCdnPrefix,
base,
dir,
dir = 'material-static',
bundleTempDir = 'bundle-deps/material-static'
) {
}) {
const cdnFiles = extraBundleCdnLink(bundleFile, originCdnPrefix).map((url) =>
getCdnPathNpmInfoForSingleFile(url, originCdnPrefix, base, dir, false, bundleTempDir)
)
Expand Down
24 changes: 12 additions & 12 deletions packages/design-core/scripts/localCdnFile/copyImportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import {
import { importmapPlugin } from '../externalDeps'
import { installPackageTemporary } from '../vite-plugins/installPackageTemporary'

export const copyLocalImportMap = (
export const copyLocalImportMap = ({
importMap,
styles,
styleUrls,
originCdnPrefix,
publicPath,
dir,
packageCopy,
bundleTempDir = 'bundle-deps/design-core-import-map'
) => {
base,
dir = 'import-map-static',
bundleTempDir = 'bundle-deps/design-core-import-map',
packageCopy = [] // key之为importMap的imports的左值 (非右值的地址上的包名)
}) => {
const importMapFiles = Object.entries(importMap.imports)
.filter(([_libKey, libPath]) => libPath.startsWith(originCdnPrefix))
.map(([libKey, libPath]) => {
if (packageCopy.includes(libKey)) {
return getCdnPathNpmInfoForPackage(libPath, originCdnPrefix, publicPath, dir, true, bundleTempDir)
return getCdnPathNpmInfoForPackage(libPath, originCdnPrefix, base, dir, true, bundleTempDir)
}
return getCdnPathNpmInfoForSingleFile(libPath, originCdnPrefix, publicPath, dir, false, bundleTempDir)
return getCdnPathNpmInfoForSingleFile(libPath, originCdnPrefix, base, dir, false, bundleTempDir)
})
const styleFiles = styles
const styleFiles = styleUrls
.filter((styleUrl) => styleUrl.startsWith(originCdnPrefix))
.map((url) => getCdnPathNpmInfoForSingleFile(url, originCdnPrefix, publicPath, dir, false), bundleTempDir)
.map((url) => getCdnPathNpmInfoForSingleFile(url, originCdnPrefix, base, dir, false), bundleTempDir)

const { packages: packageNeedToInstall, files } = getPackageNeedToInstallAndFilesUsingSameVersion(
importMapFiles.concat(styleFiles)
Expand Down Expand Up @@ -61,7 +61,7 @@ export const copyLocalImportMap = (
Object.entries(importMap.imports).map(([k, v]) => [k, files.find((f) => f.originUrl === v)?.newUrl ?? v])
)
},
styles.map((url) => styleFiles.find((f) => f.originUrl === url).newUrl ?? url)
styleUrls.map((url) => styleFiles.find((f) => f.originUrl === url).newUrl ?? url)
)
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export function extraPreviewImportFile(filename, targetFileName, originCdnPrefix
]
}

export function copyPreviewImportMap(
export function copyPreviewImportMap({
importMapJson,
targetImportMapJson,
originCdnPrefix,
base,
dir,
packageCopyLib = [],
bundleTempDir = 'bundle-deps/preview-import-map'
) {
dir = 'preview-import-map-static',
bundleTempDir = 'bundle-deps/preview-import-map',
packageCopyLib = [] // key之为cdn地址上的包名
}) {
const cdnFiles = extraPreviewImport(importMapJson, originCdnPrefix).map((url) => {
const { packageName } = url.match(
new RegExp(`^${originCdnPrefix}/?(?<packageName>.+?)@(?<versionDemand>[^/]+)(?<filePathInPackage>.*?)$`)
Expand Down
43 changes: 20 additions & 23 deletions packages/design-core/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,40 +288,37 @@ export default defineConfig(({ command, mode }) => {
monacoEditorPluginInstance,
htmlPlugin(mode),
isLocalImportMap
? copyLocalImportMap(
importmap,
importMapStyles,
VITE_CDN_DOMAIN,
getBaseUrlFromCli(config.base),
'import-map-static',
[
? copyLocalImportMap({
importMap: importmap,
styleUrls: importMapStyles,
originCdnPrefix: VITE_CDN_DOMAIN,
base: getBaseUrlFromCli(config.base),
packageCopy: [
// 这两个包的js存在相对路径引用,不能单独拷贝一个文件,需要整个包拷贝
'@opentiny/vue-theme/theme-tool',
'@opentiny/vue-theme/theme'
]
)
})
: importmapPlugin(importmap, importMapStyles),
isCopyBundleDeps
? copyBundleDeps(
'public/mock/bundle.json',
'mock/bundle.json',
VITE_CDN_DOMAIN, // mock 中bundle的域名当前和环境的VITE_CDN_DOMAIN一致
getBaseUrlFromCli(config.base),
'material-static'
).plugin(command === 'serve')
? copyBundleDeps({
bundleFile: 'public/mock/bundle.json',
targetBundleFile: 'mock/bundle.json',
originCdnPrefix: VITE_CDN_DOMAIN, // mock 中bundle的域名当前和环境的VITE_CDN_DOMAIN一致
base: getBaseUrlFromCli(config.base)
}).plugin(command === 'serve')
: [],
isLocalImportMap
? copyPreviewImportMap(
'./src/preview/src/preview/importMap.json',
'preview-import-map-static/preview-importmap.json',
VITE_CDN_DOMAIN,
getBaseUrlFromCli(config.base),
'preview-import-map-static',
[
? copyPreviewImportMap({
importMapJson: './src/preview/src/preview/importMap.json',
targetImportMapJson: 'preview-import-map-static/preview-importmap.json',
originCdnPrefix: VITE_CDN_DOMAIN,
base: getBaseUrlFromCli(config.base),
packageCopyLib: [
// 以下的js存在相对路径引用,不能单独拷贝一个文件,需要整个包拷贝
'@vue/devtools-api'
]
)
})
: []
)
return config
Expand Down

0 comments on commit 707a075

Please sign in to comment.