Skip to content

Commit f844d30

Browse files
committed
update
1 parent 1156929 commit f844d30

File tree

2 files changed

+51
-52
lines changed

2 files changed

+51
-52
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cd code/xxxx/
2222
#### | 前端工程化
2323

2424
* [前端代码异常监控实战](https://github.com/happylindz/blog/issues/5)
25+
* [深入理解 webpack 文件打包机制](https://github.com/happylindz/blog/issues/6)
2526

2627
#### | ES6
2728

markdown/webpack-bundle-analysis.md

+50-52
Original file line numberDiff line numberDiff line change
@@ -441,31 +441,31 @@ __webpack_require__.e = function requireEnsure(chunkId) {
441441
var promise = new Promise(function(resolve, reject) {
442442
installedChunkData = installedChunks[chunkId] = [resolve, reject];
443443
});
444-
installedChunkData[2] = promise;
445-
// start chunk loading
446-
var head = document.getElementsByTagName('head')[0];
447-
var script = document.createElement('script');
448-
script.type = 'text/javascript';
449-
script.charset = 'utf-8';
450-
script.async = true;
451-
script.timeout = 120000;
452-
script.src = __webpack_require__.p + "" + chunkId + "." + {"0":"ae9c5f5f","1":"0ac69acb","2":"20651a9c","3":"0cdc6c84"}[chunkId] + ".js";
453-
var timeout = setTimeout(onScriptComplete, 120000);
454-
script.onerror = script.onload = onScriptComplete;
455-
function onScriptComplete() {
456-
// 防止内存泄漏
457-
script.onerror = script.onload = null;
458-
clearTimeout(timeout);
459-
var chunk = installedChunks[chunkId];
460-
if(chunk !== 0) {
461-
if(chunk) {
462-
chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));
463-
}
464-
installedChunks[chunkId] = undefined;
465-
}
466-
};
467-
head.appendChild(script);
468-
return promise;
444+
installedChunkData[2] = promise;
445+
// start chunk loading
446+
var head = document.getElementsByTagName('head')[0];
447+
var script = document.createElement('script');
448+
script.type = 'text/javascript';
449+
script.charset = 'utf-8';
450+
script.async = true;
451+
script.timeout = 120000;
452+
script.src = __webpack_require__.p + "" + chunkId + "." + {"0":"ae9c5f5f","1":"0ac69acb","2":"20651a9c","3":"0cdc6c84"}[chunkId] + ".js";
453+
var timeout = setTimeout(onScriptComplete, 120000);
454+
script.onerror = script.onload = onScriptComplete;
455+
function onScriptComplete() {
456+
// 防止内存泄漏
457+
script.onerror = script.onload = null;
458+
clearTimeout(timeout);
459+
var chunk = installedChunks[chunkId];
460+
if(chunk !== 0) {
461+
if(chunk) {
462+
chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));
463+
}
464+
installedChunks[chunkId] = undefined;
465+
}
466+
};
467+
head.appendChild(script);
468+
return promise;
469469
};
470470
```
471471

@@ -558,33 +558,31 @@ module.exports = {
558558

559559
```javascript
560560
// dist/pageA.xxxx.js
561-
webpackJsonp(
562-
[0],[
563-
function(o, t, e) {
564-
'use strict';
565-
Object.defineProperty(t, '__esModule', { value: !0 });
566-
var n = e(1);
567-
e(2), e(3);
568-
console.log(n.a);
569-
},
570-
function(o, t, e) {
571-
'use strict';
572-
t.a = 'util A';
573-
},
574-
function(o, t, e) {
575-
'use strict';
576-
for (;;);
577-
console.log('never use');
578-
},
579-
function(o, t, e) {
580-
'use strict';
581-
const n = function() {};
582-
n.prototype.saySomething = function() {
583-
console.log('class C');
584-
};
585-
}
586-
],[0]
587-
);
561+
webpackJsonp([0],[
562+
function(o, t, e) {
563+
'use strict';
564+
Object.defineProperty(t, '__esModule', { value: !0 });
565+
var n = e(1);
566+
e(2), e(3);
567+
console.log(n.a);
568+
},
569+
function(o, t, e) {
570+
'use strict';
571+
t.a = 'util A';
572+
},
573+
function(o, t, e) {
574+
'use strict';
575+
for (;;);
576+
console.log('never use');
577+
},
578+
function(o, t, e) {
579+
'use strict';
580+
const n = function() {};
581+
n.prototype.saySomething = function() {
582+
console.log('class C');
583+
};
584+
}
585+
],[0]);
588586
```
589587

590588
引入但是没用的变量,函数都会清除,未执行的代码也会被清除。但是类方法是不会被清除的。因为 webpack 不会区分不了是定义在 classC 的 prototype 还是其它 Array 的 prototype 的,比如 classC 写成下面这样:

0 commit comments

Comments
 (0)