{"id":19545192,"url":"https://github.com/scscms/es6","last_synced_at":"2025-02-26T05:42:55.524Z","repository":{"id":93554748,"uuid":"53043535","full_name":"scscms/es6","owner":"scscms","description":null,"archived":false,"fork":false,"pushed_at":"2016-11-03T08:39:17.000Z","size":2323,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-08T19:24:06.022Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scscms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-03T10:58:06.000Z","updated_at":"2019-07-03T01:16:07.000Z","dependencies_parsed_at":"2023-10-02T08:02:59.365Z","dependency_job_id":null,"html_url":"https://github.com/scscms/es6","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scscms%2Fes6","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scscms%2Fes6/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scscms%2Fes6/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scscms%2Fes6/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scscms","download_url":"https://codeload.github.com/scscms/es6/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240801040,"owners_count":19859727,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T03:36:22.967Z","updated_at":"2025-02-26T05:42:55.469Z","avatar_url":"https://github.com/scscms.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel编译ES6\u003csup\u003eshine\u003c/up\u003e\nECMAScript 6(ES6) 的发展或者说普及之快可以说是难以想象的，对很多人来说 ECMAScript 5(ES5) 都还普及呢。现代浏览器对 ES6 新特新或多或少的有些支持，但支持度不高，所以要想在浏览器中直接使用 ES6 的新特性，还得等上一段时间。\n对 ES6 的普及起到至关重要的就不得不说 babel 了。 babel 可以将 ES6 代码完美地转换为 ES5 代码，所以我们不用等到浏览器的支持就可以在项目中使用 ES6 的特性。 \n### 安装babel\n```JavaScript\n$ npm install -g babel\n```\n一般来说安装node模块，使用官网速度比较慢，所以建议使用淘宝滤镜文件。\n```JavaScript\n$ npm install -g babel --registry=https://registry.npm.taobao.org\n```\n### 测试编译\n```JavaScript\n$ babel es6.js\n```\n提示错误：\n```JavaScript\nThe CLI has been moved into the package `babel-cli`.\nnpm install -g babel-cli\n```\n要求安装babel-cli,那么你就安装呗：\n```JavaScript\n$ npm install -g babel-cli\n```\n或者提示：\n```JavaScript\nYou have mistakenly installed th `babel` packge, which is a no-op in Babel ......\n    npm uninstall babel\n    npm install babel-cli\nSee http://babeljs.io/docs/usage/cli/ for setup instructions.\n```\n意思要求删除babel直接安装babel-cli，那么请直接执行：\n```JavaScript\n$ npm uninstall babel\n$ npm install -g babel-cli --registry=https://registry.npm.taobao.org\n```\n### 再次测试编译\n```JavaScript\n$ babel es6.js\n```\n输出仍是ES6源码！玛尼？\n原来是没有安装babel-preset-es2015插件，再安装吧：\n```JavaScript\n$ npm install babel-preset-es2015 --registry=https://registry.npm.taobao.org\n```\n然后执行：\n```JavaScript\n$ babel es6.js --presets es2015\n```\n终于可以啦。\n### 编译成文件\n编译单人文件为ES5\n```JavaScript\n$ babel es6.js --presets es2015 -o es5.js\n  # 或者\n$ babel es6.js --presets es2015 --out-file es5.js\n```\n也可以整个文件夹编译，es6文件所有文件编译到es5文件夹下：\n```JavaScript\n$ babel es6/ --presets es2015 -d es5/\n# 或者\n$ babel es6/ --out-dir es5/\n```\n整个文件夹编译到一个js文件里：\n```JavaScript\n$ babel es6/ --out-file es5.js\n```\n### 编译同时生成源文件\n```JavaScript\n$ babel script.js --out-file script-compiled.js --source-maps\n# 或\n$ babel script.js -o script-compiled.js --s\n```\n如果你想生成只有一行的文件，可使用inline参数：\n```JavaScript\n$ babel script.js --out-file script-compiled.js --source-maps inline\n```\n### 实时编译文件\n```JavaScript\n$ babel --watch es6.js --out-file es5.js \n```\n--watch命令即开启监听文件编辑功能，只要有修改就会同步编译好。那你就可以即时看到效果了。\n如果要强制退出就安Ctrl+C键退出。\n\n[babel视频](http://ninghao.net/video/3076) ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscscms%2Fes6","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscscms%2Fes6","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscscms%2Fes6/lists"}