Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
babel-preset-browser
Advanced tools
面向IE6+浏览器的使用AMD
模块的Babel6预设。
$ npm install --save-dev babel-preset-browser
通过.babelrc
(推荐)
{
"presets": ["browser"]
}
通过命令行
$ babel script.js --presets browser
这一部分主要介绍本预设使用的ES特性和相关插件配置。
以下两个插件用于解决ES3浏览器不支持使用关键字(如:default
)作为属性名的问题。
翻译思路是将ES5代码翻译为ES3支持的代码。
本预设从ES2015预设中选择了以下几个插件:
loose
模式。eval
中的常量。spec
模式以简化转换后的代码,因此要避免对使用箭头函数使用new/call/apply
,以免发生错误。let/const
声明块级函数。transform-class-properties
一共使用,以实现完整的类定义模型。在旧浏览器中不支持Getter/Setter
机制,因此使用loose
模式。Getter/Setter
机制,因此请不要使用Getter/Setter
以免出现运行时错误。const
变量有没有被赋值。tdz
属性,变量的作用域为当前块。以下插件或者功能没有被选择:
Object.getPrototypeOf
,所以不支持。for-of-array
功能。Symbol
。AMD
模块。Generator
。以下第三方插件用于补足功能:
AMD
模型,与标准版的区别是通过缩减ES6代码的功能,以满足AMD
规范。for-of
循环,不考虑任何迭代器,将所有对象当作数组或者类数据处理。以下未定稿但比较稳定的插件并加入到预设中:
transform-modules-amd
中引入,无需重复。这三个插件主要是对ES2015缺失的功能进行一些补充,以保证特征的完整性。
以下插件没有补添加但是推荐单独引入:
**
符号。::
运算符,需要可以加入。do
运算符号,可以在表达式中添加代码块,不是很符合JS的思路,没有直接加入。这四个插件属于ES7提供的新语法糖
以下插件因浏览器原因不应当被引入:
Generator
。以下插件已经被babel废弃,或者有没完整的实现,尽量避免使用:
FAQs
babel preset for old IEs and `AMD` modules
The npm package babel-preset-browser receives a total of 3 weekly downloads. As such, babel-preset-browser popularity was classified as not popular.
We found that babel-preset-browser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.