@bobbybouwmann Having generated the combined script in public/js/chart.js, I then load that from a script tag in blade:
<script src="{{ asset('js/chart.js') }}"></script>
Then I have some inline code that uses it. For example, this works fine:
const cupReturnChart = new Chart(document.getElementById('cupReturnsChart').getContext('2d'), {
type: 'bar',
data: {
datasets: [{
data: {!! json_encode($cupReturns) !!},
borderWidth: 1,
backgroundColor: '#FFAC2B',
borderColor: '#FFAC2B'
}]
},
options: options
});
That's just using chart.js, not the datalabels extension – and that's where this issues arise, for example if I try to do this:
import * as datalabels from 'chartjs-plugin-datalabels';
const cupReturnChart = new Chart(document.getElementById('cupReturnsChart').getContext('2d'), {
type: 'bar',
plugins: [datalabels.ChartDataLabels],
data: {
datasets: [{
data: {!! json_encode($cupReturns) !!},
borderWidth: 1,
backgroundColor: '#FFAC2B',
borderColor: '#FFAC2B'
}]
},
options: options
});
That import line fails saying
SyntaxError: Unexpected token '*'. import call expects exactly one argument.
Which is apparently due to the script context not being a module, though I don't know how to make it one.
Because mix appears to strip out the ChartDataLabels variable (it's present in the source file that mix is pointed at), I can't call Chart.register(ChartDataLabels); as the docs suggest either. So I'm a bit lost...