在babel 6中使用es2015预置时是否有使用松散模块的方法?

时间:2021-08-09 15:45:17

I tried to use following babelrcs:

我尝试使用以下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 个解决方案

#1


3  

I ended up creating a preset es2015-mod for this same purpose - an exact copy of Babel's es2015 with loose modules enabled.

最后,我为这个目标创建了一个preset es2015-mod——这是Babel的es2015的一个精确副本,其中启用了松散的模块。

#2


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.

通过启用es2015,您需要的是非松散模式模块。如果您想要在Babel v6中使用松散的模块模式(至少目前是这样),您需要显式地列出您希望使用的插件,列出所有2015年的部分。

#3


1  

babel-preset-es2015-loose package has been deprecated. With babel-preset-es2015 v6.13.0+, you can now configure your .babelrc like so:

babel-preset-es2015-loose包已被弃用。使用babel-preset-es2015 v6.13.0+,您现在可以配置您的.babelrc:

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

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

#4


1  

For me it was an old babel-core version. You need at least 6.13+

对我来说,这是一个古老的巴伯核心版本。你至少需要6.13+。

#5


0  

NEW: Using es2015-loose preset

es2015-loose is a preset that uses modify-babel-preset to modify es2015 preset and enable loose mode where available.

es2015-loose是一个使用modify-babel-preset修改es2015预设置并启用松散模式的预置。

Use it like that:

这样使用它:

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

Make sure to install both es2015 and es2015-loose packages:

确保安装es2015和es2015-loose包:

$ npm install --save-dev babel-preset-es2015-loose babel-preset-es2015

PS: There are other loose presets for example if you target node versions >= 4 you can use es2015-node4-loose preset.

还有其他一些松散的预置,例如,如果您的目标节点版本>= 4,您可以使用es2015-node4-松散预置。

#1


3  

I ended up creating a preset es2015-mod for this same purpose - an exact copy of Babel's es2015 with loose modules enabled.

最后,我为这个目标创建了一个preset es2015-mod——这是Babel的es2015的一个精确副本,其中启用了松散的模块。

#2


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.

通过启用es2015,您需要的是非松散模式模块。如果您想要在Babel v6中使用松散的模块模式(至少目前是这样),您需要显式地列出您希望使用的插件,列出所有2015年的部分。

#3


1  

babel-preset-es2015-loose package has been deprecated. With babel-preset-es2015 v6.13.0+, you can now configure your .babelrc like so:

babel-preset-es2015-loose包已被弃用。使用babel-preset-es2015 v6.13.0+,您现在可以配置您的.babelrc:

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

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

#4


1  

For me it was an old babel-core version. You need at least 6.13+

对我来说,这是一个古老的巴伯核心版本。你至少需要6.13+。

#5


0  

NEW: Using es2015-loose preset

es2015-loose is a preset that uses modify-babel-preset to modify es2015 preset and enable loose mode where available.

es2015-loose是一个使用modify-babel-preset修改es2015预设置并启用松散模式的预置。

Use it like that:

这样使用它:

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

Make sure to install both es2015 and es2015-loose packages:

确保安装es2015和es2015-loose包:

$ npm install --save-dev babel-preset-es2015-loose babel-preset-es2015

PS: There are other loose presets for example if you target node versions >= 4 you can use es2015-node4-loose preset.

还有其他一些松散的预置,例如,如果您的目标节点版本>= 4,您可以使用es2015-node4-松散预置。