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

craft.vite.asset no longer matches manifest format in Vite 3.x || 4.x #56

Closed
Kashkin opened this issue Jan 25, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@Kashkin
Copy link

Kashkin commented Jan 25, 2023

Describe the bug

I'm unable to reference static assets that are imported via JS and appear in the manifest, e.g. {{ craft.vite.asset("src/sprite.svg") }}.

Expected behaviour

The asset function should return the hashed path to assets in production. It appears the issue exists in extractAssetFiles in ManifestHelper.php, as it's looking for an assets key that doesn't exist in modern manifests.

Example Manifest

{
  "src/scripts/site-legacy.js": {
    "file": "assets/app-legacy-383a340e.js",
    "src": "src/scripts/site-legacy.js",
    "isEntry": true
  },
  "vite/legacy-polyfills-legacy": {
    "file": "assets/polyfills-legacy-e1be769e.js",
    "src": "vite/legacy-polyfills-legacy",
    "isEntry": true
  },
  "src/sprite.svg": {
    "file": "assets/sprite-dea648df.svg",
    "src": "src/sprite.svg"
  },
  "src/scripts/site.js": {
    "file": "assets/app-deed8d93.js",
    "src": "src/scripts/site.js",
    "isEntry": true
  }
}

Versions

  • Plugin version: 4.0.4
  • Craft version: 4.3.6.1
  • Vite version: 4.0.4
@Kashkin Kashkin added the bug Something isn't working label Jan 25, 2023
@khalwat
Copy link
Contributor

khalwat commented Jan 25, 2023

Looks like their docs may be out of date in terms of the manifest format: https://vitejs.dev/guide/backend-integration.html

@khalwat
Copy link
Contributor

khalwat commented Jan 25, 2023

Relevant changes:

vitejs/vite#6649

vitejs/vite#8768

khalwat added a commit to nystudio107/craft-plugin-vite that referenced this issue Jan 25, 2023
… 3.x or later, where assets are stored as top-level entries in the `manifest.json` ([#56](nystudio107/craft-vite#56)) ([#31](nystudio107/craft-vite#31))
khalwat added a commit to nystudio107/craft-plugin-vite that referenced this issue Jan 25, 2023
… 3.x or later, where assets are stored as top-level entries in the `manifest.json` ([#56](nystudio107/craft-vite#56)) ([#31](nystudio107/craft-vite#31))
@khalwat
Copy link
Contributor

khalwat commented Jan 25, 2023

Released a fix for this:

Craft 3: Version 1.0.30 -> https://github.com/nystudio107/craft-vite/releases/tag/1.0.30

Craft 4: Version 4.0.5 -> https://github.com/nystudio107/craft-vite/releases/tag/4.0.5

@khalwat khalwat closed this as completed Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants