Recent Posts

Featured image for Add Active Class When Specific Variables Equal On React

Add Active Class When Specific Variables Equal On React

In React, you can conditionally add an “active” class to an element based on certain variables using conditional rendering. In your code snippet, it appears that you want to add the “active” class to a list-group-item element when the invoiceId is equal to invoice.number. Here’s how you can achieve this in React:

jsx
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import React from 'react';

function YourComponent({ invoiceId, invoice }) {
  return (
    <div>
      {/* ... Other JSX code ... */}
      <div className={`list-group-item list-group-item-action ${invoiceId === invoice.number ? 'active' : ''}`}>
        {/* Your content for the list item */}
      </div>
      {/* ... Other JSX code ... */}
    </div>
  );
}

export default YourComponent;

In the code above:

Featured image for How to Bundle Bootstrap 5 with Webpack

How to Bundle Bootstrap 5 with Webpack

In this tutorial, we will walk you through the process of bundling Bootstrap 5 with Webpack, a popular JavaScript module bundler. By bundling Bootstrap with Webpack, you can efficiently manage and optimize your project’s JavaScript and CSS assets.

Before we begin, make sure you have Node.js and npm (Node Package Manager) installed on your system. You will also need a basic understanding of using npm and Webpack in your project.

Featured image for How To Bundle Bootstrap-Icons That Have Sass And Font Resources With…

How To Bundle Bootstrap-Icons That Have Sass And Font Resources With…

To bundle Bootstrap Icons that have Sass and font resources with Webpack in production mode, you’ll need to make a few modifications to your Webpack configuration. Here’s a step-by-step guide on how to achieve this:

  1. Install Dependencies:

    First, make sure you have the necessary dependencies installed. You’ll need sass-loader, css-loader, style-loader, postcss-loader, and resolve-url-loader to handle Sass and CSS files. You may also need the file-loader or url-loader for fonts and other assets.

    You can install these dependencies using npm or yarn:

    bash
    1
    
    npm install sass-loader css-loader style-loader postcss-loader resolve-url-loader file-loader --save-dev
  2. Configure Webpack:

    Update your Webpack configuration to include the necessary loaders and plugins for processing Sass and font resources. Here’s an updated webpack.config.js:

    javascript
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    
    const path = require('path');
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    const MiniCssExtractPlugin = require('mini-css-extract-plugin');
    
    module.exports = {
      entry: './web/src/js/main.js',
      output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'web', 'static', 'assets', 'js'),
      },
      mode: 'production',
      module: {
        rules: [
          {
            test: /\.(scss)$/,
            use: [
              MiniCssExtractPlugin.loader, // Extract CSS to a separate file
              'css-loader',
              'postcss-loader',
              {
                loader: 'sass-loader',
                options: {
                  sourceMap: true, // Enable source maps for debugging
                },
              },
            ],
          },
          {
            test: /\.(woff2?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
            use: [
              {
                loader: 'file-loader',
                options: {
                  name: '[name].[ext]',
                  outputPath: '../fonts/', // Adjust the output path as needed
                },
              },
            ],
          },
        ],
      },
      plugins: [
        new HtmlWebpackPlugin({
          template: './web/src/index.html', // Provide your HTML template file
        }),
        new MiniCssExtractPlugin({
          filename: '../css/styles.css', // Output path for CSS
        }),
      ],
    };

    In this configuration:

    • We’ve added the MiniCssExtractPlugin to extract the CSS into a separate file, which is a best practice for production builds.

    • The file-loader is configured to handle font files and place them in the desired output path.

    • The postcss-loader is used with autoprefixer to add necessary vendor prefixes to your CSS.

    • Make sure to adjust the paths and filenames as needed to match your project structure.

  3. Install Additional Plugins:

    You’ll need to install the html-webpack-plugin and mini-css-extract-plugin if you haven’t already:

    bash
    1
    
    npm install html-webpack-plugin mini-css-extract-plugin --save-dev
  4. Update HTML File:

    Ensure that your HTML file (specified in the HtmlWebpackPlugin) includes the CSS and JavaScript files correctly. For example:

    html
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Your App</title>
      <link rel="stylesheet" href="../css/styles.css">
    </head>
    <body>
      <!-- Your HTML content here -->
      <script src="bundle.js"></script>
    </body>
    </html>
  5. Build Your Project:

    Now, you can build your project in production mode:

    bash
    1
    
    webpack --mode production

    This will generate a production-ready bundle with your Sass styles, fonts, and Bootstrap Icons properly bundled and optimized.

Featured image for How To Remove generated license file webpack

How To Remove generated license file webpack

It appears that you want to remove the generation of license comments in your webpack bundle. To achieve this, you can set the extractComments option of the TerserPlugin to false. This will prevent the plugin from extracting and adding license comments to your bundle. Here’s how you can modify your webpack configuration:

javascript
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
   optimization: {
      minimize: true,
      minimizer: [
         new TerserPlugin({
            extractComments: false, // Set this option to false
         }),
      ],
   },
   entry: './web/src/js/main.js',
   output: {
      filename: 'bundle.js',
      path: path.resolve(__dirname, 'web', 'static', 'assets', 'js'),
   }
};

By setting extractComments to false, the TerserPlugin will not include license comments in your minified bundle. This should help you achieve your goal of removing the generated license file from your webpack output.

Featured image for Go HTML Template Active nav-link Bootstrap

Go HTML Template Active nav-link Bootstrap

In the provided HTML code snippet, it appears to be a part of a Bootstrap navigation menu that is using Go’s HTML template syntax to conditionally add the “active” class to a navigation link based on a condition. In this case, it is checking whether the current page’s title is equal to “Home” and adding the “active” class if the condition is true.

Let me break down the code for you:

Featured image for Check Whenever locked or not via SSH on Windows

Check Whenever locked or not via SSH on Windows

If you’re looking to determine whether a Windows machine is locked or not via SSH, you can use PowerShell commands to achieve this. The Get-Process command with the logonui argument can be used to check the status of the “LogonUI” process, which is responsible for the Windows login screen. If the “LogonUI” process is running, it typically means that the user is logged in and the machine is not locked. If the process is not running, it might indicate that the machine is locked or at the login screen.