目標はテスト、ビルド、実行ができること。ただ実行前に確実にビルドするとかいったん置いておく
yarnなども置いておく。javascriptツール多すぎるし流行り廃りとんでもないのでコアだけでやる
config周りは理解とても薄い状態なので、おそらく不足がある。
参考文献
tsc [.js]
だとtsconfig.json参照しないのわかるけどわっかんねえけどやっぱわかる!!!!!
実際どっちが便利よって言われると。ね、
cmd
> mkdir ts-npm-project > cd ts-npm-project > npm init This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults. See `npm help init` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg>` afterwards to install a package and save it as a dependency in the package.json file. Press ^C at any time to quit. package name: (ts-npm-project) version: (1.0.0) description: entry point: (index.js) test command: mocha dist/test git repository: keywords: author: license: (ISC) UNLICENSED About to write to src\ts-npm-project\package.json: { "name": "ts-npm-project", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "mocha dist/test" }, "author": "", "license": "UNLICENSED" } Is this OK? (yes) > mkdir ('dist','src/test') > npm install --save-dev mocha
> only
> mkdir ts-npm-project > cd ts-npm-project > npm init > mkdir ('dist','src/test') > npm install --save-dev mocha
edit
package.json
{ "name": "ts-npm-project", "version": "1.0.0", "description": "", "main": "dist/index.js", "scripts": { "test": "mocha dist/test", "start": "node dist/index.js", "build": "tsc" }, "author": "", "license": "UNLICENSED", "devDependencies": { "mocha": "^10.0.0" } }
tsconfig.json コメント抜き
{ "compilerOptions": { "target": "es2016", "module": "commonjs", "rootDir": "./src", "sourceMap": true, "outDir": "dist", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true } }
.gitignore
dist/ node_modules/
tree(after build)
│ .gitignore │ package-lock.json │ package.json │ tsconfig.json ├─dist │ │ index.js │ │ index.js.map │ │ │ └─test │ test.js │ test.js.map │├─node_modules │ ... │ └─src │ index.ts │ └─test test.ts
src以下のファイルはconsole.log("hello")でも書いとけばわかりやすいんじゃない
build,test,run
> npm run build > npm test > npm start
mkdir ('dist','src/test')
って気取って書いてみたけど、普通に個別に別行で書いた方が打ちやすくない?