TopGit theo dõi babel/babelify trên GitHub, đã đạt 1.7k sao. Browserify transform for Babel
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
var fs = require("fs");
var browserify = require("browserify");
browserify("./script.js")
.transform("babelify", {presets: ["@babel/preset-env", "@babel/preset-react"]})
.bundle()
.pipe(fs.createWriteStream("bundle.js"));
NOTE: Presets and plugins need to be installed as separate modules. For the above examples to work, you'd need to also install @babel/preset-env and @babel/preset-react:
import NavBar from "nav-bar.babel";
var Panels = require("panels.babel");
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.
Now you can omit the extension and compile .babel files:
import NavBar from "nav-bar";
var Panels = require("panels");
Source maps
By 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:
browserify().transform(babelify.configure({
// Optional ignore regex - if any filenames **do** match this regex then
// they aren't compiled
ignore: /regex/,
// Optional only regex - if any filenames **don't** match this regex
// then they aren't compiled
only: /my_es6_folder/
}))
Babelify emits a babelify event with Babel's full result object as the first
argument, and the filename as the second. Browserify doesn't pass-through the
events emitted by a transform, so it's necessary to get a reference to the
transform instance before you can attach a listener for the event:
var b = browserify().transform(babelify);
b.on("transform", function(tr) {
if (tr instanceof babelify) {
tr.once("babelify", function(result, filename) {
result; // => { code, map, ast, metadata }
});
}
});
FAQ
Why aren't files in node_modules being transformed?
This is the default browserify behavior.
A possible solution is to add:
{
"browserify": {
"transform": ["babelify"]
}
}
to the root of all your modules package.json that you want to be transformed. If you'd like to
specify options then you can use:
Another solution (proceed with caution!) is to run babelify as a global transform. Use the babel ignore option to narrow the number of files transformed:
The 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).
Why am I not getting source maps?
To use source maps, enable them in browserify with the debug option:
browserify({debug: true}).transform("babelify");
$ browserify -d -t [ babelify ]
If you want the source maps to be of the post-transpiled code, then leave debug on, but turn off babelify's sourceMaps:
babel/babelify có 1.7k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/babel/babelify. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
babel/babelify có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho babel/babelify. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
babel/babelify còn đang phát triển không?
Commit gần nhất trên babel/babelify là 5.1 năm trước (theo timestamp GitHub). Repo có 112 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
babel/babelify viết bằng ngôn ngữ gì?
babel/babelify chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc thêm về babel/babelify ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/babel/babelify là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về babelify?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về babelify.