Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding docs for importmaps #93

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/web-support/rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,45 @@ window.ApexCharts = require("apexcharts") // expose to window
import ApexCharts from 'apexcharts'
window.ApexCharts = ApexCharts
```

Or, if you use `importmaps', you can:

Download to local vendor directory (optional but recommended)

```bash
$ wget -O vendor/javascript/apexcharts.esm.js https://ga.jspm.io/npm:apexcharts@latest/dist/apexcharts.esm.js`
```

Pin "apexcharts" in `config/importmap.rb` to local esm file (if you do No. 1):

```ruby
pin "apexcharts", to: "apexcharts.esm.js"`
```

or, to CDN URL

```ruby
pin "apexcharts", to: "https://ga.jspm.io/npm:apexcharts@latest/dist/apexcharts.esm.js"`
```

Import and assign to window in `app/javascript/application.js`

```js
import ApexCharts from "apexcharts"
window.ApexCharts = ApexCharts
```

Use it with options `module: true`
For example:

```
<% series = [{
name: "Desktops",
data: [10, 41, 35, 51, 49, 62, 69, 91, 148]
}]
options = {
module: true
}
%>
<%= line_chart(series, options) %>
```