zingtouch icon indicating copy to clipboard operation
zingtouch copied to clipboard

Importing directly min.js cause errors

Open angelarted opened this issue 7 years ago • 2 comments

Hallo! I tried importing Zing library in an ES6 project as suggested in the main site (https://zingchart.github.io/zingtouch/) with this path:

  import ZingTouch from '../vendor/zingtouch/dist/zingtouch.min.js';

screenshot of the suggestion in the main page schermata 2017-03-29 alle 10 04 58

and it caused an error, I attach the screenshots

screenshot of the error schermata 2017-03-29 alle 09 56 16

Than I added it in the way suggested in the github page and it worked well (same code)

    import ZingTouch from '../vendor/zingtouch';

screenshot of the suggestion in github page schermata 2017-03-29 alle 10 22 58

Can you tell why? Many thanks!

angelarted avatar Mar 29 '17 08:03 angelarted

@angelarted Hey thanks for noticing that. The snippet on the homepage is outdated and I'll go ahead and fix that to the correct one on github.

The zingtouch.min.js file is made to attach itself to the global window object and does not force the developer to use module imports.

The import ZingTouch from 'zingtouch' syntax is actually pointing to the index.js file in the project via npm and the package.json. That file has the following code:

require('./dist/zingtouch.min.js');
module.exports = ZingTouch;

It's a small wrapper that imports the zingtouch.min.js file into it's own namespace, and then exports the single ZingTouch variable so it does not pollute your global namespace.

Importing the .min.js file directly won't work since nothing is being exported out as a module, hence your error.

mike-schultz avatar Mar 29 '17 15:03 mike-schultz

@mike-schultz HI there, I used the ES6 method to install ZingTouch as described in your comment, but the ZingTouch module is still added to my global namespace. Is that always going to be the case, or is there a way I can prevent it from being added to my global namespace?

agriffi10 avatar Dec 15 '17 16:12 agriffi10