1. npm init

  2. 创建src, lib文件夹

  3. 创建.gitignore .npmignore

  4. 添加babel依赖配置

    Usage Guide · 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

  5. 添加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"

  6. 添加测试

    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"