primus / deumdify

Browserify plugin to expose a standalone bundle as a property of the global object.
MIT License
15 stars 2 forks source link

CommonJS support #45

Open heri16 opened 6 years ago

heri16 commented 6 years ago

Is there a plugin/flag that does similar to this but leaves only CommonJS support?

lpinca commented 6 years ago

I didn't test but this patch should work:

$ git diff
diff --git a/index.js b/index.js
index fd023f9..686b3f3 100644
--- a/index.js
+++ b/index.js
@@ -22,25 +22,11 @@ function prune(code) {

   estraverse.replace(ast, {
     leave: function leave(node, parent) {
-      var ret;
-
-      if ('IfStatement' === node.type) {
-        if ('BinaryExpression' !== node.test.type) return;
-
-        if ('self' === node.test.left.argument.name) {
-          node.alternate = null;
-        } else if ('global' === node.test.left.argument.name) {
-          ret = node.alternate;
-        }
-
-        return ret;
-      }
-
       if (
           'BlockStatement' === node.type
         && 'FunctionExpression' === parent.type
       ) {
-        return node.body[0].alternate.alternate;
+        return node.body[0].consequent;
       }
     }
   });

Anyway I think it's out of the scope of this module.