how to use GitHub gist as an npm module All In One
how to use GitHub gist as an npm module All In One
如何将 GitHub gist 用作 npm 模块 All In One
{
"version": "0.0.2",
"name": "math.js",
"author": "xgqfrms",
"bin": "./math.js"
}
#!/usr/bin/env node
// math.js & `bin` package.json
console.log('math.js 👻');
const add = (a, b) => {
return a + b;
}
const math = {
add,
};
// test case
const result = add(1, 2);
console.log('result =', result, result === (1 + 2) ? '✅' : '❌');
// ESM
// export default math;
// Declaration or statement expected.ts(1128) ❌
// export math;
// CJS
// module.exports.add = add;
// module.exports = math;
https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8
solution ✅
steps
-
create one gist with filename
readme.md
or whatever filename -
edit gist
- add files,
package.json
,app.js
...and so on
demo
https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8
npx
$ npx https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8
$ npx gist:981c08fcb7e09056e1c5d9192f272c8
# --ignore-existing
$ npx --ignore-existing https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8
$ npx --ignore-existing gist:981c08fcb7e09056e1c5d9192f272c8
# npx: the --ignore-existing argument has been removed.
# See `npm help exec` for more information
$ npm help exec
#!/usr/bin/env node
& package.jsonbin
# solution
$ npx https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8
$ npx gist:1981c08fcb7e09056e1c5d9192f272c8
gist as npm package
https://dev.edenspiekermann.com/2016/03/02/gists-as-npm-packages/
https://dev.to/paul_melero/how-to-npm-install-from-github-repositories-or-gists-directly-6og
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16246096.html
未经授权禁止转载,违者必究!