npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fis-mod.js

v1.0.0

Published

modJS是一套的前端模块加载解决方案。与传统的模块加载相比,modJS会根据产品实际使用场景,自动选择一种相应的方案,使最终的实现非常轻量简洁。

Downloads

2

Readme

#modJS

简介

modJS是一套的前端模块加载解决方案。与传统的模块加载相比,modJS会根据产品实际使用场景,自动选择一种相应的方案,使最终的实现非常轻量简洁。

使用

模块的定义

  • modJS是一个精简版的AMD/CMD规范,并不完全遵守AMD/CMD规范,目的在于希望给使用者提供一个类似nodeJS一样的开发体验,同时具备很好的线上性能。

使用define来定义一个模块:

define (id, factory)

在平常开发中,我们只需写factory中的代码即可,无需手动定义模块。发布工具会自动将模块代码嵌入factory的闭包里。

factory提供了3个参数:require, exports, module,用于模块的引用和导出。

  • modJS的发布工具会保证你的程序在使用之前,所有依赖的模块都已加载。因此当我们需要一个模块时,只需提供一个模块名即可获取:

require (id)

和NodeJS里获取模块的方式一样,非常简单。

因为所需的模块都已预先加载,因此require可以立即返回该模块。

  • 考虑到有些模块无需在启动时载入,因此modJS提供了可以在运行时异步加载模块的接口:

require.async (names, onload, onerror)

names可以是一个模块名,或者是数组形式的模块名列表。

当所有都加载都完成时,onload被调用,names对应的所有模块实例将作为参数传入。

如果加载错误或者网络超时,onerror将被触发。

超时时间可以通过require.timeout设置,默认为5000(ms)。

使用require.async获取的模块不会被发布工具安排在预加载中,因此在完成回调之前require将会抛出模块未定义错误。

require.loadJs (url)

异步加载脚本文件,不做任何回调

require.loadCss ({url: cssfile})

异步加载CSS文件,并添加到页面

require.loadCss ({content: csstext})

创建一个样式列表并将css内容写入

##说明

modJS只实现了AMD的一个子集,如果需要使用完整兼容AMD规范的版本,请使用amd目录下的esl-mod.js,这个版本是基于esl版本基础之上实现了fis的需求。

相关项目

自动化框架:fis

自动添加define插件:fis-postprocessor-jswrapper