Jatin Garg
Jatin Garg

Reputation: 31

Compiling *.vue file to *.js file for using in cdn

Are there any methods to compile some Component.vue files to some javascript file? So that compiled js can be included in HTML and used with vue CDN.

For example, Lets' say we have some component Component.vue, given below


<template>
    <div class="demo">{{ msg }}</div>
</template>
<script>
export default {
    data() {
        return {
            msg: "Jatin Garg",
        };
    },
};
</script>

<style scoped>
.demo {
    color: blue;
}
</style>

Now we want to include the compiled Component.js in below HTML file.

<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>

I know a library called vue3-sfc-loader that does a similar thing. But rather using ".js" file it directly takes the Component.vue file and compiles it. Basically, I want to compile the .vue file offline

Upvotes: 2

Views: 1788

Answers (1)

peperoneen
peperoneen

Reputation: 141

The point is that you need to convert your file, not compile it. So you can to find a script that could do this, or create it by yourself.

Here is the answer to the similar question with a suitable script.

Upvotes: 0

Related Questions