【发布时间】:2020-06-12 03:00:12
【问题描述】:
从命令行运行npx babel index.js 时,我希望看到我的 babel 配置是从 babel.config.js 应用的
但似乎并非如此,因为想知道为什么会这样?
// babel.config.js
module.exports = function babel(api) {
api.cache(true);
return {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'babel-plugin-root-import',
{
rootPathSuffix: './src',
rootPathPrefix: '~/',
},
],
],
};
};
// index.js
import { AppRegistry } from 'react-native';
import App from '~/App';
AppRegistry.registerComponent("App Name", () => App)
// Expected output from npx babel index.js
import { AppRegistry } from 'react-native';
import App from './src/App'; // Note the change from '~' to './src' using babel-plugin-root-import
AppRegistry.registerComponent("App Name", () => App)
我在 npx babel --help 中注意到它指出 --no-babelrc 标志忽略来自 .babelrc 和 .babelignore 文件的配置。这是否表明调用此命令时不考虑 babel.config.js 文件?
干杯
【问题讨论】:
-
通天塔版本?
-
npx babel --version给了 6.26.0 (babel-core 6.26.3)
标签: javascript react-native babeljs npx babel-cli