Upgrade to Pro — share decks privately, control downloads, hide ads and more …

如何写出一个优秀的开源库

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for ningzbruc ningzbruc
November 27, 2020

 如何写出一个优秀的开源库

Avatar for ningzbruc

ningzbruc

November 27, 2020
Tweet

More Decks by ningzbruc

Other Decks in Programming

Transcript

  1. 初始化 - eslint $ npm i eslint --save-dev $ npx

    eslint --init "scripts": { "eslint": "eslint src/** --fix" }
  2. 构建 - 产物 • lib: commonjs => mai n •

    esm: esmodule => modul e • dist: umd? => browser? https://unpkg.alibaba-inc.com/browse/[email protected]/dist/index.umd.js
  3. 构建 - ⼯具 • lib: commonjs => babe l •

    esm: esmodule => babe l • dist: umd => rollup/webpack https://www.rollupjs.com/guide/tools/#babel
  4. 测试 - 测试⽤例 import add from '../src/add' ; test('add: 1

    + 2 = 3',() => { expect(add(1, 2)).toBe(3) ; }) ; https://jestjs.io/docs/zh-Hans/getting-started