npm init
"main": "lib/index.js",
"files": ["src/", "lib/", "README.md"],
创建src, lib文件夹
创建.gitignore .npmignore
添加babel依赖配置
dependencies:
npm install --save-dev @babel/core @babel/cli @babel/preset-env
config: babel.config.json
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"edge": "17",
"firefox": "60",
"chrome": "67",
"safari": "11.1"
},
"useBuiltIns": "usage",
"corejs": "3.6.5"
}
]
]
}
compile:
./node_modules/.bin/babel src --out-dir lib
or
npx babel src --out-dir lib
添加typescript编译依赖配置
@babel/preset-typescript · Babel
dependencies:
npm install --save-dev @babel/plugin-transform-typescript
npm install --save-dev @babel/preset-typescript
config: babel.config.json
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"edge": "17",
"firefox": "60",
"chrome": "67",
"safari": "11.1"
},
"useBuiltIns": "usage",
"corejs": "3.6.5"
}
],
"@babel/preset-typescript"
]
}
compile:
./node_modules/.bin/babel src --out-dir lib --extensions ".ts"
or
npx babel src --out-dir lib --extensions ".ts"
添加测试
Mocha - the fun, simple, flexible JavaScript test framework
添加文件夹 test
添加依赖:npm install --save-dev mocha
compile:
"scripts": {
"test": "mocha --timeout 10000"
}
// 配置文件位置
"--recursive \\"./test/**/*.js\\""
//配置babel编译
"--require @babel/register"