3
votes

I am using Vuejs 2 (webpack-simple template) and I would like to know how can I compile template before render it. Below my code :

App.vue

<template>
    <div id="app">
        <h1>{{ msg }}</h1>
    </div>
</template>
<script>
    export default {
        name: 'app'
    }
</script>

main.js

import Vue from 'vue'
import App from './App.vue'

const res = Vue.compile(App)
const vm = new Vue({
    el: '#app',
    data: {
        msg: 'hello'
    },
    render: res.render,
    staticRenderFns: res.staticRenderFns
})

And these is the error that I've got when I start the server: __WEBPACK_IMPORTED_MODULE_0_vue___default.a.compile is not a function

I also tried this plugin vue-template-compiler with no luck. Can you please help me to make it work ? Thanks in advance.

1
What happened when using vue-template-compiler? - Mahmud Adam
@MahmudAdam I got this error : ...MyProject/node_modules/vue-template-compiler/package.json Unexpected token. You may need an appropriate loader to handle this file type. ... - Maria Minh
@MahmudAdam doesn't work - Maria Minh

1 Answers

4
votes

You will need this setting in webpack's config:

resolve: {
  alias: {
    'vue$': 'vue/dist/vue'
  }
}

despite on this problem: http://vuejs.org/guide/installation.html#Standalone-vs-Runtime-only-Build