Skip to content

@rollup/plugin-url does not use the asset mechanism #1918

@ilonachan

Description

@ilonachan
  • Rollup Plugin Name: @rollup/plugin-url
  • Rollup Plugin Version: 8.0.2

Expected Behavior / Situation

The plugin mechanism offers an emitFile function meant for copying asset files to the output directory. By only referencing the files through their reference ID, the build system is able to keep track of dependencies. The list of produced asset files is also reflected in the output.

Actual Behavior / Situation

@rollup/plugin-url uses regular file system operations to manually copy the files over. This is bad because among other things, it means there is no method to retrieve a list of copied asset files. As this information seems to be part of the intended output of a Rollup build, I consider this a bug (but apparently I'm wrong).

Modification Proposal

Use the correct APIs. Especially since this is an official plugin, it should absolutely set a good example and use the officially provided API for file management. I'm even willing to provide a PR for it.

While this is relatively straightforward to fix, it has some implications on the API of this plugin. For example, the emission of assets can't be turned off by the plugin anymore, only in the output settings. I believe this is intended, but it is a breaking change.

Likewise the destDir parameter won't make sense anymore, since that is also determined by the build output (and that is definitely correct). This means that if the plugin was previously used for unintended purposes of dropping files outside of the output directory, that "functionality" would be broken.

The publicPath behavior may need to be rethought in light of the default file import URL handling of Rollup. My understanding is that import.meta.url is supposed to fill that role, which would again make the parameter obsolete. For now I've opted to just replicate the current output exactly by overriding resolveFileUrl.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions