安裝node和npm
npm init 初始化項目
規範版本號
一級版本,重構版本
二級版本,重大功能改進
三級版本,小升級或者bug修復
爲何從0.0.1開始,可以認爲是非正式版,正式版可以以1.x.x開始了。
規範一級目錄
src - 源代碼
release - 發佈結果
test - 單元測試用例
doc - 文檔
example - 示例
構建工具
複製命令
npm i babel-core babel-loader babel-polyfill babel-preset-es2015 babel-preset-latest webpack webpack-cli --save-dev --registry=https://registry.npm.taobao.org
添加.gitignore文件
創建.babelrc文件
文件內容
{ "presets": ["es2015","latest"], "plugins": [] }
項目根目錄下創建 webpack.config.js文件
內容如下
module.exports = { entry : './src/index.js', output : { pathh: __dirname, filename: './release/bundle.js', }, module: { rules: [{ test: /\.js?$/, exculde: /(node_modules)/, loader: 'babel-loader' }] } }
修改package.json中的scripts
添加代碼
"release": "webpack"
運行命令,生成release的內容
npm run release
運行示例
在example中創建test.html,引用release的內容
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>***</title> </head> <body> <p> example </p> <script src="../release/bundle.js"></script> </body> </html>
如何規範化運行
npm安裝靜態網頁工具
npm install http-server -g
修改package.json中的scripts,添加
"example": "http-server -p 8080"
運行命令
npm run example
瀏覽器訪問
http://localhost:8080/example/test.html
規範git分支
至少要2個分支,master和dev。原則是用不到就先不要規劃。
完善README.md
- 產品簡介
- 產品安裝和下載
- 快速使用
- 交流提問區
- 關於作者