question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use choices.js on webpack?

See original GitHub issue

I’m using webpack.

./node_modules/.bin/webpack -v
3.5.2

I tried choices.js. However happend build error. It is because svg file can not found.

// resources/css/admin/app.css
@import "choices.js/assets/styles/css/choices.css";
$ webpack

ERROR in ./resources/css/admin/app.css
Module not found: Error: Can't resolve '../../icons/cross-inverse.svg' in '/Users/orange-lion/**/resources/css/admin'
 @ ./resources/css/admin/app.css 6:150116-150156

ERROR in ./resources/css/admin/app.css
Module not found: Error: Can't resolve '../../icons/cross.svg' in '/Users/orange-lion/**/resources/css/admin'
 @ ./resources/css/admin/app.css 6:151469-151501

I know that it will work if it is an absolute path.

.choices[data-type*="select-one"] .choices__button {
  background-image: url("/assets/icons/cross-inverse.svg");
  padding: 0;
  ...
}

This code will not faild to build. But, it is to edit directly node_modules/choices.js/assets/styles/css/choices.css I don’t want to do it.

Are you have any good idea?

[Edit] Can copy that file, but that is not a good solution. Because it will not keep up with the version upgrade.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
zackschustercommented, Aug 11, 2017

Overwrite the icon path prior to import:

$choices-button-icon-path: "~choices.js/assets/icons";
@import '~choices.js/assets/styles/scss/choices';

Coincidentally, you need to do something similar for font-awesome:

$fa-font-path: "~font-awesome/fonts";
@import '~font-awesome/scss/font-awesome';
1reaction
danfraticiucommented, Feb 1, 2018

I fixed this issue by using svg-url-loader with this is webpack config:

module: {
    rules: [
        ...
        {
            test: [
                /choices\.js\/.*\.svg/
            ],
            use: {
                loader: 'svg-url-loader',
                    options: {}
                }
            }
        }
    }
}

This will inline the cross.svg image as base64.

Also you have to @import the choices.css

Later Edit:

Upon rereading, you issue might be different… I fixed that issue by using @import (less) instead of @import (inline), but I use less… so this won’t work for everyone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to import Choices.js into webpack 4? - Stack Overflow
I am trying to import the module Choices.js into webpack. My entry file (app.js): enter image description here; My package.json enter image ...
Read more >
How to use choices.js on webpack? · Issue #223 - GitHub
I'm using webpack. ./node_modules/.bin/webpack -v 3.5.2 I tried choices.js. ... I know that it will work if it is an absolute path.
Read more >
Choices
Choices.js is a lightweight, configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.
Read more >
3 Dependencies - choices.js - npm
Start using choices.js in your project by running `npm i choices.js`. There are 159 other projects in the npm registry using choices.js.
Read more >
Choices.js - Best of JS
This is useful if you have a lot of choices where it is easier for a user to use the search area to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found