Created
April 13, 2016 20:18
-
-
Save TheLarkInn/774289cfed6909143a31d99bd19a55c2 to your computer and use it in GitHub Desktop.
convertES6StyleAndHTMLImportsToTypeScriptFriendlyRequires.js
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
module.exports = function convertES6StyleAndHTMLImportsToTypeScriptFriendlyRequires(source) { | |
this.cacheable && this.cacheable(); | |
var hasES6StyleAndHTMLImportRegex = new RegExp(/import\s+(.+)\s+from\s+([\'|\"].+\.(html|jade|haml|twig|erb|css|scss|less|yaml|sass|styl)[\'\"]);?/, 'g'); | |
var results; | |
try { | |
results = source.replace(hasES6StyleAndHTMLImportRegex, | |
"let $1 = require($2);\n" | |
); | |
} catch(e) { | |
var err = ""; | |
if (e.location == null || e.location.first_column == null || e.location.first_line == null) { | |
err += "Template Loader Error. The original exception was: " + e + "\n"; | |
} else { | |
err += "ERROR ERROR ERROR ERROR"; | |
} | |
throw new Error(err); | |
} | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment