Skip to content

Commit bc0b2ea

Browse files
committed
build: offer sourcemap & global variable
1 parent 8058e35 commit bc0b2ea

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { globalAttrs, globalProps } from './index'
1717

1818
export type Mode = 'tree' | 'text'
1919

20+
const name = 'JsonEditorVue'
2021
const modelValueProp = isVue3 ? 'modelValue' : 'value'
2122
const updateModelValue = isVue3 ? 'update:modelValue' : 'input'
22-
2323
const boolAttrs = [
2424
'mainMenuBar',
2525
'navigationBar',
@@ -30,7 +30,7 @@ const boolAttrs = [
3030
]
3131

3232
export default defineComponent({
33-
name: 'JsonEditorVue',
33+
name,
3434
props: {
3535
[modelValueProp]: {},
3636
mode: {
@@ -166,3 +166,5 @@ export default defineComponent({
166166
return () => h('div', { ref: 'jsonEditorRef' })
167167
},
168168
})
169+
170+
export { name }

vite.config.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ConfigEnv, UserConfigExport } from 'vite'
22
import dts from 'vite-plugin-dts'
33
import { name } from './package.json'
4+
import { name as globalVariableName } from './src/Component'
45

56
// https://vitejs.dev/config/
67
export default ({ command }: ConfigEnv): UserConfigExport => {
@@ -10,18 +11,16 @@ export default ({ command }: ConfigEnv): UserConfigExport => {
1011
name,
1112
entry: 'src/index.ts',
1213
},
14+
sourcemap: true,
1315
rollupOptions: {
1416
external: [
1517
'vanilla-jsoneditor',
1618
'vue',
1719
'vue-demi',
1820
],
1921
output: {
20-
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
2122
globals: {
22-
'vanilla-jsoneditor': 'JSONEditor',
23-
'vue': 'Vue',
24-
'vue-demi': 'VueDemi',
23+
[name]: globalVariableName,
2524
},
2625
},
2726
},

0 commit comments

Comments
 (0)