Skip to content

feat: external all dependencies of core package #1236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/canvas/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ export default defineConfig({
return ''
}
},
external: ['vue', '@vueuse/core', 'vue-i18n', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: [
'vue',
'@vueuse/core',
'vue-i18n',
/@opentiny\/tiny-engine.*/,
/@opentiny\/vue.*/,
/^@babel.*/,
/^@vue.*/,
'diff-match-patch',
'jsondiffpatch',
'postcss',
'postcss-selector-parser'
]
},
minify: true
}
Expand Down
9 changes: 8 additions & 1 deletion packages/common/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ export default defineConfig({
/@opentiny\/tiny-engine.*/,
/@opentiny\/vue.*/,
/^prettier.*/,
/^@babel.*/
/^@babel.*/,
/^@eslint.*/,
/^@vueuse.*/,
/^@vue.*/,
'axios',
'css-tree',
'eslint-linter-browserify',
'vue-draggable-next'
]
}
}
Expand Down
18 changes: 17 additions & 1 deletion packages/design-core/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,23 @@ export default defineConfig({
}
}
},
external: ['vue', 'monaco-editor', 'prettier', /@opentiny\/vue.*/, '@opentiny/tiny-engine-meta-register']
external: [
'vue',
'monaco-editor',
'prettier',
'@vue/repl/monaco-editor',
'element-resize-detector',
'eslint-linter-browserify',
'file-saver',
'html2canvas',
'sortablejs',
'vue-i18n',
/@opentiny\/vue.*/,
/@opentiny\/tiny-engine-*/,
/@vue\/*/,
/@babel\/*/,
/@vueuse\/*/
]
}
}
})
2 changes: 1 addition & 1 deletion packages/layout/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
output: {
banner: 'import "./style.css"'
},
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, '@vueuse/core', 'vue-draggable-next']
}
}
})
2 changes: 1 addition & 1 deletion packages/plugins/block/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
output: {
banner: 'import "./style.css"'
},
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, '@vue/shared', 'html2canvas', 'pinyin-pro']
}
}
})
10 changes: 9 additions & 1 deletion packages/plugins/datasource/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ export default defineConfig({
output: {
banner: 'import "./style.css"'
},
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: [
'vue',
/@opentiny\/tiny-engine.*/,
/@opentiny\/vue.*/,
'@vue/shared',
'axios',
'vue-clipboard3',
'xlsx'
]
}
}
})
2 changes: 1 addition & 1 deletion packages/plugins/i18n/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
output: {
banner: 'import "./style.css"'
},
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, 'vue-clipboard3']
}
}
})
2 changes: 1 addition & 1 deletion packages/plugins/schema/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
output: {
banner: 'import "./style.css"'
},
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, '@vueuse/core']
}
}
})
2 changes: 1 addition & 1 deletion packages/plugins/tutorial/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
output: {
banner: 'import "./style.css"'
},
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, 'marked']
}
}
})
2 changes: 1 addition & 1 deletion packages/register/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default defineConfig({
formats: ['es']
},
rollupOptions: {
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, 'lodash-es']
}
}
})
2 changes: 1 addition & 1 deletion packages/settings/props/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
output: {
banner: 'import "./style.css"'
},
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, '@vueuse/core']
}
}
})
2 changes: 1 addition & 1 deletion packages/settings/styles/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
output: {
banner: 'import "./style.css"'
},
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, '@vueuse/core', 'postcss']
}
}
})
2 changes: 1 addition & 1 deletion packages/toolbars/lang/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
output: {
banner: 'import "./style.css"'
},
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, '@vueuse/core']
}
}
})
2 changes: 1 addition & 1 deletion packages/toolbars/view-setting/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineConfig({
formats: ['es']
},
rollupOptions: {
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, '@vueuse/core']
}
}
})
2 changes: 1 addition & 1 deletion packages/utils/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default defineConfig({
formats: ['es']
},
rollupOptions: {
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, 'jszip']
}
}
})
10 changes: 9 additions & 1 deletion packages/vue-generator/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ export default defineConfig({
},
sourcemap: true,
rollupOptions: {
external: ['@babel/parser', '@babel/traverse', '@babel/generator']
external: [
'@babel/parser',
'@babel/traverse',
'@babel/generator',
'vue',
'vue-eslint-parser',
/@vue\/.*/,
/@opentiny\/tiny-engine.*/
]
}
}
})
2 changes: 1 addition & 1 deletion packages/webcomponent/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个包是不是可以删除了,已经没有用到了

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以,下次 PR 变更上来

rollupOptions: {
// 确保外部化处理那些你不想打包进库的依赖
external: ['vue', 'vue-i18n'],
external: ['vue', 'vue-i18n', '@vue/shared'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Good externalization of @vue/shared dependency.

Adding '@vue/shared' to the externals list is appropriate for this package. However, I notice that you've updated the globals mapping for 'vue' and 'vue-i18n' but not for '@vue/shared'.

Consider whether you need to add '@vue/shared' to the globals object for UMD builds:


🏁 Script executed:

#!/bin/bash
# Check if @vue/shared is used in UMD builds and needs a global variable mapping

# Search for imports of @vue/shared in the webcomponent package
rg -A 2 "from ['\"]\@vue/shared['\"]" packages/webcomponent/

Length of output: 167


I’ll check the Vite config and scan for any actual imports of @vue/shared before deciding if a UMD global is needed.


🏁 Script executed:

#!/bin/bash
set -e

echo "1) Locate Vite config for webcomponent package"
rg -l "vite.config.js" 

echo -e "\n2) Show externals & globals in vite.config.js"
sed -n '1,200p' packages/webcomponent/vite.config.js | sed -n '30,60p'

echo -e "\n3) Find any usage of @vue/shared in source files"
rg -n "@vue/shared" packages/webcomponent

Length of output: 1407


Add missing UMD global for @vue/shared

The webcomponent bundle imports utilities from @vue/shared (e.g. in src/defineCustomElement.js), and you’ve externalized it in Rollup, but you haven’t provided a corresponding global in the UMD build. This will lead to a runtime “undefined” when consumers use the UMD script.

• File: packages/webcomponent/vite.config.js
• Location: under rollupOptions.output.globals

Suggested diff:

 output: {
   globals: {
     vue: 'Vue',
     'vue-i18n': 'VueI18n',
+    '@vue/shared': 'VueShared'
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
external: ['vue', 'vue-i18n', '@vue/shared'],
// packages/webcomponent/vite.config.js
export default defineConfig({
build: {
rollupOptions: {
external: ['vue', 'vue-i18n', '@vue/shared'],
output: {
globals: {
vue: 'Vue',
'vue-i18n': 'VueI18n',
'@vue/shared': 'VueShared'
}
}
}
}
})

output: {
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals: {
Expand Down