配置
module.exports = {
//...
optimization: {
usedExports: false
}
}
告诉webpack确定每个模块的使用的导出。收集的导出信息会被其它optimizations选项或者代码生成工具使用。例如js压缩工具移除未使用的导出代码。
可选值为 boolean
boolean = true
设置为true后,可以看到模块上边有
/! export decrement [provided] [unused] [renamed to Mj] /
/! export increment [provided] [used] [renamed to nP] /
这些注释信息。
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ([
/* 0 */,
/* 1 */
/*!**********************!*\
!*** ./increment.js ***!
\**********************/
/*! default exports */
/*! export decrement [provided] [unused] [renamed to Mj] */
/*! export increment [provided] [used] [renamed to nP] */
/*! export incrementBy2 [provided] [unused] [renamed to pN] */
/*! other exports [not provided] [unused] */
/*! runtime requirements: __webpack_require__, __webpack_exports__ */
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
var __webpack_unused_export__;
const add = __webpack_require__(/*! ./math */ 2)/* .add */ .I;
exports.nP = function increment(val) {
return add(val, 1);
};
__webpack_unused_export__ = function incrementBy2(val) {
return add(val, 2);
};
__webpack_unused_export__ = function decrement(val) {
return add(val, 1);
};
/***/ }),
/* 2 */
/*!*****************!*\
!*** ./math.js ***!
\*****************/
/*! default exports */
/*! export add [provided] [used] [renamed to I] */
/*! export multiply [provided] [unused] [renamed to J] */
/*! other exports [not provided] [unused] */
/*! runtime requirements: __webpack_exports__ */
/***/ ((__unused_webpack_module, exports) => {
var __webpack_unused_export__;
exports.I = function add() {
var sum = 0,
i = 0,
args = arguments,
l = args.length;
while (i < l) {
sum += args[i++];
}
return sum;
};
__webpack_unused_export__ = function multiply() {
var product = 0,
i = 0,
args = arguments,
l = args.length;
while (i < l) {
sum *= args[i++];
}
return sum;
};
/***/ })
/******/ ]);