
Security News
Node.js Drops Bug Bounty Rewards After Funding Dries Up
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.
butterfly-loader
Advanced tools
一个精致实用的AMD javascript模块加载器,可用于node端和浏览器环境
在HTML中引入加载器
<script src="path-to-butterfly-root/dist/butterfly.min.js"></script>
/**
* 定义模块
* @param {String} id - 模块id
* @param {Array} depends - 依赖模块
* @param {Any} factory - 模块构造器
*/
define(id, depends, factory)
define(id, depends)
define(id, factory)
define(depends, factory)
define(factory)
用于设置和获取config
loader.config(name)
loader.config(name, value)
一般用于配置alias和resolve规则
butterfly.config('alias', {
'util-request', 'util/request'
});
alias也可以是一个function
butterfly.config('alias', function(id) {
if (id.startsWith('ui-')) {
return 'ui/' + id;
}
});
butterfly.config('resolve', function(id) {
return '/assets/' + id + '.js';
});
定义一个新的loader
window.x = butterfly.new('x', { autoloadAnonymous: true });
然后就可以使用x加载器了
x.define('util', ['exports'], function(exports) {
exports.sum = function(a, b) {
return a + b;
};
});
x.require(['util'], function(util) {
util.sum(1, 2).should.be.equal(3);
});
定义模块
加载模块
判断模块是否已加载
取消定义一个模块
取得加载器中所有的模块
解析模块远程地址
默认情况下,加载器会占有butterfly和define两个全局变量,如果有冲突时可以使用这个方法解决
window.x = butterfly.noConflict();
define(...) // 这个就是原来的define
x.define(...) // 现在就可以使用x来定义和加载模块了
FAQs
An AMD javascript loader can be used in both in node & browse env.
We found that butterfly-loader 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
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.