Skip to content

Commit 55bf74c

Browse files
committed
fix: add base path to local cdn path
1 parent ebf1bfd commit 55bf74c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

designer-demo/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"type": "module",
66
"scripts": {
77
"dev": "cross-env vite",
8-
"build:alpha": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vite build --mode alpha",
9-
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vite build",
8+
"build:alpha": "cross-env NODE_OPTIONS=--max-old-space-size=10240 vite build --mode alpha",
9+
"build": "cross-env NODE_OPTIONS=--max-old-space-size=10240 vite build",
1010
"test": "vitest run",
1111
"test:watch": "vitest"
1212
},

packages/build/vite-config/src/localCdnFile/localCdnPlugin.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function extractInfo(str) {
6565
* @param {string} cdnDir - 本地CDN目录名
6666
* @returns {Object} - Vite插件对象
6767
*/
68-
function createEnvReplacementPlugin(cdnDir) {
68+
function createEnvReplacementPlugin(cdnDir, base) {
6969
return {
7070
name: 'vite-replace-cdn-env',
7171
config(config) {
@@ -74,7 +74,9 @@ function createEnvReplacementPlugin(cdnDir) {
7474
config.define = {}
7575
}
7676

77-
config.define['import.meta.env.VITE_CDN_DOMAIN'] = JSON.stringify(`./${cdnDir}`)
77+
config.define['import.meta.env.VITE_CDN_DOMAIN'] = JSON.stringify(
78+
`${base.endsWith('/') ? base : base + '/'}${cdnDir}`
79+
)
7880
// 使用本地 CDN 时,强制设置CDN类型为 local
7981
config.define['import.meta.env.VITE_CDN_TYPE'] = JSON.stringify('local')
8082
}
@@ -377,7 +379,7 @@ export function localCdnPlugin({
377379
// 返回插件数组
378380
return [
379381
// 创建环境变量替换插件,替换CDN域名为本地路径
380-
createEnvReplacementPlugin(cdnDir),
382+
createEnvReplacementPlugin(cdnDir, base),
381383
// 安装需要的包
382384
...installPackageTemporary(packageNeedToInstall, bundleTempDir),
383385
// 使用自定义的copyPlugin替代直接调用copy

0 commit comments

Comments
 (0)