
在html中直接调用暴露的方法
问题描述:
vite打包后生成了一个umd文件,如何在html中直接调用该文件暴露的方法?目前已尝试挂载到window上,是否还有其他方法?
配置信息:
立即学习“前端免费学习笔记(深入)”;
import { visualEditorPlugin } from '@jim/visual-editor';
export default function config() {
return {
vue: {
template: {
compilerOptions: {
delimiters: [
'{#',
'#}'
]
}
}
},
plugins: [
visualEditorPlugin({
cachePath: cachePath
}),
cssInjectedByJsPlugin({
styleId: `${name}-style`,
topExecutionPriority: true
}),
{
...typescript({
tsconfig: './tsconfig.json',
include: ['./src/**']
}),
apply: 'build',
declaration: true,
declarationDir: 'types/',
rootDir: '/'
}
],
build: {
lib: {
name,
fileName: name
},
rollupOptions: {
output: {
sourcemap: true
}
}
}
};
}答案:
目前只能通过挂载到全局对象(即 window)的方式进行调用,之后通过合理路径直接调用即可。
另外,也可以考虑打包多种格式,例如 umd、iife、esm,然后根据需要引用。
以上就是Vite 打包 UMD 文件后,如何直接在 HTML 中调用其暴露的方法?的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号