Compile ".vue" component in browser, with JS only?

I would like to compile the ".vue" components (with html / js / css content) in JS, but in a browser, no browser / vuify / webpack or others ...

In a better world, I would like to include my ".vue" component in my html application, for example with the need to compile things, server side:

<script type="vuejs/component" src="myComp.vue"></script>

      

Should this be possible ?! not? (And I can't imagine that no one got this idea or has already done it)

+3


source to share


2 answers


In fact, this is possible with http-vue-loader:



https://github.com/FranckFreiburger/http-vue-loader

+7


source


In the browser, it doesn't make sense to compile when it's much more efficient to just compile your component locally rather than relying on the client client to do so.

In fact, the answer above regarding vue-http-loader talks about it for development use only and links to this article: https://vuejs.org/2015/10/28/why-no-template-url/

With that said, I created a vue-cli template that lets you precompile files .vue

into a single file .js

that you can use in your browser. One JS file contains template, script and styles. It uses webpack, but it is very easy to run and keeps track of your files as they change.



$ vue init RonnieSan/vue-browser-sfc my-project

Repo: https://github.com/RonnieSan/vue-browser-sfc

The instructions are in the README.

+1


source







All Articles