【发布时间】:2021-12-25 03:51:02
【问题描述】:
有没有什么方法可以将一些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 文件中。
<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文件
【问题讨论】:
-
这正是 Vue CLI 所做的。
-
我使用了
vue build Component.vue lib。但它不起作用并产生了非常巨大的文件。
标签: javascript vue.js vue-component vue-sfc vue3-sfc-loader