Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit aa8d498

Browse files
committed
add support for Webpack v1 bundles
1 parent 39bb2ca commit aa8d498

3 files changed

Lines changed: 45 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $ npm install moduleraid
1313
Or if you directly want to use it in the browser
1414

1515
```html
16-
<script src="https://unpkg.com/moduleraid@1.0.0/moduleraid.js"></script>
16+
<script src="https://unpkg.com/moduleraid@2.0.0/moduleraid.js"></script>
1717
```
1818

1919
Alternatively, just copy the script from `moduleraid.js` and run it in a devtool console
@@ -61,7 +61,7 @@ on `undefined`), and now we have all modules (_or most of them_)!
6161

6262
## Known Issues
6363

64-
* It crashes if `webpackJsonp` is not existing
64+
* Doesn't work with Webpack 3
6565
* There seem to be a lot of empty modules, I'm not sure if these are _padding_ or something is missing here
6666

6767
## License

moduleraid.js

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,56 @@
99
const moduleRaid = function () {
1010
mArr = [];
1111

12-
mEnd = false;
13-
mIter = 0;
14-
15-
while (!mEnd) {
16-
try {
17-
mArr[mIter] = webpackJsonp([],[],[mIter]);
18-
mIter++;
12+
getWebpackVersion = function() {
13+
switch(webpackJsonp.length) {
14+
case 2:
15+
return 1;
16+
case 3:
17+
return 2;
1918
}
20-
catch (err) {
21-
mEnd = true
19+
}
20+
21+
fillModuleArray = function(mArr, version) {
22+
switch(version) {
23+
case 1:
24+
webpackJsonp([0], [function(e,t,i) {
25+
mCac = i.c;
26+
Object.keys(mCac).forEach(function(mod) {
27+
mArr[mod] = mCac[mod].exports;
28+
})
29+
}]);
30+
break;
31+
case 2:
32+
mEnd = false;
33+
mIter = 0;
34+
35+
if (!webpackJsonp([],[],[mIter])) {
36+
throw 'Unknown Webpack structure';
37+
}
38+
39+
while (!mEnd) {
40+
try {
41+
mArr[mIter] = webpackJsonp([],[],[mIter]);
42+
mIter++;
43+
}
44+
catch (err) {
45+
mEnd = true;
46+
}
47+
}
48+
break;
49+
default:
50+
throw 'Unknown Webpack version';
2251
}
2352
}
2453

54+
fillModuleArray(mArr, getWebpackVersion())
55+
2556
get = function get (id) {
2657
return mArr[id]
2758
}
2859

2960
findModule = function findModule (query) {
30-
results = []
61+
results = [];
3162

3263
mArr.forEach(function(mod) {
3364
if (typeof mod.default === "object") {
@@ -41,7 +72,7 @@ const moduleRaid = function () {
4172
}
4273
})
4374

44-
return results
75+
return results;
4576
}
4677

4778
return {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "moduleraid",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "Get modules from webpackJsonp",
55
"main": "moduleraid.js",
66
"scripts": {

0 commit comments

Comments
 (0)