4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ncc で ビルドしてみた[Typescript]

Last updated at Posted at 2020-07-29

やること

tsclib/ にビルドした後に ncc で再びビルドし、 dist/index.js の 1ファイルにまとめる

メリット

  • 軽い
  • minify がお手軽に行える(-m オプションをつけるだけ)
  • 圧縮率が良い感じ(?)(未検証)
  • webpack 等の複雑な設定ファイルを書かなくて良い

こんなところに感じた

package.json

主なオプション

  • main: lib/main.js
  • scripts
    • build: "tsc"
    • pack: "ncc build -m"

build の後 pack を実行する

{
  "name": "add-issue-links",
  "version": "1.0.3",
  "description": "A GitHub Action for adding an issue reference to a pull request.",
  "main": "lib/main.js",
  "scripts": {
    "build": "tsc",
    "format": "prettier --write \"{src,test}/**/{*.ts,*.tsx,*.js,*.jsx}\"",
    "format:check": "prettier --check \"{src,test}/**/{*.ts,*.tsx,*.js,*.jsx}\"",
    "lint": "eslint \"{src,apps,libs,test}/**/{*.spec.ts,*.ts,*.tsx,*.js,*.jsx}\"",
    "lint:fix": "eslint \"{src,apps,libs,test}/**/{*.ts,*.tsx,*.js,*.jsx}\" --fix",
    "test": "jest --passWithNoTests",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "pack": "ncc build -m",
    "all": "npm run format && npm run lint && npm test && npm run build && npm run pack"
  },
  "author": "tktcorporation",
  "license": "MIT",
  "dependencies": {
    "@actions/core": "^1.2.3",
    "@actions/github": "^2.1.1"
  },
  "devDependencies": {
    "@types/jest": "^25.1.4",
    "@types/node": "^13.9.2",
    "@typescript-eslint/parser": "^2.24.0",
    "@zeit/ncc": "^0.22.3",
    "eslint": "^6.8.0",
    "eslint-plugin-github": "^3.4.1",
    "eslint-plugin-jest": "^23.8.2",
    "jest": "^25.1.0",
    "prettier": "^1.19.1",
    "ts-jest": "^25.2.1",
    "typescript": "^3.9.7"
  }
}

tsconfig.js

tsc の 実行用

  • module: "commonjs"
  • outDir: "./lib"
{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "target": "es2019",
    "sourceMap": true,
    "outDir": "./lib",
    "baseUrl": "./",
    "incremental": true
  },
  "include": [
    "**/src/**/*"
  ],
  "exclude": [
    "node_modules",
    "test",
    "__test__",
    "dist",
    "lib",
    "**/*spec.ts",
  ]
}

参考

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?