hearsay/require-js-bundle
HearsayRequireJsBundle integrates RequireJS with Symfony applications, offering configuration for module paths, shims, and dependencies plus Twig helpers to load scripts. It simplifies managing JavaScript modules and optimized RequireJS builds.
Read this first: hearsay/require-js-bundle is a Symfony2 bundle, not a Laravel package. It is archived, has zero dependents, and targets a pre-Symfony 4 / pre-PHP 8 era. There is no service provider, no package discovery, and no supported composer require path into a modern Laravel app. Your day-to-day leverage is therefore not "install and use" — it is "mine the config schema and reproduce the behavior natively."
Minimal steps for a Laravel developer:
composer.json. You will drag in old Symfony components and risk dependency conflicts with the Laravel runtime.DependencyInjection/Configuration.php — the config schema (baseUrl, paths, shim, deps, map, waitSeconds) you should mirror.RequireJs/ — the core config/optimizer classes; explains how the final require.config payload is assembled.Resources/config/ — Symfony DI wiring; read only if you need to understand the assembly order.Twig/ — the extension that emits script tags and config; gives you the exact output shape to replicate in Blade.README.md — Symfony2 install steps (AppKernel, config.yml); reference only.requirejs from npm, drop require.js into public/js/vendor/, define config/requirejs.php from the bundle's schema, and render it from your layout:<script src="{{ asset('js/vendor/require.js') }}"></script>
<script>
require.config(@json(config('requirejs')));
require(['app/page']);
</script>
AppKernel, add hearsay_require_js under config.yml, and let the bundle's Twig helper emit config + script tag. Wire one page/module before touching the optimizer.The bundle's real value to you is its config blueprint, not its runtime.
The bundle assumes config-driven path/shim definitions and a Twig helper to render them:
# config.yml
hearsay_require_js:
base_url: "js"
paths:
app: "app"
jquery: "vendor/jquery"
shim:
jquery:
exports: "$"
Day-to-day rule: keep all module IDs and paths in config, never inline in templates. That is what makes repeatable builds possible and what the optimizer reads.
Mirror the schema 1:1 in config/requirejs.php so your mental model transfers:
return [
'baseUrl' => '/js',
'paths' => [
'app' => 'app',
'jquery' => 'vendor/jquery',
],
'shim' => [
'jquery' => ['exports' => '$'],
],
];
Expose it once via a directive so pages never repeat require.config():
// app/Providers/AppServiceProvider.php
Blade::directive('requirejs', function () {
return "<?php echo '<script>require.config(' . json_encode(config('requirejs')) . ');</script>'; ?>";
});
Layout:
@requirejs
@stack('requirejs-modules')
@push/@stackThis maps cleanly onto Laravel's stack workflow and is the pattern you'll use every day:
@push('requirejs-modules')
<script>require(['app/dashboard']);</script>
@endpush
Global config lives in the layout; each page pushes only its entry module. Avoid per-page require.config() overrides — they cause silent path drift.
r.js outside Mix/ViteLaravel Mix and Vite are ESM-first; RequireJS is AMD. Do not fight the toolchain. Keep AMD builds as a separate, explicit npm/composer script:
{ "scripts": { "build:amd": "r.js -o build.js" } }
// build.js
({
baseUrl: "resources/js",
name: "app/main",
out: "public/js/app-built.js",
paths: { jquery: "vendor/jquery" }
})
Run it in CI (or a Composer post-install script), then reference public/js/app-built.js from Blade. Generate build.js from the same PHP config if you want a single source of truth; keep it static if the config rarely changes.
The highest-leverage pattern for a Laravel team is to copy the config concepts, not the code: baseUrl, paths, shim, deps, map, waitSeconds. Reproduce the bundle's Twig output with @json or json_encode in Blade. Skip the Symfony DI classes unless you are reverse-engineering how the optimizer resolves a graph.
Twig/ in the repo.web/ as the document root; Laravel uses public/. Every baseUrl and paths entry needs translating. A silent 404 on a module is almost always this.deps confusion. shim declares non-AMD globals and their exports; deps forces load order. Mixing them up produces "$ is undefined" errors that look like a RequireJS bug but are a config bug.waitSeconds low in dev to surface unresolved paths fast. Then bisect by loading a single module ID directly (require(['app/foo'])) — most failures are a bad paths entry, not a code error.r.js writes a new bundle file each build. In production, reference a hashed/versioned filename (e.g., via mix()-style manifest) or you will ship stale AMD bundles behind CDN cache.r.js-built AMD bundles in separate Blade layouts/routes. Interleaving them causes double-loading of RequireJS and unpredictable execution order.config/requirejs.php and the small Blade directive; do not fork the bundle.import(), and migrate behind a feature flag rather than porting this bundle forward.How can I help you explore Laravel packages today?