Skip to content

helixge/vue3-single-file-component-to-js-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vue-single-file-component-to-js-compiler

Converts Vue3 single component file:

<template>
  <div>{{ text }}</div>
</template>

<script>
export default {
  data: function() {
    return {
      text: "Example"
    };
  },
  methods: {}
};
</script>

Into Vue component declaration in JS:

window.VueComponents = window.VueComponents || {};
window.VueComponents['test-component'] = {
  data: function () {
    return {
      text: "Example"
    };
  },
  methods: {},
  template: `
  <div>{{ text }}</div>
`
};

which can later be used to register components on the app instance:

const app = Vue.createApp({});

if (window.VueComponents) {
    Object.keys(window.VueComponents).forEach(function(componentName) {
        app.component(componentName, window.VueComponents[componentName]);
    });
}

app.mount(...);

About

Compile Vue3 single file components to JS format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •