4 months ago

laravel-mix & blade syntax needed to use JS package

Posted 4 months ago by bsholdice

I want to use in a new 5.8 project. I kept getting a browser error:

Uncaught ReferenceError: sparkline is not defined.'

With the help of a SO question ( it seems that one solution is to use mix.copy() to simply stage the .js file in /public/js/, which is then pulled down as a in my blade.


const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .copy('node_modules/@fnando/sparkline/dist/sparkline.js', 'public/js');


    <meta name="csrf-token" content="{{ csrf_token() }}">
    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ mix('js/sparkline.js') }}"></script>

Is there a way to .mix() the .js into my app.js and import/invoke it somehow?

I have gaps in my knowledge about implementing JS packages in Laravel via laravel-mix and how the functions therein are made available to the browser. I'd like to learn more.

Any help appreciated.

Please sign in or create an account to participate in this conversation.