Compile a “.vue” component in browser, with JS only?

扶醉桌前 提交于 2019-12-23 10:07:00

问题


I'd like to compile ".vue" components (with contains html/js/css) into JS, but in browser side, without browserify/vuify/webpack or others ...

In a better world, i'd like to include my ".vue" component into my html app, like that, withoud need of compile things, server side:

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

It should be possible ?! no ? (And I can't imagine that no one got this idea, or have done it already)


回答1:


In fact, it's possible with http-vue-loader :

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




回答2:


It doesn't make sense to compile in the browser when it's so much more efficient to just pre-compile your component locally instead of relying on a visitor's client to do it.

In fact, the answer above regarding vue-http-loader says it's only for use in development 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 pre-compile .vue files into a single .js files you can use in the browser. The single JS file contains the template, script, and styles. It uses webpack, but it's super easy to run and watches your files as you edit them.

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

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

Instructions are in the README.



来源:https://stackoverflow.com/questions/43896319/compile-a-vue-component-in-browser-with-js-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!