Changing Vue.js from standalone to runtime-only build later in a project?
javascript, vue.js, vuejs2
Solution
`standalone` supports template option in components. For example, you can do this:
`Vue.component('my-component', { template: '<div>A custom component!</div>' })`
`standalone` also allows you to load `vue.js` from a CDN, like you would do with jQuery or any other javascript library.
`runtime-only` does not allow you to use `template` in component definition. So you need to create `my-component.vue` file and define template inside as detailed in Single File Components guide: http://vuejs.org/guide/single-file-components.html
Also you need to use `vue-cli` for development, if you are using `runtime-only`.
To switch from `standalone` to `runtime-only`, you will have to rewrite all the components into `my-component.vue` files, and start using `vue-cli`
To switch from `runtime-only` to `standalone`, there are no changes required.
Other than that, it is painless to switch between `runtime-only` and `standalone`.
My preference: `runtime-only` only mode, as it produces much smaller builds and theoretically performs better, as templates are pre-compiled. Also the sections in `vue` file are well organized and easy to read. Separate vue files for components also forces you to structure your app better.
Problem
Went with the `runtime-only` build version of Vue.js for a new project. I saw in the docs that to switch to the `standalone` one needs to add an alias to webpack, like so: ``` resolve: { alias: { 'vue$': 'vue/dist/vue.js' } } ``` At the moment, I don't need the compiler in my app. However, it's possible that at some point I will need to switch to the `standalone` build. My question is: Will it be a painless switch between `runtime-only` and `standalone` later or will it require heavy refactoring? If it does, I might as well start with `standalone` and avoid refactoring later on.