编写package

分析npm package

-index.js 小项目只要一个index.js入口文件即可

-package.json npm安装json格式

-README.md 项目介绍文档

-LICENSE 协议

-CONTRIBUTING.md 贡献列表

-CHANGELOG.md 变更日志

-.travis.yml

-.gitignore git忽略文件

-.npmignore npm安装忽略文件

-.eslintignore esling语法检测忽略文件

-.eslintrc eslint语法规则

-webpack.config.js webpack配置文件

理解package.json

  1. {
  2. /* Name of the project */
  3. "name": "react-component-boilerplate",
  4. /* Brief description */
  5. "description": "Boilerplate for React.js components",
  6. /* Who is the author + optional email + optional site */
  7. "author": "Juho Vepsäläinen <email goes here> (site goes here)",
  8. /* Version of the package */
  9. "version": "0.0.0",
  10. /* `npm run <name>` */
  11. "scripts": {
  12. "start": "webpack-dev-server",
  13. "test": "karma start",
  14. "test:tdd": "npm run test -- --auto-watch --no-single-run",
  15. "test:lint": "eslint . --ext .js --ext .jsx --cache",
  16. "gh-pages": "webpack",
  17. "gh-pages:deploy": "gh-pages -d gh-pages",
  18. "gh-pages:stats": "webpack --profile --json > stats.json",
  19. "dist": "webpack",
  20. "dist:min": "webpack",
  21. "dist:modules": "rm -rf ./dist-modules && babel ./src --out-dir ./dist-modules",
  22. "pretest": "npm run test:lint",
  23. "preversion": "npm run test && npm run dist && npm run dist:min && git commit --allow-empty -am \"Update dist\"",
  24. "prepublish": "npm run dist:modules",
  25. "postpublish": "npm run gh-pages && npm run gh-pages:deploy",
  26. /* If your library is installed through Git, you may want to transpile it */
  27. "postinstall": "node lib/post_install.js"
  28. },
  29. /* Entry point for terminal (i.e., <package name>) */
  30. /* Don't set this unless you intend to allow CLI usage */
  31. "bin": "./index.js",
  32. /* Entry point (defaults to index.js) */
  33. "main": "dist-modules",
  34. /* Package dependencies */
  35. "dependencies": {},
  36. /* Package development dependencies */
  37. "devDependencies": {
  38. "babel": "^6.3.17",
  39. ...
  40. "webpack": "^1.12.2",
  41. "webpack-dev-server": "^1.12.0",
  42. "webpack-merge": "^0.7.0"
  43. },
  44. /* Package peer dependencies. The consumer will fix exact versions. */
  45. /* In npm3 these won't get installed automatically and it's up to the */
  46. /* user to define which versions to use. */
  47. /* If you want to include RC versions to the range, consider using */
  48. /* a pattern such as ^4.0.0-0 */
  49. "peerDependencies": {
  50. "lodash": ">= 3.5.0 < 4.0.0",
  51. "react": ">= 0.11.2 < 16.0.0"
  52. }
  53. /* Links to repository, homepage, and issue tracker */
  54. "repository": {
  55. "type": "git",
  56. "url": "https://github.com/bebraw/react-component-boilerplate.git"
  57. },
  58. "homepage": "https://bebraw.github.io/react-component-boilerplate/",
  59. "bugs": {
  60. "url": "https://github.com/bebraw/react-component-boilerplate/issues"
  61. },
  62. /* Keywords related to package. */
  63. /* Fill this well to make the package findable. */
  64. "keywords": [
  65. "react",
  66. "reactjs",
  67. "boilerplate"
  68. ],
  69. /* Which license to use */
  70. "license": "MIT"
  71. }

webpackoutput.libraryTargetexternals配置项,自行了解


<<上一节:webpack语法分析


另外:

自定义loader

配置react