ES6语法的包需要转换为ES5语法
-
安装bebel
npm install --save-dev babel-cli babel-preset-es2015 babel-preset-es2017 babel-preset-react
-
对.babelrc文件进行配置
{
"presets": ["es2015","es2017","react"],
}
- 对package.json文件进行配置
添加下面选项
"scripts": {
"build": "babel src -d lib",
"prepublish": "npm run build"
},
然后按需修改package.json的main
这个属性。
- 打包
执行npm publish
即可
不要把node_modules同步到github
NPM默认不会把node_modules
发上去。
但是github会。所以.gitignore
这个文件不可少。
其常见内容如下
node_modules/
design/
docs/
dist/
_site/
*.bak
mock/salary/vars.js
default.vm
# GIT/SVN generated files #
###########################
*.diff
*.patch
.svn/
.git/
# IDE generated files #
#######################
*.iml
.idea/
.ipr
.iws
*~
~*
.settings
.project
.lastbuildtime
.*proj
.deploy/
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db