-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export format options, accept different import formats, fixes #63 #64
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ module.exports = function (content) { | |
var pathSep = options.pathSep || '/'; | ||
var resource = this.resource; | ||
var pathSepRegex = new RegExp(escapeRegExp(path.sep), 'g'); | ||
var exportAsEs6Default = options.exportAsEs6Default; | ||
var exportAsDefault = options.exportAsDefault; | ||
|
||
// if a unix path starts with // we treat is as an absolute path e.g. //Users/wearymonkey | ||
// if we're on windows, then we ignore the / prefix as windows absolute paths are unique anyway e.g. C:\Users\wearymonkey | ||
|
@@ -45,19 +47,26 @@ module.exports = function (content) { | |
.replace(new RegExp(escapeRegExp(pathSep) + '+', 'g'), pathSep); | ||
var html; | ||
|
||
if (content.match(/^module\.exports/)) { | ||
if (content.match(/(?:^module\.exports)|(?:^export\s+default)|(?:^exports.default)/)) { | ||
var firstQuote = findQuote(content, false); | ||
var secondQuote = findQuote(content, true); | ||
html = content.substr(firstQuote, secondQuote - firstQuote + 1); | ||
} else { | ||
html = content; | ||
} | ||
|
||
var exportsString = "module.exports = "; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would a simpler solution be to just keep the same export expression of the content? That way only I'm thinking something like:
The README change would also then not be required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works for me! |
||
if (exportAsDefault) { | ||
exportsString = "exports.default = "; | ||
} else if (exportAsEs6Default) { | ||
exportsString = "export default "; | ||
} | ||
|
||
return "var path = '"+jsesc(filePath)+"';\n" + | ||
"var html = " + html + ";\n" + | ||
(requireAngular ? "var angular = require('angular');\n" : "window.") + | ||
"angular.module('" + ngModule + "').run(['$templateCache', function(c) { c.put(path, html) }]);\n" + | ||
"module.exports = path;"; | ||
exportsString + " path;"; | ||
|
||
function getAndInterpolateOption(optionKey, def) { | ||
return options[optionKey] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/^(module\.exports|export\s+default|exports.default)/
is a bit easier to read.