theme | progresss | controls | slideNumber | overview | loop | history |
---|---|---|---|---|---|---|
white |
true |
true |
false |
true |
true |
true |
怎么写一个能用的 npm 包
--
- browser
- node
--
漂亮的badge
--
发布到npm
--
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
--
const depMod = require('someMod')
...
module.exports = exportMod
--
import { namedExp }, defaultExp from 'someMod'
...
export const namedExport = {}
export default defaultExport = {}
--
(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>
npm login
# update package
npm version <newVersion>
npm publish
--
cnpm sync
--
<script src="https://cdn.jsdelivr.net/npm/package@version/file"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dzh.js"></script>