From 408202729ec842029a68a730bf2dbff532379f20 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 21 Aug 2015 11:19:11 -0700 Subject: [PATCH] Add sourceURL comment to all compiled js files --- src/compile-cache.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compile-cache.js b/src/compile-cache.js index 0f2554efb..c30f03105 100644 --- a/src/compile-cache.js +++ b/src/compile-cache.js @@ -61,7 +61,7 @@ function compileFileAtPath (compiler, filePath, extension) { var cachePath = compiler.getCachePath(sourceCode, filePath) var compiledCode = readCachedJavascript(cachePath) if (compiledCode == null) { - compiledCode = compiler.compile(sourceCode, filePath) + compiledCode = addSourceURL(compiler.compile(sourceCode, filePath), filePath) writeCachedJavascript(cachePath, compiledCode) } return compiledCode @@ -84,6 +84,12 @@ function writeCachedJavascript (relativeCachePath, code) { fs.writeFileSync(cachePath, code, 'utf8') } +function addSourceURL (jsCode, filePath) { + if (process.platform === 'win32') + filePath = '/' + path.resolve(filePath).replace(/\\/g, '/') + return jsCode + '\n' + '//# sourceURL=' + encodeURI(filePath) + '\n' +} + var INLINE_SOURCE_MAP_REGEXP = /\/\/[#@]\s*sourceMappingURL=([^'"\n]+)\s*$/mg require('source-map-support').install({