Here’s how to add Vue.js support to your Sage 9 project.
1. Add dependencies
yarn add vue
yarn add --dev babel-core babel-eslint babel-loader \
babel-plugin-transform-runtime babel-preset-env \
babel-preset-stage-2 babel-register \
vue-loader vue-style-loader vue-template-compiler
2. Add a .babelrc
file
{
"presets": ["es2015", "stage-0"],
"plugins": ["transform-runtime"]
}
3. Add stuff to webpack.config.js
To your webpack.config.js
file (found in resources/assets/build/
), add this to modules.rules
:
{
test: /\.vue$/,
loader: 'vue'
},
And to force the runtime to include the full compiler (only needed if you want your root Vue element to be parsed as a Vue template), add this under resolve
:
alias: {
'vue$': 'vue/dist/vue.esm.js' // 'vue/dist/vue.common.js' for webpack 1
},
4. Setup a directory for your .vue
components
resources/assets/scripts/vue/
seems like a good spot for those .vue
components.
Here’s an example:
The root vue element is here:
And here’s home.js
hooking a Vue instance to parse that element and calling that sites.vue
component: