Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lodash Bundle Laravel Package

bmatzner/lodash-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation: Run composer require bmatzner/lodash-bundle:~4.17 and update dependencies. Add new Bmatzner\LoDashBundle\BmatznerLoDashBundle() to AppKernel.php.

  2. Asset Setup: Execute php app/console assets:install web (or --symlink for symlinked assets).

  3. First Use Case: Include the bundle in a Twig template:

    <script src="{{ asset('bundles/bmatznerlodash/js/lodash.min.js') }}"></script>
    

    Now use Lo-Dash in your frontend JavaScript (e.g., _.map(), _.filter()).


Implementation Patterns

Workflows

  1. Frontend Integration:

    • Use Lo-Dash for client-side data manipulation (e.g., filtering, mapping, or deep cloning).
    • Example: Transform API responses before rendering:
      const formattedData = _.map(apiResponse, (item) => ({ ...item, formattedDate: _.now() }));
      
  2. Twig-Asset Optimization:

    • Combine lodash.min.js with other JS assets using Symfony’s asset pipeline (e.g., app/console assets:install --symlink).
  3. Legacy Symfony2 Workflow:

    • Since this is a Symfony2 bundle, ensure your project uses Symfony 2.x (not 3+ or 4+).
    • Use {{ asset() }} for dynamic paths in Twig.

Integration Tips

  • Version Locking: Pin to 4.17.4 explicitly in composer.json to avoid future breakage.
  • Build Tools: If using Webpack/Gulp, manually copy lodash.min.js to web/bundles/bmatznerlodash/js/ to avoid asset pipeline conflicts.
  • Testing: Test Lo-Dash functionality in browser console or unit tests (e.g., Karma/Jasmine).

Gotchas and Tips

Pitfalls

  1. Symfony Version Mismatch:

    • This bundle only works with Symfony 2.x. Attempting to use it in Symfony 3+ or 4+ will fail.
    • Fix: Use a modern alternative like symfony/webpack-encore + npm install lodash.
  2. Asset Pipeline Conflicts:

    • If using --symlink, ensure web/bundles/bmatznerlodash/ exists and is writable.
    • Fix: Run php app/console assets:install --symlink web and verify symlinks.
  3. No NPM/Bower:

    • The bundle predates modern JS tooling. Avoid mixing it with NPM/Bower-managed dependencies.
    • Fix: Use npm install lodash in newer projects.
  4. Outdated Lo-Dash:

    • Version 4.17.4 is 10+ years old (released 2018). Modern Lo-Dash (v4.17.21+) includes security fixes.
    • Fix: Manually replace lodash.min.js with a newer version from lodash.com.

Debugging

  • 404 Errors: Verify bundles/bmatznerlodash/js/lodash.min.js exists in web/ after assets:install.
  • JS Errors: Check browser console for ReferenceError: _ is not defined. Ensure the script tag loads after DOM ready or in a defer block.

Extension Points

  • Custom Builds: Replace lodash.min.js with a custom build (e.g., using lodash’s custom build tool) to reduce bundle size.
  • Twig Extensions: Create a custom Twig extension to expose Lo-Dash utilities to templates (though this is unconventional for JS libraries). Example:
    // src/Acme/LoDashExtension.php
    class LoDashExtension extends \Twig_Extension {
        public function getFunctions() {
            return [
                new \Twig_SimpleFunction('lodash_script', function() {
                    return '<script src="{{ asset("bundles/bmatznerlodash/js/lodash.min.js") }}"></script>';
                }),
            ];
        }
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony