Skip to content

Plugin transforms static resources, vite:asset-import-meta-url can't resolve #7515

Answered by donmccurdy
donmccurdy asked this question in Q&A
Discussion options

You must be logged in to vote

I didn't exactly figure out what was wrong with my original code, but I did end up finding a plugin setup that works for this purpose — to load, process, and rename static assets — in both Vite and Rollup. Simplified solution below:

import { createFilter, normalizePath } from "@rollup/pluginutils";
import fs from "fs/promises";
import crypto from "crypto";
import path from "path";

const PLUGIN_NAME = "bin";

const HASH_LENGTH = 8;

const DEFAULT_PLUGIN_OPTIONS = {
  include: "**/*.{bin}",
  exclude: "",
  publicPath: "",
  transforms: [],
  verbose: false,
};

/**
 * Import and process .bin assets.
 */
export default function bin(pluginOptions = {}) {
  pluginOptions = { ...DEFAULT_PLUGI…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by donmccurdy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant