Is there a way to use loose modules when using es2015 preset in babel 6?

时间:2015-10-30 23:30:58

标签: babeljs

I tried to use following babelrcs: { "presets": [ ["es2015", { "transform-es2015-modules-commonjs": { "loose": true } }] ] } fails with "Invalid options type for foreign" { "presets": ["es2015"], "plugins": [ ["transform-es2015-modules-commonjs", { "loose": true }] ] } ignores the "loose" option { "plugins": [ ["transform-es2015-modules-commonjs", { "loose": true }] ] } does not use the preset

5 个答案:

答案 0 :(得分:4)

By enabling es2015, you are asking for non-loose-mode modules. If you want loose module modes in Babel v6 (at least at the moment), you would need to explicitly list the plugins you wish to use by listing everything that is part of es2015.

答案 1 :(得分:3)

我最终为此目的创建了预设es2015-mod - 启用了松散模块的Babel es2015的精确副本。

答案 2 :(得分:1)

babel-preset-es2015-loose package has been deprecated。使用babel-preset-es2015 v6.13.0 +,您现在可以像这样配置.babelrc

{ presets: [ ["es2015", {"loose": true}] ] }

答案 3 :(得分:1)

对我而言,这是一个旧的babel-core版本。您至少需要6.13+

答案 4 :(得分:0)

新:使用es2015-loose preset

es2015-loose是一个预设,使用modify-babel-preset修改es2015预设并启用loose mode

使用它:

INSERT INTO upsert_table VALUES (2, 2, 'inserted')
   ON CONFLICT ON CONSTRAINT upsert_table_sub_id_key
   DO UPDATE SET status = 'upserted' RETURNING *;

 id | sub_id |  status
----+--------+----------
  2 |      2 | upserted
(1 row)

确保同时安装es2015es2015-loose个包:

{
  "presets": ["es2015-loose"]
}

PS:还有其他松散的预设,例如,如果您定位节点版本> = 4,则可以使用es2015-node4-loose预设。