Choices: How to add Choices to Rails 6 with Webpack ?

Created on 9 Mar 2020  路  2Comments  路  Source: Choices-js/Choices

Choices is a great library and it fits my use case pretty nicely. But I have trouble how to include it in a Rails 6 project.

I have added the js side but have trouble including the css part of the library.

Most helpful comment

The reason was I was using Tailwind with Purgecss which removed all the included classes. Ignore with

/*! purgecss start ignore */
@import "choices.js/public/assets/styles/choices.css";
/*! purgecss end ignore */

All 2 comments

Here is the javascript from application.js

const Choices = require('choices.js')
document.addEventListener("turbolinks:load", function() {
    var dropDownSelects = new Choices('.form-select')
})

And the css import from application.scss

@import "choices.js/src/styles/choices.scss";

The above setup works in development but not in production.

The reason was I was using Tailwind with Purgecss which removed all the included classes. Ignore with

/*! purgecss start ignore */
@import "choices.js/public/assets/styles/choices.css";
/*! purgecss end ignore */
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ggcaponetto picture ggcaponetto  路  4Comments

ryanbuening picture ryanbuening  路  4Comments

rstacruz picture rstacruz  路  4Comments

jkrehm picture jkrehm  路  4Comments

zslabs picture zslabs  路  6Comments