I would like to ask how install and integrate [email protected] with my laravel application.
I use cdn links right now but later it wont be an option for me later.
Used cdn links:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
Method I tried:
- Installing chartjs
npm i [email protected]
- Add this line in webpack.mix.js:
mix.copy('node_modules/chart.js/dist/chart.js', 'public/chart.js/chart.js');
- Then run this from command line:
npm run dev
- In the blade you want the chart on:
<script src="{{ asset('chart.js/chart.js') }}"></script>
Install the package:
Make a file called something like
/resources/js/mychart.js
:In your
/resources/js/app.js
, add the following, at the top:Now run your build, to compile your JavaScript into one file.
Laravel Mix, will already have a line for compiling the app.js file.
Now whenever you reference
/public/js/app.js
, your chart will be included there too.If you'd like a separate file, then change your
webpack.mix.js
file to this:And remember to remove it from the imports in the
/resources/js/app.js
file.