【Babel】简单的方法发布一个npm包

331 阅读1分钟

提供一个架子,方便发布npm包。

  • .vscode/setting.json
{
  "eslint.enable": false,
  "editor.formatOnSave": false,
  "editor.tabSize": 2,
  "eslint.workingDirectories": ["./xxxx"],
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}
  • lib/index.js 源代码

  • dist打包后的文件

  • .babelrc

.{
    "presets": [
        "@babel/preset-env"
    ],
    "plugins": [
        "babel-plugin-static-fs"
    ]
}
  • .eslintrc
{
  "extends": "@deyi/eslint-config-ibt/tsrc",
  "rules": {
    "jsx-a11y/no-noninteractive-element-interactions": 0,
    "class-methods-use-this": 0,
    "import/extensions": 0,
    "no-plusplus": 0,
    "no-underscore-dangle": 0,
    "no-restricted-globals": 0,
    "no-nested-ternary": 0,
    "react/jsx-no-target-blank": 0,
    "react/no-array-index-key": 0,
    "react/jsx-curly-newline": 0,
    "no-unused-expressions": 0,
    "no-restricted-syntax": 0,
    "no-await-in-loop": 0,
    "@typescript-eslint/indent": 0,
    "indent": 0
  }
}
  • .prettierrc
{
  "trailingComma": "es5",
  "tabWidth": 2,
  "useTabs": false,
  "singleQuote": true,
  "printWidth": 200,
  "bracketSpacing": true
}
  • package.json
{
  "name": "@deyi/ibddp-sdk",
  "version": "1.2.8",
  "description": "",
  "main": "./dist/index.js",
  "scripts": {
    "build": "babel lib --out-dir dist",
    "pub": "npm run build && npm publish"
  },
  "repository": {
    "type": "git",
    "url": "git@git.com:fe/ibddp-sdk.git"
  },
  "author": "deyi",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.6.4",
    "@babel/core": "^7.6.3",
    "@babel/polyfill": "^7.6.0",
    "@babel/preset-env": "^7.6.3",
    "@babel/register": "^7.6.2",
    "babel-plugin-static-fs": "^3.0.0"
  },
  "dependencies": {
    "@didi/eslint-config-ibt": "0.0.26"
  }
}