Skip to main content

Command Palette

Search for a command to run...

How set up webpack for TypeScript & SCSS

Published
1 min read
M

I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.

I published a new section in my (still) free webpack course. If you look for quick inspiration, my final config is webpack.config.js:

const MiniCssExtractPlugin = require("mini-css-extract-plugin"),
  HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  plugins: [
    new MiniCssExtractPlugin(),
    new HtmlWebpackPlugin({ title: "Contact App" }),
  ],
  mode: "production",
  devtool: "nosources-source-map",
  module: {
    rules: [
      {
        test: /\.html$/i,
        loader: "html-loader",
      },
      {
        test: /\.ts$/,
        use: "ts-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.css$/i,
        use: [MiniCssExtractPlugin.loader, "css-loader"],
      },
      {
        test: /\.scss$/i,
        use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
      },
      {
        test: /\.png/,
        type: "asset",
        parser: {
          dataUrlCondition: {
            maxSize: 10 * 1024, // 10kb
          },
        },
      },
    ],
  },
  resolve: {
    extensions: [".ts", ".js"],
  },
};

If you are interested in a full explanation in the video form, you can sign up for my webpack video course here.

More from this blog

H

How to dev

164 posts

Articles about programming. JavaScript and general advice for beginners in the industry.