TypeScript에서 Webpack과 Babel를 사용하도록 하는 설정을 다룹니다.

webpack과 babel의 자세한 내용은 아래 링크에서 확인해보세요.

Webpack & Babel 다루기

Webpack 설치 및 설정

npm install -D webpack webpack-cli webpack-dev-server
npm install -D html-webpack-plugin
npm install -D babel-loader

wpeback.config.js 설정

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  mode: "development",
  entry: "./index.ts",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].bundle.js",
  },
  module: {
    rules: [
      {
        test: /\\.(js|ts)?$/,
        exclude: /node_modules/,
        use: "babel-loader"
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: "index.html",
      template: "./index.html"
    })
  ]
};

Babel 설치 및 설정