Plugins SVG.js and RequireJS

I am trying to create an SVG.js plugin to create dynamic graphics. The site I want to use in order to use requireJS through django-require.

I am trying to get plugins to increase the SVG object exported by SVG.js correctly.

The plugin is modeled after svg.path.js , another SVG.js plugin, and looks something like this:

 (function() { SVG.extend(SVG.Path, { myGraphicType: function(p){ return this; } }); }).call(this); 

My plugin will depend on svg.path and SVG . svg.path also dependent on SVG . The shim in config requireJS looks like this:

 shim: { 'svg-0.32' : { exports: 'SVG' }, 'svg.path': { deps: ['svg-0.32'] }, 'svg.myplugin': { //My plugin! deps: ['svg-0.32', 'svg.path'] } } 

The main application defined() depends on both SVG and svg.myplugin . However, when I come to use the plugin as follows:

 var myGraphic = SVG.path().myGraphicType() 

I was told that SVG not defined in the svg.myplugin.js file.

What is the correct way to enable such plugins using requireJS?

+4
source share

Source: https://habr.com/ru/post/1496463/


All Articles