babel编译器导出未定义和实际导出在一起
有人可以解释为什么babel编译以下内容:
import {resolve} from "path"; export const exportedConst = "value";
至:
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.exportedConst = undefined; var _path = require("path"); var exportedConst = exports.exportedConst = "value";
如果我导出了exportedConst
而不导入任何其他模块:
export const exportedConst = "value";
它将其编译为:
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var exportedConst = exports.exportedConst = "value";
为什么会产生这一行? exports.exportedConst = undefined;
并像这样导出
var exportedConst = exports.exportedConst = "value";
这会导致IDE看到两个导出
也许这是智力问题,但这让我想到为什么巴贝尔这样做。
我在用:
- nodejs:v8.5.0
- babel-cli:6.26.0(babel-core 6.26.0)
- babel-preset-env:1.6.1
在这里尝试
或者如果你想在本地重现,这是一个快速的单行命令
mkdir stackoverflow-questin && cd stackoverflow-questin && npm init -y && npm install babel-cli babel-preset-env && echo 'import {resolve} from "path";\nexport const exportedConst = "value";' > index.js && npx babel index.js --out-file index.compiled.js --presets=env
- 如何运行nodejs应用程序作为永远或新贵的服务?
- 您应该通过在Babelconfiguration中使用`env`部分禁用生产中的react-transform-hmr
- 如何用Jest使用babel-preset-env
- 不同的babel预设为后端和前端,但为相同的env
- 在浏览器中使用babel-standalone
- 运行node.js时出现错误与babel“无法find预设”es2015“相对于目录”
- 发布一个需要来自node_modules的CSS的npm包
- 通过browserify reactjs包脚本不工作在客户端(未捕获ReferenceError:组件未定义)
- babel,带有nodemon脚本的webpack?