0
0

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 1 year has passed since last update.

いつも忘れるTypeScript環境構築メモ

Posted at

思い立ったときにすぐ環境作れないからメモ  

とにかくinit

> mkdir ts-test
> cd ts-test
> yarn init
> yarn add -D typescript
> .\node_modules\.bin/tsc --init
> git init

git bash だとyarn initがなんかエラーになったからコマンドプロンプトで

フォルダ構成 どうせsrcとdist

みんなこうする
srcをコンパイルしてdistに入れる

tsconfig.jsonに色々かいてる。
デフォルト+αでこんなもんか

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
    "declarationMap": true /* Create sourcemaps for d.ts files. */,
    "sourceMap": true /* Create source map files for emitted JavaScript files. */,
    "outDir": "dist" /* Specify an output folder for all emitted files. */,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
  },
  "include": ["src"],
  "exclude": ["node_modules", "dist"]
}

コンパイルスクリプトなど

mainとfilesも気にする。
パッケージとしてnode_modulesに含まれたときのindexとファイルを指定

package.json
{
  "name": "ts-test",
  "version": "1.0.0",
  "main": "dist/index.js",
  "license": "MIT",
  "files": [
    "dist"
  ],
  "scripts": {
    "clean": "rm -rf dist",
    "build": "./node_modules/.bin/tsc",
    "watch": "./node_modules/.bin/tsc --watch"
  },
  "devDependencies": {
    "typescript": "^4.7.4"
  }
}

やってみる

src/index.ts
export const test:string ="test";
> yarn build

dist下に色々できた
dist/index.js
dist/index.d.ts
dist/index.d.ts.map
dist/index.js.map

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?