Unbundeling a pre-built Javascript file built using browserify

431 views Asked by At

I have a third party library, non uglified which was bundled using browserify. Unfortunately the original sources are not available.

Is there a way to unbundled it into different files/sources.

1

There are 1 answers

1
cartant On BEST ANSWER

You should be able to 'unbundle' the pre-built Browserify bundle using browser-unpack.

It will generate JSON output like this:

[
  {
    "id": 1,
    "source": "\"use strict\";\r\nvar TodoActions = require(\"./todo\"); ... var VisibilityFilterActions = require(\"./visibility-filter\"); ...",
    "deps": {
      "./todo": 2,
      "./visibility-filter": 3
    }
  },
  {
    "id": 2,
    "source": "\"use strict\";\r\n ...",
    "deps": {}
  },
  {
    "id": 3,
    "source": "\"use strict\";\r\n ...",
    "deps": {}
  },
  ...
]

It should be reasonably straight-forward to transform the JSON output into source files that can be required. Note that the mappings of require literals (like "./todo") are in the deps. That is, the module required as "./todo" corresponds to the source with an id of 2.

There is also a browserify-unpack tool - which writes the contents as files - but I've not used it.