Là một dự án mã nguồn mở, thlorenz/browserify-shim đã đạt 928 sao trên GitHub, ngôn ngữ JavaScript. 📩 Makes CommonJS incompatible files browserifyable.
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.
For a version compatible with the v2 API npm install [email protected] instead.
Features
The core features of browserify-shim are:
Shims non-CommonJS modules in order for them to be browserified by specifying an alias, the path to the file,
and the identifier under which the module attaches itself to the global window object.
Includes depends for shimming libraries that depend on other libraries being in the global namespace.
applies shims configured inside the dependencies of your package
Additionally, it handles the following real-world edge cases:
Modules that just declare a var foo = ... on the script level and assume it gets attached to the window object.
Since the only way they will ever be run is in the global context — "ahem, … NO?!"
Makes define and also module be undefined, in order to fix improperly-authored
libraries that need
shimming but try anyway to use AMD or CommonJS. For more info read the comment inside this
fixture
removes invalid requires, i.e. require('jquery') although 'jquery' isn't installed due to the library being
improperly published or installed incorrectly via a downloader like bower
Since browserify-shim is a proper browserify transform you can publish packages with files that need to be shimmed,
granted that you specify the shim config inside the package.json.
When browserify resolves your package it will run the browserify-shim transform and thus shim what's necessary
when generating the bundle.
browserify-shim walks upwards from each source file and uses the first "browserify-shim" configuration it finds in a package.json file. You can't shim files outside your project from your project's package. You can add multiple package.json files as long as browserify-shim can always find a package above each source file with the right configuration.
API
You Will Always
1. Install browserify-shim dependency
In most cases you want to install it as a devDependency via:
npm install -D browserify-shim
2. Register browserify-shim as a transform with browserify
The above includes ./js/vendor/jquery.js (relative to the package.json) in the bundle and exports window.$.
Additionally it exposes window.THREE as three, so you can var three = require('three'). More info
below.
Short Form vs. Long Form config
Since jquery does not depend on other shimmed modules and thus has no depends field, we used the short form to
specify its exports, however the example above is equivalent to:
You want to avoid spreading the knowledge that THREE is a global and stay consistent in how you resolve dependencies.
Additionally if THREE would ever be published to npm and you decide to install it from there,
you don't have to change any of your code since it already is requireing it properly.
b) Use aliases
You may expose files under a different name via the browser field and refer to them under that alias in the shim config:
or in a build.js script add: process.env.BROWSERIFYSHIM_DIAGNOSTICS=1 to the top.
Multi Shim Example including dependencies
Some libraries depend on other libraries to have attached their exports to the window for historical reasons :(.
(Hopefully soon we can truly say that this bad design is history.)
In this contrived example we are shimming four libraries since none of them are commonJS compatible:
x exports window.$
x-ui exports nothing since it just attaches itself to x. Therefore x-ui depends on x.
y exports window.Y and also depends on x expecting to find it on the window as $.
z exports window.zorro and depends on x and y. It expects to find x on the window as $, but y on the window as YNOT,
which is actually different than the name under which y exports itself.
We will be using the depends field in order to ensure that a dependency is included and initialized before a library
that depends on it is initialized.
Below are three examples, each showing a way to properly shim the above mentioned modules.
Note: all paths are relative to ./config/shim.js instead of the package.json.
The main difference to a) is the depends field specification. Instead it being an array of strings it expresses its dependencies as a hashmap:
key:path-to-file
value: the name under which it is expected to be attached on the window
More Examples
shim-jquery
expose-jquery
shim-jquery-external
the tests are a great resource to investigate the
different ways to configure shims and to understand how shims are applied to packages found inside the node_modules
of your package
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/thlorenz/browserify-shim là nguồn chính thức.
thlorenz/browserify-shim có bao nhiêu sao?
thlorenz/browserify-shim có 928 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/thlorenz/browserify-shim. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
thlorenz/browserify-shim có phải mã nguồn mở không?
Có — thlorenz/browserify-shim phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/thlorenz/browserify-shim.
thlorenz/browserify-shim có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho thlorenz/browserify-shim. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
thlorenz/browserify-shim có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho thlorenz/browserify-shim. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
thlorenz/browserify-shim còn đang phát triển không?
Commit gần nhất trên thlorenz/browserify-shim là 6 tháng trước (theo timestamp GitHub). Repo có 84 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc browserify-shim có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về browserify-shim.