Day 19 - Intermediate JS: Webpack - Loaders & Plugins

WebDev Series

19 March, 2024

21

21

0

  • Day 19 - Intermediate JS: Webpack - Loaders & Plugins
    • html-webpack-plugin
      • This will automatically build an HTML file in dist for us when we build our project.
    • Use loaders by defining module.rules in webpack.config.js config file and use imports like import './style.css'; and import Img from './unsplash.jpg'; in the js file 🙂
      • The image tag is dynamically added to the dist/index.html file
        //...
        module: {
        rules: [
        {
        test: /\\.css$/i,
        use: ['style-loader', 'css-loader'],
        },
        {
        test: /\\.(png|svg|jpg|jpeg|gif)$/i,
        type: 'asset/resource',
        },
        ]
        }
        //...
      • A little into regex (regular expression) used here
        • Write the regex between / /
        • $ → to match last part - mdn docs
        • i modifier to tell case-insensitive match - link
      • JSON is a built-in loader meaning import data from ./data.json can be used without added any loader to webpack.config.js
      • npx webpack --watch to let it run & update everytime we make any change

21

21

0

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2025. Showcase Creators Inc. All rights reserved.