Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit 292bf2e

Browse files
committed
chore: global import
Signed-off-by: Innei <i@innei.in>
1 parent 55fd18a commit 292bf2e

10 files changed

Lines changed: 126 additions & 37 deletions

File tree

index.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
@@ -16,12 +16,6 @@
1616
<!-- ENV INJECT -->
1717
<!-- MX SPACE ADMIN DASHBOARD VERSION INJECT -->
1818
<!-- injectable script -->
19-
<script src="./node_modules/vue/dist/vue.global.js"></script>
20-
<script src="./node_modules/vue-router/dist/vue-router.global.js"></script>
21-
<script src="./node_modules/vue-demi/lib/index.iife.js"></script>
22-
<script src="./node_modules/@vueuse/shared/index.iife.min.js"></script>
23-
<script src="./node_modules/@vueuse/core/index.iife.min.js"></script>
24-
<script src="./node_modules/@vueuse/components/index.iife.min.js"></script>
2519
</head>
2620

2721
<body>

library-external.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import randomstring from 'randomstring'
22
import { viteExternalsPlugin as ViteExternals } from 'vite-plugin-externals'
3+
import { createHtmlPlugin } from 'vite-plugin-html'
4+
import { viteStaticCopy } from 'vite-plugin-static-copy'
35
import type { HtmlTagDescriptor } from 'vite'
46
import type { Target } from 'vite-plugin-static-copy'
57

@@ -55,11 +57,6 @@ export const setupLibraryExternal = (
5557
dest: './assets/vueuse',
5658
rename: `vueuse.components.iife.${staticSuffix}.js`,
5759
},
58-
{
59-
src: './node_modules/@vueuse/router/index.iife.min.js',
60-
dest: './assets/vueuse',
61-
rename: `vueuse.router.iife.${staticSuffix}.js`,
62-
},
6360
]
6461

6562
const injectTags = staticTargets
@@ -68,7 +65,9 @@ export const setupLibraryExternal = (
6865
injectTo: 'head',
6966
tag: 'script',
7067
attrs: {
71-
src: `${isProduction ? baseUrl : '/'}${target.dest}/${target.rename}`,
68+
src: isProduction
69+
? `${baseUrl}${target.dest}/${target.rename}`
70+
: target.src,
7271
type: 'text/javascript',
7372
},
7473
}
@@ -82,18 +81,18 @@ export const setupLibraryExternal = (
8281

8382
'@vueuse/core': 'VueUse',
8483
'@vueuse/components': 'VueUse',
85-
'@vueuse/router': 'VueUse',
84+
8685
'vue-demi': 'VueDemi',
8786
}),
88-
// ViteStaticCopy({
89-
// targets: staticTargets,
90-
// }),
91-
// VitePluginHtml({
92-
// minify: false,
93-
// inject: {
94-
// tags: injectTags,
95-
96-
// },
97-
// }),
87+
isProduction &&
88+
viteStaticCopy({
89+
targets: staticTargets,
90+
}),
91+
createHtmlPlugin({
92+
minify: false,
93+
inject: {
94+
tags: injectTags,
95+
},
96+
}),
9897
]
9998
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"validator": "13.11.0",
7777
"vite-plugin-windicss": "1.9.3",
7878
"vue": "3.4.3",
79+
"vue-demi": "*",
7980
"vue-router": "4.2.5",
8081
"xss": "1.0.14",
8182
"xterm": "5.3.0",
@@ -106,6 +107,7 @@
106107
"prettier": "3.1.1",
107108
"randomstring": "1.3.0",
108109
"rollup": "^4.9.2",
110+
"rollup-plugin-external-globals": "0.9.1",
109111
"rollup-plugin-visualizer": "5.12.0",
110112
"typescript": "5.3.3",
111113
"unplugin-auto-import": "0.17.3",

packages/plugin-bunder-kit/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ export function VitePluginBundlerKit(manifest: any): Plugin {
2323
'vue-router',
2424
'@vueuse/core',
2525
'@vueuse/components',
26-
'@vueuse/router',
2726
],
2827
output: {
2928
globals: {
3029
vue: 'Vue',
3130
'vue-router': 'VueRouter',
3231
'@vueuse/core': 'VueUse',
3332
'@vueuse/components': 'VueUse',
34-
'@vueuse/router': 'VueUse',
3533
},
3634
extend: true,
3735
},

plugins/hello/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Plugin</title>
7-
<script src="./src/index.tsx" type="module"></script>
7+
<script src="./src/index.ts" type="module"></script>
88
</head>
99
<body></body>
1010
</html>

plugins/hello/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"name": "mx-plugin-hello",
33
"version": "0.0.1",
44
"devDependencies": {
5+
"@rollup/pluginutils": "^5.1.0",
56
"@vitejs/plugin-vue": "5.0.2",
67
"@vitejs/plugin-vue-jsx": "3.1.0",
8+
"rollup-plugin-external-globals": "^0.9.1",
79
"vite": "5.0.10",
810
"vite-tsconfig-paths": "4.2.3",
911
"vue": "3.4.3"

plugins/hello/pnpm-lock.yaml

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/hello/src/App.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { defineComponent } from 'vue'
22

3+
export const Component = defineComponent({
4+
setup() {
5+
return () => <div>Hello</div>
6+
},
7+
})
8+
39
export const register = () => {
410
return {
511
name: 'hello',
612

7-
component: defineComponent({
8-
setup() {
9-
return () => <div>Hello</div>
10-
},
11-
}),
13+
component: Component,
1214
}
1315
}

plugins/hello/vite.config.mts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import externalGlobals from 'rollup-plugin-external-globals'
2+
import { defineConfig } from 'vite'
13
import tsconfigPaths from 'vite-tsconfig-paths'
24
import type { Plugin } from 'vite'
35

@@ -18,7 +20,7 @@ function VitePluginBundlerKit(manifest: any): Plugin {
1820
lib: {
1921
entry: 'src/index.ts',
2022
name: manifest.metadata.name,
21-
formats: ['iife'],
23+
formats: ['esm'],
2224
fileName: () => 'main.js',
2325
},
2426
rollupOptions: {
@@ -27,15 +29,13 @@ function VitePluginBundlerKit(manifest: any): Plugin {
2729
'vue-router',
2830
'@vueuse/core',
2931
'@vueuse/components',
30-
'@vueuse/router',
3132
],
3233
output: {
3334
globals: {
3435
vue: 'Vue',
3536
'vue-router': 'VueRouter',
3637
'@vueuse/core': 'VueUse',
3738
'@vueuse/components': 'VueUse',
38-
'@vueuse/router': 'VueUse',
3939
},
4040
extend: true,
4141
},
@@ -46,7 +46,8 @@ function VitePluginBundlerKit(manifest: any): Plugin {
4646
}
4747
}
4848

49-
export default {
49+
// eslint-disable-next-line import/no-default-export
50+
export default defineConfig({
5051
plugins: [
5152
vue(),
5253
vueJsx(),
@@ -56,5 +57,18 @@ export default {
5657
name: 'hello',
5758
},
5859
}),
60+
// replaceImportsToGlobal({
61+
// include: 'src/**/*.tsx', // 根据需要调整
62+
// // ... 其他选项
63+
// }),
5964
],
60-
}
65+
build: {
66+
rollupOptions: {
67+
plugins: [
68+
externalGlobals({
69+
vue: 'Vue',
70+
}),
71+
],
72+
},
73+
},
74+
})

pnpm-lock.yaml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)