Skip to content
Advertisement

How to render .vue file in javascript when using ES5? (Trying to use webpack and vue-loader)

I have been trying to migrate a vue project and I unfortunately cannot use import/export in where I am building the application. Therefore, to simplify my problem, I created a project from scratch to build a vue component without the vue-cli.

I have been successful to bring up the vue app with webpack before I created .vue files but after that point I started to get the following error and my .vue file wouldn’t render.

JavaScript

The code is the following and I’ll try to keep it as simple as possible:

index.js

JavaScript

App.vue

JavaScript

index.html

JavaScript

and lastly the webpack.config.js

JavaScript

I run webpack-dev-server --config ./webpack.config.js from npm to get the webpack server running. I also did webpack --config ./webpack.config.js but then I have to run the index.html in chrome and I thought running a server might actually be better for the bundle.

I am aware that a lot of people had similar problems but for some reason none of the solutions I found out there worked for me. I’d really appreciate some help about which direction I should take to fix this situation.

This article might be helpful but I am not sure how to fix my project with it: https://v2.vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only

Edit On Request

dev-Dependencies and dependencies:

JavaScript

Advertisement

Answer

What has worked thanks to thanksd’s comment:

JavaScript

However, it is important to have var App = require('./App.vue').default; especially the default part for the vue files. Hopefully that helps other people as well. I understand that my problem was in the end a simple syntax problem.

Advertisement