How set up webpack for TypeScript & SCSS
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.
About the author
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
Comments
Join the discussionNo comments yet. Be the first to comment.





