VueJs
Introduction
The Vue.js Drupal module provides a bridge between Drupal and the Vue.js framework. This module is compatible with both Vue 2 and 3 and comes with additional support for petite vue.
Vue
Composer Merge Plugin (Vue 3 only)
Library installation via- Install the composer merge-plugin via
composer require wikimedia/composer-merge-plugin
- Add the following entry in your composer.json:
"merge-plugin": {
"include": [
"web/modules/contrib/vuejs/composer.libraries.json"
]
},
- Update the vuejs module via composer:
composer update 'drupal/vuejs'
- Navigate to the
admin/config/development/vue
page. - Set the installation type to "Local library".
- Set the library path to
/package/dist/vue.runtime.global.prod.js
if not already defined so.
Library installation via manual download
Vue 3
- Download
https://registry.npmjs.org/vue/-/vue-3.5.13.tgz
- Extract the tar inside the drupal
libraries/vue
folder. - Navigate to the
admin/config/development/vuejs
page. - Set the installation type to "Local library".
- Set the library path to
/libraries/vue/package/dist/vue.runtime.global.prod.js
if not already defined so.
Vue 2
- Download
https://registry.npmjs.org/vue/-/vue-2.7.16.tgz
- Extract the tar inside the drupal
libraries/vue
folder. - Navigate to the
admin/config/development/vuejs
page. - Set the installation type to "Local library".
- Set the library path to
/libraries/vue/package/dist/vue.min.js
if not already defined so.
Library Installation via CDN
- Navigate to the
admin/config/development/vuejs
page. - Set the installation type to "Use an external CDN".
- Select your prefered provider and Version.
USAGE
- You can use it inside Twig templates as usual, for example:
{{ attach_library('vuejs/vue') }}
- You can attach it programmatically:
function MYMODULE_page_attachments(array &$attachments) {
$attachments['#attached']['library'][] = 'vuejs/vue';
}
- You can add it as a dependency inside your
*.libraries.yml
:
dependencies:
- vuejs/vue
Petite vue
Library installation via manual download
- Download
https://registry.npmjs.org/petite-vue/-/petite-vue-0.4.1.tgz
- Extract the tar inside the drupal
libraries/petitevue
folder. - Navigate to the
admin/config/development/vuejs
page. - Set the installation type to "Local library".
- Set the library path to
/libraries/petitevue/package/dist/petite-vue.iife.js
if not already defined so.
Library Installation via CDN
- Navigate to the
admin/config/development/vuejs
page. - Set the installation type to "Use an external CDN".
- Select your prefered provider and Version.
USAGE
- You can use it inside Twig templates as usual, for example:
{{ attach_library('vuejs/petitevue') }}
- You can attach it programmatically:
function MYMODULE_page_attachments(array &$attachments) {
$attachments['#attached']['library'][] = 'vuejs/petitevue';
}
- You can add it as a dependency inside your
*.libraries.yml
:
dependencies:
- vuejs/petitevue
PROJECT PAGE
For more information, visit the project page at https://www.drupal.org/project/vuejs