- How do I install rhapsody-project/require-js-bundle with Composer?
- Install it with composer require rhapsody-project/require-js-bundle and let Composer resolve the version constraint from Packagist. The package ships as a Symfony bundle with a framework-agnostic core, so in a Laravel app you either register its service provider manually in config/app.php or use the core classes directly. After installing, publish or copy the default configuration so you have a starting point for declaring your module paths and shims.
- Does this package support Laravel 10 and Laravel 11?
- The package itself is framework-agnostic at its core, so Laravel version support mostly depends on the PHP and Symfony component constraints declared in its composer.json. Check those constraints before installing on Laravel 10 or 11, since a mismatch in the required PHP version or Symfony contracts will block the Composer install. If your application satisfies those requirements, the core RequireJS configuration and rendering logic will run normally inside Laravel.
- How do I configure RequireJS paths, shims, and bundles?
- All RequireJS settings live in a single configuration structure where you declare paths, shims, and bundles together. Paths map module names to file locations, shims declare dependencies and exported globals for non-AMD scripts, and bundles map module prefixes to already-built bundle files. Declaring everything in one place means Twig or Blade templates only reference module names instead of hard-coded script URLs.
- How do I render RequireJS script tags and bootstrap a module in a Blade template?
- The bundle provides templating helpers for emitting the RequireJS script tag and the inline bootstrap call for a given module. Those helpers are written for Twig, so in Laravel you either use the underlying renderer from the core classes or wrap it in a small Blade directive of your own. The result is the same: one helper call outputs the configured paths and kicks off your entry module.
- Can I use this package in Laravel without adopting Symfony?
- Yes. The RequireJS integration logic sits in a PSR-compatible, framework-agnostic core, and the Symfony bundle is only a thin bridge around it. That means you can instantiate the configuration and renderer classes directly in a Laravel service provider without pulling Symfony's full framework into your stack. You only inherit the Symfony dependency through the bridge layer, which you can bypass entirely.
- How does r.js optimizer support work for production builds?
- The configuration format mirrors the options the r.js optimizer expects, so the same module definitions you use at runtime can drive a build. You run r.js through Node during your deploy step to produce concatenated and minified bundles, then point the paths and bundles configuration at those built files. In production you serve the optimized output, while development keeps loading individual modules for easier debugging.
- Does this replace Laravel Mix or Vite?
- No. This package handles runtime AMD module loading and RequireJS configuration; Mix and Vite handle asset compilation and bundling pipelines. They can coexist, for example by having Mix copy your RequireJS modules or r.js build output into the public directory. If you have already moved to native ES modules with Vite, RequireJS is generally an unnecessary extra layer.
- How do I clear the cache after changing RequireJS configuration?
- The bundle is designed to work alongside Symfony's cache component, so generated configuration and asset references can be cached. After editing paths, shims, or bundles, clear the framework cache so the new configuration is picked up. In Laravel that usually means running php artisan config:clear and php artisan cache:clear if you have cached configuration.
- Is this package still maintained, and what are the alternatives?
- Check the GitHub repository for recent commits, open issues, and tagged releases before committing to it, since small bundles like this can go quiet. Alternatives include plain RequireJS configured by hand, the requirejs optimizer run directly from Node, or modern ES module bundlers such as Vite. If you need long-term support, weigh the convenience of the bundle against the cost of vendoring a small amount of configuration code yourself.
- How can I test that my RequireJS modules load correctly?
- Load a page in the browser with the network panel open and confirm each module resolves to the expected file without 404s or shim warnings. Exercise the entry module's main code paths, then run the r.js build and repeat the check against the optimized bundles before deploying. Automated smoke tests that assert the expected script tags and bootstrap call appear in the rendered output catch configuration regressions early.