Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jsio require preprocessor
var importExpr = /^(\s*)(import\s+[^=+*"'\r\n;\/]+|from\s+[^=+"'\r\n;\/]+)(;|\/|$)/gm;
function replaceImport(raw, p1, p2, p3) {
if (!/\/\//.test(p1)) {
return p1 + 'jsio(\'' + p2 + '\')' + p3;
}
return raw;
}
var requireExpr = /^(.*)require\(['"]([^=+*"'\r\n;]+)['"]\)(;|\/|$)/gm;
function replaceRequire(raw, p1, p2, p3) {
if (!/\/\//.test(p1)) {
return p1 + 'jsio(\'' + p2 + '\')' + p3;
}
return raw;
}
exports = function (path, moduleDef, opts) {
moduleDef.src = moduleDef.src.replace(importExpr, replaceImport);
moduleDef.src = moduleDef.src.replace(requireExpr, replaceRequire);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.