Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parcel build returns temporary filenames to (html) optimiser #9948

Closed
Denperidge opened this issue Sep 10, 2024 · 1 comment
Closed

Parcel build returns temporary filenames to (html) optimiser #9948

Denperidge opened this issue Sep 10, 2024 · 1 comment

Comments

@Denperidge
Copy link

Denperidge commented Sep 10, 2024

🐛 bug report

While adapting a CSP optimizer plugin, which currently works as expected when using the parcel live server/parcel command (which returns asset links like src="/index.hash.js"), but returns non-existent filenames once parcel build is used (and thus having assets links like src="/index.HASH_REF_19010c15bfc1db13.js)

See the repo source at https://github.com/Denperidge/parcel-optimizer-strict-csp
See the example repo at https://github.com/Denperidge-Contrib/parcel-optimizer-strict-csp-example

🎛 Configuration (.babelrc, package.json, cli command)

.parcelrc

{
    "extends": [
        "@parcel/config-default",
    ],
    "optimizers": {
        "*.html": ["...", "parcel-optimizer-csp"]
    }
}
# Works
npm run start

# Doesn't work
npm run build

🤔 Expected Behavior

The final src filenames should(I assume?) be shown in the optimizer's html input (e.g. /index.c36f364e.js)

😯 Current Behavior

Once parcel build is used instead of serve, the html contents (logged at this part in the code returns ... src: '/index.HASH_REF_19010c15bfc1db13.js' ..., which doesn't include the final filename. As such I cannot read them to hash them down the road, which is suboptimal

🌍 Your Environment

Software Version(s)
Parcel 2.12.0
Node v22.2.0
npm/Yarn Nix npm doesn't want to show me i guess
Operating System NixOS 24.05
@Denperidge Denperidge changed the title HASH_REF_PREFIX in optimizer <script src> when building Parcel build returns temporary filenames to (html) optimiser Sep 11, 2024
@Denperidge
Copy link
Author

Denperidge commented Sep 16, 2024

Update: from https://parceljs.org/plugin-system/overview/#phases-of-parcel

The optimizing phase transforms the contents of each bundle. When this is done, Parcel determines the content hashes of each bundle, which are applied to the final output filenames.

Optimizer isn't the right thing to use. Ended up using a reporter instead! Issue closed.

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

No branches or pull requests

1 participant