Skip to content

fix: Remove custom image rules#145

Merged
g-elwell merged 3 commits intorelease/2.0.0from
fix/remove-custom-image-rules
May 23, 2025
Merged

fix: Remove custom image rules#145
g-elwell merged 3 commits intorelease/2.0.0from
fix/remove-custom-image-rules

Conversation

@g-elwell
Copy link
Member

Description

Removes custom image loader(s) in favour of those provided by wp-scripts

An issue was reported #144 where font files were being processed incorrectly, this was due to the combination of both wp-scripts loaders and our own being applied. Having audited what our loaders were doing, it's safe to remove them.

Fonts and images (png|woff|woff2|eot|ttf|gif|jpg|jpeg)

These were being copied by file-loader previously, will now be handled by wp-scripts which includes a couple of additional file types too:

  • bmp|png|jpe?g|gif|webp - get copied to dist/images
  • woff|woff2|eot|ttf|otf - get copied to dist/fonts

It doesn't matter where you're storing the files in your project, referencing them in JS/(S)CSS will cause webpack to find them and copy the files to dist with hashes added to their names.

SVGs

wp-scripts covers using SVGs both as files/resources and in React as components, although this differs from how we have been using it previously:

Import SVG as component

Syntax is different

Previous:
import SVG from '../logo.svg';

wp-scripts:
import { ReactComponent as SVG } from '../logo.svg';

Import SVG as url

Syntax is different - the SVG isn't copied to dist, it's base64 encoded. Tested working in both JS and (S)CSS.

Previous:
import svg from '../svg-file.svg?url';

wp-scripts:
import svg from '../svg-file.svg';

How to test

I've tested the reported issue is resolved by this change by following the steps outlined there. The font file is copied to dist correctly and referenced correctly in the generated CSS file.

project
  static
    font.woff2
  src
    entrypoints
      editor
        index.js
        styles.scss
  dist
    fonts
      font.4fea716b.woff2
    editor.css

// styles.scss contains:
@font-face {
  font-family: 'my-font-family';
  src: url('../../../static/font.woff2') format('woff2');
  font-display: swap;
}

// generated editor.css contains:
@font-face{font-display:swap;font-family:my-font-family;src:url(fonts/font.4fea716b.woff2) format("woff2")}

@g-elwell g-elwell requested a review from ampersarnie as a code owner May 23, 2025 10:22
@g-elwell g-elwell merged commit 54a0174 into release/2.0.0 May 23, 2025
0 of 3 checks passed
@g-elwell g-elwell mentioned this pull request Jun 24, 2025
13 tasks
g-elwell added a commit that referenced this pull request Oct 16, 2025
* fix: initial testing of webpack config import

* chore: bump version

* chore: make beta version

* fix: remove extrenuous new line

* fix: remove config that is nolonger required

* chore: bump version

* chore: clean up build assets

* chore: update @wordpress/scripts to latest

* chore: rebuild package lock

* chore: rebuild package lock

* 2.0.0-alpha.2

* fix: block copy context and target

* 2.0.0-alpha.3

* fix: allow for big bite block structure builds

* chore: version bump

* fix: ensure block and non-block entrypoints can be built together

* fix: revert changes to entrypoint detection

the entrypoint detection should not care if block entrypoints are present, as these are handled by wp-scripts. it can continue to throw an error provided we catch this in the correct location

* fix: catch errors if non-block entrypoints are not found

* test: update webpack and file system mocks

* test: added example to cover scenario with both

* fix: add seperate example css for frontend

* fix: remove css-loader and minification plugin from rules

* chore: remove css-loader and mini-css-extract-plugin packages

* feat: add initial support for script modules

* fix: re-add eslint and stylelint plugins

* feat: use wp-scripts eslint config

* chore: remove unused plugins

* fix: move import/resolver to correct location in config

* fix: remove unneeded rule

* fix: extend wordpress babel config

* fix: re-add extraneous deps rule

* fix: prevent re-processing js and ts

* chore: remove unused dependencies

* chore: rebuild package-lock

* chore: update node version

* fix: correct file name and format of eslint-config-func

* docs: explain entrypoint and block directory structure

* fix: correctly set WP src path

* chore: update wp packages to latest

* chore: update sass-loader

* chore: bump version

* chore: version bump

* fix: adds context path assignment to webpack configs

* chore: remove debugging

* fix: reassign project path to env var as may be required for single project builds

* fix: set WP_SOURCE_PATH env var before requiring wp-scripts webpack config to allow CSS/JS to build

* fix: ensure WP_SOURCE_PATH is always a relative path

* fix: Remove custom image rules (#145)

* fix: remove custom image rules

* test: update svg import syntax in example site

* chore: version bump

* Set correct path for script modules (#146)

* fix: ensure script module config uses correct source path for project

* chore: version bump

* feat: add eslint import/order rule (#147)

* fix: add stylelint use logical properties rule (#148)

* chore: rename dist directory to build to align with wp-scripts (#150)

* chore: update example site code to fix eslint issues

* test: add integration tests

* chore: apply eslint to source and fix issues

* fix: resolve eslint issues relating to global vars

* chore: add missing deps to package json

* chore: destructure global inside of function to avoid failing test

* chore: remove integration test file

* Revert "chore: remove integration test file"

This reverts commit 2743aed.

* ci: run only cli tests in CI

* fix: remove static config interfering with dynamic aliases

* docs: correct inline links to avoid pointing to wiki

* fix: explicitly use prettier and eslint configs

* test: broaden string matching to prevent terminal formatting issues

* chore: update minimum node version to 22

* docs: update working with your assets doc

* chore: version bump 2.0.0

* docs: add upgrade guide from v1

---------

Co-authored-by: Paul Taylor <paul@bigbite.net>
Co-authored-by: Paul Taylor <ampersarnie@users.noreply.github.com>
Co-authored-by: Paul Taylor <paul.taylor@hey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant