{"id":13446992,"url":"https://github.com/babel/babelify","last_synced_at":"2026-04-06T03:36:11.890Z","repository":{"id":21516348,"uuid":"24835467","full_name":"babel/babelify","owner":"babel","description":"Browserify transform for Babel","archived":false,"fork":false,"pushed_at":"2021-08-06T15:16:27.000Z","size":224,"stargazers_count":1677,"open_issues_count":12,"forks_count":114,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-05-08T01:25:59.927Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/babel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["babel"],"open_collective":"babel","custom":"https://gitcoin.co/grants/2906/babel-compiler-for-next-generation-javascript"}},"created_at":"2014-10-06T05:59:09.000Z","updated_at":"2025-05-05T21:59:00.000Z","dependencies_parsed_at":"2022-08-22T21:41:03.223Z","dependency_job_id":null,"html_url":"https://github.com/babel/babelify","commit_stats":null,"previous_names":["sebmck/6to5-browserify"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Fbabelify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Fbabelify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Fbabelify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babel%2Fbabelify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/babel","download_url":"https://codeload.github.com/babel/babelify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253726972,"owners_count":21954110,"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-07-31T05:01:05.201Z","updated_at":"2025-12-16T22:24:45.610Z","avatar_url":"https://github.com/babel.png","language":"JavaScript","readme":"# babelify [![Build Status](https://travis-ci.org/babel/babelify.svg?branch=master)](https://travis-ci.org/babel/babelify)\n\n[Babel](https://github.com/babel/babel) [browserify](https://github.com/substack/node-browserify) transform.\n\nAs of [Babel 6.0.0](http://babeljs.io/blog/2015/10/29/6.0.0/) there are **no plugins included by default**. For babelify to be useful, you must also include some [presets](http://babeljs.io/docs/plugins/#presets) and/or [plugins](http://babeljs.io/docs/plugins/#transform).\n\n## Installation\n\n```sh\n# Babel 7\n$ npm install --save-dev babelify @babel/core\n\n# Babel 6\n$ npm install --save-dev babelify@8 babel-core\n```\n\n## Usage\n\n### CLI\n\n```sh\n$ browserify script.js -o bundle.js -t [ babelify --presets [ @babel/preset-env @babel/preset-react ] --plugins [ @babel/plugin-transform-class-properties ] ]\n```\n\n### Node\n\n```javascript\nvar fs = require(\"fs\");\nvar browserify = require(\"browserify\");\nbrowserify(\"./script.js\")\n  .transform(\"babelify\", {presets: [\"@babel/preset-env\", \"@babel/preset-react\"]})\n  .bundle()\n  .pipe(fs.createWriteStream(\"bundle.js\"));\n```\n\n**NOTE:** [Presets and plugins](http://babeljs.io/docs/plugins/) need to be installed as separate modules. For the above examples to work, you'd need to also install [`@babel/preset-env`](https://www.npmjs.com/package/@babel/preset-env) and [`@babel/preset-react`](https://www.npmjs.com/package/@babel/preset-react):\n\n```sh\n$ npm install --save-dev @babel/preset-env @babel/preset-react\n```\n\n### Options\n\nSelected options are discussed below. See the [babel](http://babeljs.io/) docs for the complete list of [options](http://babeljs.io/docs/usage/options/).\n\nOptions may be passed in via standard [browserify](https://github.com/substack/node-browserify#btransformtr-opts) ways:\n\n```sh\n$ browserify -t [ babelify --presets [ @babel/preset-env @babel/preset-react ] ]\n```\n\n```js\nbrowserify().transform(\"babelify\", {presets: [\"@babel/preset-env\", \"@babel/preset-react\"]});\n```\n\n```js\nvar babelify = require(\"babelify\");\nbrowserify().transform(babelify, {presets: [\"@babel/preset-env\", \"@babel/preset-react\"]});\n```\n\nOr, with the `configure` method:\n\n```js\nbrowserify().transform(babelify.configure({\n  presets: [\"@babel/preset-env\", \"@babel/preset-react\"]\n}));\n```\n\n#### Customizing extensions\n\nBy default, all files with the extensions `.js`, `.es`, `.es6` and `.jsx` are compiled. You can change this by passing an array of extensions.\n\n**NOTE:** This will override the default ones so if you want to use any of them\nyou have to add them back.\n\n```js\nbrowserify().transform(\"babelify\", {extensions: [\".babel\"]});\n```\n\n```sh\n$ browserify -t [ babelify --extensions .babel ]\n```\n\nNow you can use:\n\n```js\nimport NavBar from \"nav-bar.babel\";\nvar Panels = require(\"panels.babel\");\n```\n\n**NOTE:** By default, Browserify will only lookup `.js` and `.json` files when the extension is omitted (like node's `require`). To lookup additional extensions, use browserify's [`extensions` option](https://github.com/substack/node-browserify#browserifyfiles--opts).\n\n```js\nbrowserify({\n  extensions: [\".babel\"]\n}).transform(\"babelify\", {\n  extensions: [\".babel\"]\n});\n```\n\n```sh\n$ browserify --extensions=.babel -t [ babelify --extensions .babel ]\n```\n\nNow you can omit the extension and compile `.babel` files:\n\n```js\nimport NavBar from \"nav-bar\";\nvar Panels = require(\"panels\");\n```\n\n#### Source maps\n\nBy default, browserify sets the source map sources paths relative to the basedir (or to `process.cwd()` if not set). To make the sources paths absolute, set the `sourceMapsAbsolute` option on babelify:\n\n```js\nbrowserify().transform(\"babelify\", {\n  sourceMapsAbsolute: true\n});\n```\n\n```sh\n$ browserify -t [ babelify --sourceMapsAbsolute ]\n```\n\n#### Additional options\n\n```javascript\nbrowserify().transform(babelify.configure({\n  // Optional ignore regex - if any filenames **do** match this regex then\n  // they aren't compiled\n  ignore: /regex/,\n\n  // Optional only regex - if any filenames **don't** match this regex\n  // then they aren't compiled\n  only: /my_es6_folder/\n}))\n```\n\n```sh\n$ browserify -t [ babelify --ignore regex --only my_es6_folder ]\n```\n\n#### Babel result (metadata and others)\n\nBabelify emits a `babelify` event with Babel's full result object as the first\nargument, and the filename as the second. Browserify doesn't pass-through the\nevents emitted by a transform, so it's necessary to get a reference to the\ntransform instance before you can attach a listener for the event:\n\n```js\nvar b = browserify().transform(babelify);\n\nb.on(\"transform\", function(tr) {\n  if (tr instanceof babelify) {\n    tr.once(\"babelify\", function(result, filename) {\n      result; // =\u003e { code, map, ast, metadata }\n    });\n  }\n});\n```\n\n## FAQ\n\n### Why aren't files in `node_modules` being transformed?\n\nThis is the default browserify behavior.\n\nA possible solution is to add:\n\n```json\n{\n  \"browserify\": {\n    \"transform\": [\"babelify\"]\n  }\n}\n```\n\nto the root of all your modules `package.json` that you want to be transformed. If you'd like to\nspecify options then you can use:\n\n```json\n{\n  \"browserify\": {\n    \"transform\": [[\"babelify\", { \"presets\": [\"@babel/preset-env\"] }]]\n  }\n}\n```\n\nAnother solution (proceed with caution!) is to run babelify as a [global](https://github.com/substack/node-browserify#btransformtr-opts) transform. Use the babel [`ignore` option](http://babeljs.io/docs/usage/options/) to narrow the number of files transformed:\n\n```js\nbrowserify().transform(\"babelify\", {\n  global: true,\n  ignore: /\\/node_modules\\/(?!app\\/)/\n});\n```\n\nThe above example will result in a transform that also includes the `app` module in `node_modules`: the `global` flag transform all files, and the `ignore` regular expression then excludes all those in the `node_modules` directory *except* those that are in `node_modules/app` (since `?!` will match if the given suffix is absent).\n\n### Why am I not getting source maps?\n\nTo use source maps, enable them in browserify with the [`debug`](https://github.com/substack/node-browserify#browserifyfiles--opts) option:\n\n```js\nbrowserify({debug: true}).transform(\"babelify\");\n```\n\n```sh\n$ browserify -d -t [ babelify ]\n```\n\nIf you want the source maps to be of the post-transpiled code, then leave `debug` on, but turn off babelify's `sourceMaps`:\n\n```js\nbrowserify({debug: true}).transform(\"babelify\", {sourceMaps: false});\n```\n\n```sh\n$ browserify -d -t [ babelify --no-sourceMaps ]\n```\n","funding_links":["https://github.com/sponsors/babel","https://opencollective.com/babel","https://gitcoin.co/grants/2906/babel-compiler-for-next-generation-javascript"],"categories":["JavaScript","Tools","Transpilers","ES6转码器(ES6 to ES5)","基础"],"sub_categories":["Transforms","24.3 Web Sockets","ECMAScript 2015 (ES6)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabel%2Fbabelify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbabel%2Fbabelify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabel%2Fbabelify/lists"}