为什么babel-plugin-transform-modules-commonjs选项noInterop不会删除__esModule属性?

时间:2019-07-04 15:40:04

标签: babeljs

import PI from "./pi";

export function surface(radius) {
  return PI * radius * radius / 2.0;
}

编译为:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.surface = surface;

var _pi = _interopRequireDefault(require("./pi"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function surface(radius) {
  return _pi.default * radius * radius / 2.0;
}

如果将noInterop选项设置为true。生成的新代码为:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.surface = surface;

var _pi = require("./pi");

function surface(radius) {
  return _pi.default * radius* radius/ 2.0;
} 

为什么Object.defineProperty调用仍然存在?

0 个答案:

没有答案