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

s94-require

v1.0.16

Published

可以在浏览器中直接使用CommonJS的模块,书写语法和nodejs一样

Downloads

7

Readme

s94-require

可以在浏览器中直接使用CommonJS的模块,书写语法和nodejs一样,模块实时绑定、循环引用不会造成内存泄漏

Install

$ npm install s94-require

使用

<script src="node_modules/s94-require/index.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    //引用
    var md5 = require('md5'); //项目中没用md5模块的自行npm
    console.log(md5('123'));
</script>

注意:由于require方法在查找模块的时候,是在当前项目对应模块目录查找,而当前项目的模块目录,是根据index.js的路径来推算的,所以不要改变index.js的的存放路径,否则会报错 模块不存在

循环引用

var a = require('./a');
console.log(a)

a.js

console.log('导入b之前')
const b = require('./b'); // 注意,此时a.js代码就停在这里,等待b.js执行完毕,再往下执行。
console.log(b)
console.log('导入b之后')

module.exports = '我是a模块'

b.js

console.log('导入a之前')
const a = require('./a');  // 发生了"循环引用",系统会去a.js模块对应对象的exports属性取值
console.log(a) // 因为a.js还没有执行完,只执行第一行和第二代码,所以此时a的值是一个空对象
console.log('导入a之后')

module.exports = '我是b模块'

打印

导入b之前
导入a之前
{}
导入a之后
我是b模块
导入b之后
我是a模块