Skip to content

Latest commit

 

History

History
180 lines (129 loc) · 3.3 KB

reveal.md

File metadata and controls

180 lines (129 loc) · 3.3 KB
theme progresss controls slideNumber overview loop history
white
true
true
false
true
true
true

怎么写一个能用的 npm


啥叫能用 ?

--

多环境

  • browser
  • node

--

漂亮的badge

--

发布到npm

--

CLI[可选]

npx your-custome-command ...[option]

讲完了

npm init
npm build
npm publish

  • all in one page
  • npm package
  • webpack realated: module, jsnext:main, browser
  • publish related: files, version, private, publishConfig
  • directories: bin, doc, test, lib, example

Module规范

vue-dist

--

CommonJS/CJS

const depMod = require('someMod')
...
module.exports = exportMod

--

ES Module

import { namedExp }, defaultExp from 'someMod'
...
export const namedExport = {}
export default defaultExport = {}

--

UMD

(function (root, factory) {
  "use strict";

  // AMD
  if (typeof define === 'function' && define.amd) {
    define([], factory);
  }
  // CommonJS
  else if (typeof exports === 'object') {
    module.exports = factory();
  }
  // Browser
  else {
    root.moduleName = factory();
  }
})(this, function () {
  "use strict";
 // 具体的代码
 ...
})

--

<script nomodule src="fallback.js"></script>
<script type="module">
  import { addTextToBody } from './utils.mjs';
  addTextToBody('Modules are pretty cool.');
</script>

构建 - Babel


npm 发布

npm login
# update package
npm version <newVersion>
npm publish

--

cnpm sync

--

Open Source CDN

<script src="https://cdn.jsdelivr.net/npm/package@version/file"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dzh.js"></script>

谢谢


参考