3

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.

4
  • What happened when using vue-template-compiler? Commented Oct 17, 2016 at 16:15
  • @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. ... Commented Oct 17, 2016 at 16:28
  • Try this: stackoverflow.com/questions/33469929/… Commented Oct 17, 2016 at 21:28
  • @MahmudAdam doesn't work Commented Oct 18, 2016 at 9:43

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly it works, but compile function support only String as param. Thanks for your reply @imcvampire.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.