Skip to content

posty-studio/dependency-extraction-css-hash-fixer-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Dependency Extraction CSS Hash Fixer Webpack Plugin

This tiny Webpack plugin is designed to be used in tandem with the Dependency Extraction Webpack Plugin, which is used when using the @wordpress/scripts package to build JS files for WordPress plugins and themes, and extracts a list of dependencies as well as a hash based on the file's contents.

The Dependency Extraction Webpack Plugin can be used to build CSS files as well (as seen in the official docs), but the problem here is that the hash is based on an empty JS file, which means that the hash will always be same no matter the contents of the associated CSS file.

This plugin fixes that by using the contents of the CSS file to generate the hash, so that it will change when the CSS file changes. This is useful for cache busting and ensuring that the correct CSS file is loaded.

Installation

Install the module:

npm install @posty-studio/dependency-extraction-css-hash-fixer-webpack-plugin --save-dev

Usage

const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const DependencyExtractionCssHashFixerWebpackPlugin = require("@posty-studio/dependency-extraction-css-hash-fixer-webpack-plugin");
const RemoveEmptyScriptsPlugin = require("webpack-remove-empty-scripts");
const path = require("path");

module.exports = {
  ...defaultConfig,
  ...{
    entry: {
      ...defaultConfig.entry(),
      "css/main": path.resolve(process.cwd(), "src/scss", "main.scss"),
    },
    plugins: [
      ...defaultConfig.plugins,
      new RemoveEmptyScriptsPlugin({
        stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS,
      }),
      new DependencyExtractionCssHashFixerWebpackPlugin(),
    ],
  },
};

About

A Webpack plugin to fix CSS hash references in extracted CSS files using the @wordpress/scripts package.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy