私が取り組むツールは、プログラムでBabelを使用しています。プラグインはほとんど必要なく、すべて正常に動作します。Babelのトランスフォーム/プラグインにプログラムでオプションを渡す方法は?
Tho、私はBabel変換にオプションを渡したいと思います。私はまだそれをやっていないことに気づき、私が試みているものがうまくいかないように見える。
具体的には、babel-transform-strict-mode
を含め、strict:false
を渡してグローバル厳密モードを無効にします。私は私のコードで
// with options
{
"plugins": [
["transform-strict-mode", {
"strict": true
}]
]
}
:
ドキュメントが.babelrc
ファイルを持つときにそれを使用する方法について説明し
const babelify = require("babelify")
, es2015 = require("babel-preset-es2015")
, reactify = require("babel-preset-react")
, strictMode = require("babel-plugin-transform-strict-mode")
;
...
this.browserify.transform(babelify, {
global: true,
babelrc: false,
presets: [
reactify
, es2015
, [
strictMode
, { strict: false }
]
]
});
es2015
ながらpresets
配列に大きなreactify
仕事、strictMode
を追加{ strict: false }
で動作しません。
エラーがある:私は代わりにstrictMode
の変換名(["transform-strict-mode", { strict: false }]
)を使用している場合、これは別のモジュールの一部であるため
ReferenceError: [BABEL] /home/.../index.js: Unknown option: foreign.visitor.
Check out http://babeljs.io/docs/usage/options/ for more
information about options.
A common cause of this error is the presence of a
configuration options object without the corresponding
preset name. Example:
Invalid:
`{ presets: [{option: value}] }`
Valid:
`{ presets: [['presetName', {option: value}]] }`
For more detailed information on preset configuration,
please see
http://babeljs.io/docs/plugins/#pluginpresets-options.
、それは、明らかに、モジュールを見つけることができません。
require
モジュール(この場合はstrictMode
)には、プログラムで(babelrc
なし)オプションを渡すにはどうすればよいですか?
ああ、それは面白いです。だから、私はfooを "foo"からもうインポートできなくなるでしょうか?私は[this plugin](https://github.com/genify/babel-plugin-transform-remove-strict-mode)を使用して終了しました。これはおそらくそれが単に厳格な "; use"を削除するだけです。ありがとう! –
これはオプションです。あなたのコードはもはや仕様に準拠していないことに留意してください。そうすればES6モジュールをNodeに置いてから使用したい場合、CommonJSを使用せずにこの問題に直面して修正する方法がありません。 – loganfsmyth
'if(this._){...}'をチェックしていたのに 'this'が' undefined'だったので、クライアント側でいくつかのライブラリ(例えば 'アンダースコア')を使っていくつかの問題があっただけです。 。 –