From 3277db4494d4a1ff2e866f8c32d28d32a6612a4e Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 2 Feb 2017 00:24:04 +0100 Subject: [PATCH] Added support for import 'file' Support for importing modules without accessing anything out of them ``` import 'module-name' ``` or ``` import './file.js' ``` --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 791265b..9de12f0 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ var hook = require('node-hook'); hook.hook('.js', (src, name) => { src = src.replace(/import ([^{]*?) from '(.*?)'/g, 'const $1 = require("$2")'); + src = src.replace(/import '(.*?)'/g, 'require("$1")'); src = src.replace(/export default ([^ ]*)/g, 'module.exports = $1'); src = src.replace(/export (var|let|const) ([a-zA-Z0-9_$]*)/g, '$1 $2 = module.exports.$2'); src = src.replace(/export function ([a-zA-Z0-9_$]*)/g, 'var $1 = module.exports.$1 = function'); @@ -12,4 +13,4 @@ hook.hook('.js', (src, name) => { .join(''); }); return src; -}); \ No newline at end of file +});