A .NET tool that searches and extracts Webpack chunk loaders from .js files.
The extractor supports:
- Chunk loader that uses an object expression (e.g.,
{100: "chunk1", 101: "chunk2"}[e] + ".js") - Chunk loader that uses
ifstatements (e.g.,if (100 === e) return "chunk.js") - Chunk loader that uses ternary operator (
?:) (e.g.,100 === e ? "chunk.js" : ...) - Chunk loader that uses
switchstatement (e.g.,switch (e) { case 100: return "chunk.js" }) - Chunk loader that uses array lookup (e.g.,
["chunk1.js", "chunk2.js"][e])
For an overview of how this works read DOC.md.
Note: I don't intend to continue developing this tool any further, as there are better alternatives available, such as jxscout. This project began as a research experiment to explore chunk detection algorithms, and it's reached its conclusion.
Build with .NET.
dotnet publish src/WpkSnoop.Cli/WpkSnoop.Cli.csproj -c Release -o .
You might receive some JINT warning when compiling as native AOT but the tool seems to work fine after some testing.
Description:
Webpack Chunk Loader Extractor
Usage:
wpksnoop <path> [options]
Arguments:
<path> Path to the JS file containing the chunk loader
Options:
-d, --dir Specifies that the path is a directory path
-v, --verbose Specifies verbose output
-H, --header <header> Specifies the HTTP headers for chunk file GET requests
-D, --domain <domain> Specifies the base URL for chunk file GET requests
-x, --proxy <proxy> Specifies the proxy URL for chunk file GET requests
-k, --insecure Specifies to not validate HTTPS certificates for chunk file GET requests
-t, --threads <threads> Specifies the number of threads to use [default: 2147483647]
--version Show version information
-?, -h, --help Show help and usage information
Sample JS files can be found under tests/WpkSnoop.Core.Test/Samples/. They are used to test different chunk loaders generated by Webpack.
wpksnoop tests/WpkSnoop.Core.Test/Samples/small.js
wpksnoop -d tests/WpkSnoop.Core.Test/Samples/
Used to send all the found chunk loader entries to a site.
wpksnoop tests/WpkSnoop.Core.Test/Samples/small.js -D 'https://example.com/chunks/'
The chunk loader entries can also go through a proxy, useful for using tools like burp.
wpksnoop tests/WpkSnoop.Core.Test/Samples/small.js -v -D 'https://example.com/chunks/' -x 'http://localhost:8080'
HTTP headers can be added by using -H.
wpksnoop tests/WpkSnoop.Core.Test/Samples/small.js -v -D 'https://example.com/chunks/' -H 'Cookie: 1' -H 'Cookie: 2'
Sample Webpack project used for testing can be found under webpack/. Generate Webpack files by:
cd webpack
npm install
npm run build
The generated Webpack files will be under webpack/dist/.
See issues.