修改自 [https://github.com/1egoman/debundle](https://github.com/1egoman/debundle)
npm install @hectorqin/debundle修改自 https://github.com/1egoman/debundle
升级了依赖,修改了部分兼容问题,还有其它bug,但是能跑通了,支持es6语法。不保证拆分文件的完整性和准确性,==
``bash`
npm i -g @hectorqin/debundle
`bash
$ debundle
Usage: debundle [input file] {OPTIONS}
Options:
--input, -i Bundle to debundle
--output, -o Directory to debundle code into.
--config, -c Configuration file
$ curl https://raw.githubusercontent.com/hectorqin/debundle/master/test_bundles/browserify/bundle.js > bundle.js
$ curl https://raw.githubusercontent.com/hectorqin/debundle/master/test_bundles/browserify/debundle.config.json > debundle.config.json
$ cat debundle.config.json
{
"type": "browserify",
"knownPaths": {}
}
$ debundle -i bundle.js -o dist/ -c debundle.config.json
$ tree dist/
dist/
├── index.js
└── node_modules
├── number
│ └── index.js
└── uuid
├── index.js
├── lib
│ ├── bytesToUuid.js
│ └── rng.js
├── v1.js
└── v4.js
4 directories, 7 files
`
`json`
{
"type": "browserify",
"entryPoint": 1,
"knownPaths": {}
}
(To debundle a simple Webpack bundle, replace browserify the above configuration with webpack)
A configuration can have a number of flags - they are documented in DOCS.md.
No. There a bunch of metadata that's lost when bundling:
- Any custom package.json settings for each node_module and the root package.1.js
- In a webpack bundle, the names of modules aren't in the bundle. By default, debundling will produce
files named after the module id (ie, ) unless manually overridden.
- If your code was minified, the output files from the debundling process will also be minified (ie,
no whitespace, single letter variables, etc). It's up to you to run source through other tools to
make it look nicer.
- Make sure that either when rebundling or running with node that you're using the correct file as
your entrypoint.
- Read through all the configuration options. Some of them have caveats.
- You could have run into an edge case that I haven't seen yet. Feel free to open an issue if you believe that to be the case.
Not officially. However, if a bundle shares the same type module layout as Browserify or Webpack it
may be possible to set the moduleAst
configuration option to point to the location of the modules.
- After cloning down the project, run npm install - that should be it../src/index.js
- Debundler entry point is (that's how you run it!)test_bundles/
- A bunch of sample bundles are in . A script, test_bundles/run_test.sh can run thedist/
debundler against a given bundle and try to debundle it into . (CI will, as part of runningnpm test`
tests, debundle all the bundles in that folder.)
- Make sure any contribution pass the tests:
Some companies specify in their terms of service that their code cannot be "reverse engineered".
Debundling can definitely (depending on how you're using the code) fall under that umbrella.
Understand what you are doing so you don't break any agreements :smile: