I have generated sample Vue.js project using vue-cli and built it by
vue build --target lib --name myWidget src/main.js
I must use Requirejs to load it:
<script>
requirejs.config({
paths: {
"Vue": "https://cdn.jsdelivr.net/npm/[email protected]/dist/vue",
"myWidget": "https://codematic.tech/yamaWidget.umd",
}
});
</script>
<script>
require(["Vue"], function (Vue) {
console.log('Vue loaded');
require(["myWidget"], function (widget) {
console.log('Widget loaded');
});
});
</script>
Looks like it should work, however I've got an error:
TypeError: Cannot read property 'config' of undefined
which points to
Vue.config.productionTip = false
in source code. I managed to fix it by adding Vue = window.Vue; in Vue's main.js file and window.Vue = Vue in <script> tag, after require'ing Vue. Library is loading, mounting in #app. Looks weird, but is working.
Problem is when I import something in Vue's main.js file. In example,
import Snotify from 'vue-snotify';
gives me an error below:
Cannot read property 'extend' of undefined
which leads me to line:
var script = external_commonjs_vue_commonjs2_vue_root_Vue_default.a.extend({
By the way - when I load both Vue.js and myWidget.umd.js directly through <script> tag, everything is working fine!