user1432751 user1432751 - 1 year ago 115
Javascript Question

Using `.vue` files with latest browsers that support import/export

Chrome 60 and latest Firefox with flags have support

directives. I would like to use
files without NodeJS, but I can't figure out how to do it.

works fine with
files, but when I am trying to do it with
I am getting fail.

My code:

<!DOCTYPE html>
<script src=""></script>

<script type="module">
import {myc} from './c.vue';



for start I tried to place in
next code:
export const myc = "ccc";

But I got error:
GET http://localhost:8082/c.vue

Is it's possible to place there content like:

<div id="app">

export default {
name: 'app',
data () {
return {
msg: 'Welcome!'
components: {}

Answer Source

As said in the comment, even modern browsers are unable to read .vue files, and that's very unlikely to change in the future. So you should should use some build tool to convert .vue to .js. For bundle solutions, see the other answers.

If for some reason you don't want to bundle them (the only serious reason I can see for it is for fun & test / pure electron release, actually, but anyway), I may have another solution.

I didn't tested it for your particular use case (native import/export in browser), but I wrote a module using vueify to convert .vue files into .js, without bundling them, using gulp. It should probably work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download