8.5 Shop: Assets Migration
When to Execute
This step is OPTIONAL. Execute only if your plugin has custom JavaScript or CSS in shop.
Overview
Sylius 2.0 requires all assets to be in the assets/ directory:
Target structure:
Admin:
assets/admin/Shop:
assets/shop/Compiled by Webpack Encore
Imported in entrypoint files
Your assets might currently be in:
src/Resources/public/(old Sylius 1.x location)assets/(already in correct location, but may need updates)Inline in templates (should be extracted)
Goal: Move everything to assets/shop/ and use modern approaches (Stimulus or imports)
π― Decision Guide
β
Option 1: Rewrite to Stimulus Controller (RECOMMENDED if you know how)
Use when: You know Stimulus and can rewrite JavaScript to Stimulus controller
Good for: Product galleries, image zoom, add to cart, interactive UI
Note: Sylius already includes Stimulus - no additional installation needed.
1. Create Stimulus controller
assets/shop/controllers/product_gallery_controller.js:
2. Register controller
assets/shop/controllers.json:
3. Use in templates
Learn more: Sylius - Customizing Dynamic Elements
Option 2: Move to assets/shop/ + Import in Entrypoint
Use when: You want to migrate existing JavaScript without rewriting
1. Move JavaScript file to assets/shop/
2. Import in entrypoint
assets/shop/entrypoint.js:
3. Rebuild assets
CSS/SCSS Migration
1. Move CSS to assets/shop/
2. Import in entrypoint
assets/shop/entrypoint.js:
3. Use Bootstrap 5 variables
4. Rebuild assets
Declaring External JavaScript Dependencies
Important: If your JavaScript imports external packages (not starting with . or @symfony), you must declare them in tests/TestApplication/package.json.
Example: If using Swiper, Chart.js, Photoswipe, etc.:
tests/TestApplication/package.json:
Note: End users will need to install these packages in their applications. Document this in UPGRADE.md or README.md.
Validation
After migration, verify:
Last updated
Was this helpful?
