Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

usage of JS plugins with webpack

I am trying to reconfigure my Symfony 3 project to use webpack encore instead of normal asstets. I am a little stuck with this.

For one part of the application I developed some JS plugins which inherits from Kube (a CSS and JS Framework I am unsing). Here is an exmaple:

(function (Kube) {
Kube.Assignment = function (element, options) {

    this.namespace = 'assignment';
    this.defaults = {
        //...
    };

    Kube.apply(this, arguments);

    this.start();
};

Kube.Assignment.prototype = {

    start: function () {
        //...
    }
};

Kube.Assignment.inherits(Kube.Distribution);

Kube.Plugin.create('Assignment');
Kube.Plugin.autoload('Assignment');

}(Kube));

Unfortunatly Kube is not recognized.

The module 'imperavi-kube' is installed via yarn and is imported via

let Kube = require('imperavi-kube');

I am getting the following error: TypeError: Kube.Assignment.inherits is not a function

Propably this is not a issue of the Kube Framework but somthing about handeling JS plugins with webpack.

Inside the Kube module there is a class 'Kube' defined with a prototype. The Prototype ends with window.Kube = Kube;

like image 233
SpigAndromeda Avatar asked Mar 16 '18 13:03

SpigAndromeda


1 Answers

Try to import Kube like this:

import * as Kube from <your path> or <alias> or <module name>

I may be wrong, but as far as I remember sometimes it works a bit differently.

like image 57
Anton Pilyak Avatar answered Nov 10 '22 03:11

Anton Pilyak