Skip to content

Transform file hook #3778

Description

@LarsDenBakker

Feature Use Case

When emiting files during a build, it would be great if we can have a hook for transforming those files. This way we can separate plugins which emit/copy files and plugins which transform those files.

Feature Proposal

Add a transformFile hook similar to transform.

export default {
  plugins: [
    {
      transformAsset(content, id) {
        if (id.endsWith('.json') {
          // minify JSON
          return JSON.stringify(JSON.parse(content));
        } else if (id.endsWith('.png') {
          return minifyImage(content);
        }
      }
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions