Mad Fish DT World

MadfishDT world github blog page

Typescript Nodejs Setting

Reference

Make Package.json

Configuration Typescript

if you use local project installed typescript

npx tsc --init

if you use global installed typescript

tsc --init

tsconfig.json

{
  "compilerOptions": {
     "lib": [
        "es5",
        "es6"
     ],
     "target": "es5",
     "module": "commonjs",
     "moduleResolution": "node",
     "outDir": "./build",
     "emitDecoratorMetadata": true,
     "experimentalDecorators": true,
     "sourceMap": true
  }
}

Configuration Webpack

const path = require('path');

module.exports = {
  entry: './src/main.ts', //entry source path
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      }
    ]
  },
  devtool: 'source-map',
  target: 'node',
  resolve: {
    extensions: [ '.tsx', '.ts', '.js' ]
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  }
};

Make Application Source Code

src/main.ts

class AppMain {
  public app: express.Application;


  constructor () {
    console.log(`I'm Main`);
  }
}

export default AppMain;

Developing run Scrip && build Script

package.json

....
 "scripts": {
    "start": "nodemon --watch src --delay 1 --exec ts-node src/main.ts",
    "build": "webpack --config config/webpack.config.js",
  },

template code