The rapid development of a npm package (wheels)

motivation

A lot of people want to write your own wheels, but started working when you always encounter the following problems

  • How a basic js library should prepare
  • The basic front-end project which files should be
  • But also how packaged and released to the npm
  • How can you let others recognize the syntax of es6
  • How should write readme
  • How to add eslint
  • How to package a file format umd make direct reference to html

To this end, I specifically made templates to quickly build a JavaScript library project, and do the basic configuration.

Contents are as follows:

.
├── _config.yml
├── build # 打包后的项目文件目录
|   ├── your-js-lib.min.js # 压缩后的js项目库文件
|   └── your-js-lib.min.js.map # map文件
├── node_modules # node_modules
|   └── ... # 依赖组件 ├── src # src目录 | ├── core # 源码组件目录 | └── index.js # 入口文件 ├── .babelrc # babel配置文件 ├── .gitignore # git忽略提交 ├── .npmignore # npm发表忽略提交 ├── eslintrc.json # eslin配置及规则说明 ├── LICENSE # LICENSE ├── package.json # 包依赖管理文件 ├── README.md # 项目使用说明文档 └── rollup.config.js # rollup打包工具配置文档 复制代码

Develop

When development work, we are usually in srcthe directory to create a project file or directory according to their needs, the following two-step way of foreign export.

step1

// `src/core/`
export default a or export {a, b}

step2

// `src/index.js
import YourJsLib from "./core/YourJsLib";
export default YourJsLib;

es6 lint

npm run lint

Bale

npm run build

use

In direct reference page

<script src="js/your-js-lib.min.js"></script>

Or install using npm

npm install your-js-lib --save
...

import YourJsLib from 'your-js-lib';

PS

  • Eslint need to install the plug-in according to their own development process development tools
  • Published npm package need to create under the project name

Item reference address :( Welcome to the star, providing issues, and constantly improve this warehouse.)

YourJsLib

Guess you like

Origin www.cnblogs.com/ahthw/p/12177877.html