【发布时间】:2018-10-03 06:42:12
【问题描述】:
使用@babel/cli 使用以下命令转译代码:
babel --plugins @babel/plugin-transform-arrow-functions www/js/origin.js --out-file www/js/result.js
生成一个文件,该文件需要从我的计算机使用绝对路径导入。当然,在服务器上运行它会因为找不到路径而中断。
这里是一个绝对导入的例子:
import _slicedToArray from "/Users/myself/project/node_modules/@babel/runtime/helpers/builtin/es6/slicedToArray";
import _createClass from "/Users/myself/project/node_modules/@babel/runtime/helpers/builtin/es6/createClass";
import _inherits from "/Users/myself/project/node_modules/@babel/runtime/helpers/builtin/es6/inherits";
import _possibleConstructorReturn from "/Users/myself/project/node_modules/@babel/runtime/helpers/builtin/es6/possibleConstructorReturn";
import _getPrototypeOf from "/Users/myself/project/node_modules/@babel/runtime/helpers/builtin/es6/getPrototypeOf";
import _classCallCheck from "/Users/myself/project/node_modules/@babel/runtime/helpers/builtin/es6/classCallCheck";
import _typeof from "/Users/myself/project/node_modules/@babel/runtime/helpers/builtin/es6/typeof";
转译后的文件有什么办法可以内联包含它需要的所有内容吗?
目前我没有使用任何特定的babel.config.js 或babelrc 文件。
【问题讨论】:
-
你必须在某个地方有一个 babelrc,无论是
.babelrc文件、.babelrc.js文件还是package.json#babel字段,因为这些导入是你必须通过@babel/plugin-transform-runtime模块选择加入的.它可能在某个父文件夹中。 -
使用 --no-babelrc 产生相同的结果。我们试图删除使用 @vue/app 预设的 babel.config.js,但它并没有改变。
-
嗯,我不确定。你能做一个可重现的例子吗?肯定有一些其他插件从某个地方加载。
-
我遇到了同样的问题。你想出解决方案了吗?
-
没有。没有找到解决办法
标签: javascript babeljs