Laravel-mix: [Question] How to utilize vue-runtime build?

Created on 26 Jul 2017  路  12Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 1.3.0
  • Node Version: 6.11.1
  • NPM Version: 3.10.10
  • OS: Linux

Description:

Vue comes with a runtime build which allows for CSP compliance.

Steps To Reproduce:

The following addition to the webpack.mix.js allows mix to use the runtime version:

mix.webpackConfig({
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.runtime.js'
        }
    }
});

This compiles the resources find but does not work during runtime as the templates are not compiled to render functions. In the link above, it is suggested that webpack + vue-loader can be used to pre-compile the templates.

However, I couldn't find a way to do this. It would be great if this could be included in the docs. If it is already included, please forgive my ignorance and point me to it :smiley:

Most helpful comment

<my-cookie-banner>
</my-cookie-banner>

There's your problem. You're sending HTML with a custom element, which Vue will pick up on, but being unable to handle rendering it, missing the template compiler and all :P

Try something like this:

const root = require('./components/MyCookieBanner.vue');
const app = new Vue({
  el: '#app',
  render: createElement => createElement(root) //< The important line
});

EDIT: In addition you shouldn't have anything inside <div id="app">

All 12 comments

Are you using single file components?

@DrJonki Yes, all the components in the project will be single file components. I suppose that's kind of necessary to get the pre-compilation?

@sausin Correct. The default installation of Mix has vue-loader already set-up (mentioned here), so as long as all of your Vue templates are defined either in single-file