Created
January 31, 2015 18:41
-
-
Save sloosch/07eb491558862cee53fd to your computer and use it in GitHub Desktop.
ng annotate webpack loader with source map support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ngAnnotate = require('ng-annotate'); | |
var utils = require('loader-utils'); | |
var SourceMapConsumer = require('source-map').SourceMapConsumer; | |
var SourceMapGenerator = require('source-map').SourceMapGenerator; | |
module.exports = function(content, sm) { | |
var filename = utils.getCurrentRequest(this); | |
var res = ngAnnotate(content, { | |
add : true, | |
sourcemap : {inline: false, inFile : filename, sourceRoot:filename} | |
} | |
); | |
var mergeMap = null; | |
if(sm) { | |
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sm)); | |
generator.applySourceMap(new SourceMapConsumer(res.map), filename); | |
mergeMap = generator.toString(); | |
} | |
this.callback(null, res.src, mergeMap); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
P.S. Made a PR to the repo that owns the
ng-annotate-loader
name on npm: andrey-skl/ng-annotate-loader#2