有没有什么方法可以把一些Component.vue文件编译成javascript文件?以便编译后的js可以包含在HTML中并与vue CDN一起使用。
例如,假设我们有一些组件Component.vue,如下所示
<template>
<div class="demo">{{ msg }}</div>
</template>
<script>
export default {
data() {
return {
msg: "Jatin Garg",
};
},
};
</script>
<style scoped>
.demo {
color: blue;
}
</style>现在我们想把编译好的Component.js包含在下面的文件中。
<html lang="en">
<head>
<script src="/path/to/Component.js"></script>
<script src="vue@next"></script>
<body>
<div id="app">
<component></component>
</div>
</body>
<script>
const app = Vue.createApp({});
app.component("component", Component);
app.mount("#app");
</script>
</head>
<body></body>
</html>我知道一个名为vue3-sfc-loader的库可以做类似的事情。而不是使用".js“文件,它直接获取Component.vue文件并编译它。基本上,我想脱机编译.vue文件
发布于 2021-11-12 21:28:12
关键是你需要转换你的文件,而不是编译它。所以你可以找到一个可以做这件事的脚本,或者自己创建它。
用合适的脚本Here is出类似问题的答案。
https://stackoverflow.com/questions/69948991
复制相似问题