私はバベルを学ぼうとしています。babel-coreモジュールを動作させましたが、使用しようとしていますが.babelrc
、何も実行されません。
これが私の.babelrc
ファイルです。
{
"plugins":["transform-es3-property-literals"]
}
そして、これが私のコードです:
var babel = require("babel-core");
var js = `var x = { catch: 4, bar: 7 };`;
var notUsingBabelRc = babel.transform(js,{
plugins: ["transform-es3-property-literals"]
}).code;
var usingBabelRc = babel.transform(js).code
console.log(notUsingBabelRc == usingBabelRc);
//false, but should be true. Adding plugins as an option transforms the code.
console.log(usingBabelRc == js);
//true, but should be false. The code is not changed from its original form.
.babelrc
プロジェクトのルートディレクトリにファイルがあります。using_babelrc.js
プロジェクトのルートディレクトリと呼ばれるスクリプトファイルもあります。
それから私は電話をしnode using_babelrc
、私がfalse true
期待しているのに私は得るtrue false
。
私が見逃している簡単なことは何ですか?
このtransform
関数には、そのファイル名に関連するファイルのfilename
検索を開始するために提供されたオプションも必要.babelrc
です。あなたの場合:
babel.transform(js, {filename: "using_babelrc.js"}).code;
と同じフォルダにある設定ファイルを読み取りますusing_babelrc.js
。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加