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

npm-publish-demo-webpack

v1.0.3

Published

if you want to create a npm project, this library maybe is suitable for you

Downloads

2

Readme

如果想用webpack打包并发布关于react组件的npm包 这里适合你

if you want to create a npm project of react in webpack, this library maybe is suitable for you

发布要求

  • 源代码采用 ES6 写,但发布到 Npm 仓库的需要是 ES5 的,并且遵守 CommonJS 模块化规范。如果发布到 Npm 上去的 ES5 代码是经过转换的,请同时提供 Source Map 以方便调试
  • 该 UI 组件依赖的其它资源文件例如 CSS 文件也需要包含在发布的模块里
  • 尽量减少冗余代码,减少发布出去的组件的代码文件大小
  • 发布出去的组件的代码中不能含有其依赖的模块的代码,而是让用户可选择性的去安装。例如不能内嵌 React 库的代码,这样做的目的是在其它组件也依赖 React 库时,防止 React 库的代码被重复打包

工程目录

node_modules/hello-webpack
├── lib
│   ├── index.css (组件所有依赖的 CSS 都在这个文件中)
│   ├── index.css.map
│   ├── index.js (符合 CommonJS 模块化规范的 ES5 代码)
│   └── index.js.map
├── src (ES6 源码)
│   ├── index.less
│   └── index.tsx
└── package.json (模块描述文件)console.log("Hello world!");
}

webpack构建

  • 使用 babel-loader 把 ES6 代码转换成 ES5 的代码
  • 通过开启 devtool: 'source-map' 输出 Source Map 以发布调试
  • 设置 output.libraryTarget='commonjs2' 使输出的代码符合CommonJS2 模块化规范,以供给其它模块导入使用
  • 需要通过 less-loader 和 MiniCssExtractPlugin 解决样式引入的资源
  • 需要注意的是 Babel 在把 ES6 代码转换成 ES5 代码时会注入一些辅助函数

本例子仅支持tsx+less的组件编写方式 如果需要扩展或者更改请修改webpack配置 均有相应的注释

发布流程

  • yarn build 生成发布包
  • 修改packjson的name还有其他配置为你需要的配置
  • npm adduser 按流程填账号密码邮箱
  • npm publish 最终发布 注意 每次publish前都要更新一次版本号