Can SystemJS plugins modify already rewritten files?

When I tried to get Angular (1.x) working with systemjs, I realized that there is currently no way (I know) to automatically insert $inject components in Angular, which makes the components work even when function arguments are intercepted by the minifier. $inject creating $inject annotations is tedious, error prone, and violates the DRY principle.

There is a mature npm module called ng-annotate that solves this problem and is used in many similar situations for linking. Since I studied SystemJS, I see that there is a plug-in system that includes the ability to translate source code, which is what ng-annotate does.

From what I see, SystemJS gives you the ability to map a specific file extension to a single bootloader, and all sample plugins support the new file type. What I would like to do is post-process output the SystemJS transformation process instead of adding a new file type. It seems that SystemJS should be able to do this because it has a processing pipeline, but I cannot figure out how to properly insert it into it. Right now I am using Browserify to achieve the same effect, but I have a rather complicated set of build tasks and I would like to simplify it using SystemJS if possible.

Other strategies to use ng-annotate in the bootloader pipeline with SystemJS will also be evaluated.

+6
source share
1 answer

In the end, I figured out the way, but it seems very awkward. System.src itself uses the hook() function for this, but is not exported for use. I would appreciate any way to improve this, and I hope that eventually the loader function support mechanism, supported properly, will become available:

 var System = require('systemjs'); var systemTranslate = System.translate; System.translate = function(load) { return systemTranslate.call(this, load).then(function (result) { if (result) { var processedResult = result; // Do your processing here. load.source = processedResult; } return load.source; }); } 

I have not experimented much with this since my specific use cases for building System.js are currently deadlocked (Typescript source maps are still busted), but presumably you can also return the promise.

I will leave this answer unselected for a while to find out if anyone has any better advice.

+2
source

All Articles