I'm using Symfony 4 with Webpack Encore, (which is supposed to be the new Assetic (cf SensioLab) ).
But I have an issue :/ On each page, I link two scripts app.js and app.css which are compiled by Webpack and contain all my libraries from this js code :
// CSS
// Libraries
require('font-awesome/css/font-awesome.css')
require('bootstrap/dist/css/bootstrap.css')
require('@css/elements/_nav.scss')
require('@css/app.scss')
require('@css/elements/_box.scss')
// JS
require('jquery')
require('vue')
require('axios')
require('bootstrap')
Moreover, I have some page which have personal js and css file. (in addition of app.js and app.css), which contain the configuration of the page. These files are also compiled by webpack, from a .vue file. For example, my index.vue file is :
<script>
import UpPage from '@components/up-page/page.vue'
new Vue({
el: "#media-container",
delimiters: ["<%", "%>"],
data: {
media: [],
nbMediaPerSearch: 20,
canShowMedia: false
},
methods: {
getMedia: function (nb) {
let that = this;
axios.get(Routing.generate("api_rest_page_get_page_media", {
count: nb
})).then(function (result) {
let data = result.data;
// Add media to media list
if (data.length > 0)
data.forEach(function (elt) {
that.media.push(elt);
});
that.canShowMedia = that.media.length !== 0;
}).catch(function (error) {
console.error(error);
})
},
openInNewTab: function (url) {
let win = window.open(url, '_blank');
win.focus();
}
},
beforeMount() {
this.getMedia(this.nbMediaPerSearch);
}
})
</script>
Eventualy, My Twig file use the index.js file provided to list all the media in the #media-container (with a v-for loop on a div)
But, when I try to see my page, I have this error :
Uncaught ReferenceError: Vue is not defined at Object../node_modules/babel-loader/lib/index.js?{"cacheDirectory":true}!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./assets/vue/pages/user/my-page/index.vue (index.vue:16)
I have tried something like this in my app.js :
let $ = require('jquery')
let Vue = require('vue')
let axios = require('axios')
let bootstrap = require('bootstrap')
But same issue :/ I have no idea of what is causing this issue, I am a beginner with webpack and webpack encore :/