Home Forums Chart Support Can canvasjs work with webpack Reply To: Can canvasjs work with webpack

#33840

I found I needed to fiddle with my Webpack config a bit to get something working. In case it helps somebody else, this is what worked for my React app…

1. Copied canvasjs.min.js and canvasjs.react.js to a new folder at the root called “assets”
2. Installed some babel stuff “npm install –save-dev babel-loader @babel/core @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties”
3. Modified my webpack.config.js to use babel to load canvasJS files
`
{
test: /\.js$/,
include: [
path.resolve(__dirname, ‘assets’),
],
use: {
loader: ‘babel-loader’,
options: {
presets: [
[‘@babel/preset-env’, { targets: “defaults” }],
“@babel/preset-react”
],
“plugins”: [
“@babel/plugin-proposal-class-properties”
]
}
}
},
`

I’m not entirely sure all of the babel setting are correct or necessary, but I found it to work via trial-and-error so I’m likely to keep it as-is. I hope this helps.

  • This reply was modified 3 years ago by jkeith.
  • This reply was modified 3 years ago by jkeith.