Skip to content

Instantly share code, notes, and snippets.

@CristianRP
Last active April 19, 2024 15:21
Show Gist options
  • Save CristianRP/cdf42a80fe366a90fadb38b33293b8db to your computer and use it in GitHub Desktop.
Save CristianRP/cdf42a80fe366a90fadb38b33293b8db to your computer and use it in GitHub Desktop.
TS configuration with Webpack

JS Project Setup with Webpack + TypeScript

Install Webpack dependencies

yarn add [email protected] [email protected] [email protected] [email protected] nodemon @faker-js/faker

Install TS dependencies

yarn add -D typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin ts-loader

TS config (tsconfig.json)

{
  "compilerOptions": {
    "outDir": "./dist/",
    "noImplicitAny": true,
    "module": "ESNext",
    "target": "ES2020",
    "jsx": "react",
    "allowJs": true,
    "moduleResolution": "node"
  }
}

Basic webpack.config.js

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

module.exports = {
  mode: 'development',
  devServer: {
    port: 8080,
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html',
    })
  ],
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment