photopea / UPNG.js

Fast and advanced PNG (APNG) decoder and encoder (lossy / lossless)
MIT License
2.1k stars 259 forks source link

Using with Angular #19

Closed friksa closed 6 years ago

friksa commented 6 years ago

When using this library with Angular5, it works great during development, but the build process using angular-cli strips it (tree shaking). I am not an expert at all of the different module types, but I forked the project and made it work for Angular and I am sure my brute force change will cause issues with other module systems... Wanted to give you a heads up in case you want to document it or make it Angular friendly. Thanks!

These are the changes I made to get it work in Angular 5 production

(function (factory) {
  window['UPNG'] = factory();
})(function () {

var UPNG = {};

// // Make available for import by `require()`
// var pako;
// if (typeof module == "object") {module.exports = UPNG;}  else {window.UPNG = UPNG;}
// if (typeof require == "function") {pako = require("pako");}  else {pako = window.pako;}
// function log() { if (typeof process=="undefined" || process.env.NODE_ENV=="development") console.log.apply(console, arguments);  }
// (function(UPNG, pako){

...... library .....

  return UPNG;
});
photopea commented 6 years ago

Hi, I think this will always make UPNG a property of a window. Our goal was to avoid this and integrate it with node.js . Can @Scimonster help us?

friksa commented 6 years ago

Yeah, I know my solution is not good for all module systems / build systems, but it works perfectly for Angular production.

Scimonster commented 6 years ago

I'm not familiar with an Angular build process.

photopea commented 6 years ago

I am closing it again. The interface should be clear for general-purpose JS, and users of build systems should figure their own way how to deal with it.