To import select2 using Parcel.js, follow the steps below:
npm install -g parcel-bundler
.npm init
.npm install select2
.In your HTML file, add the following code to import Select2:
<link rel="stylesheet" href="node_modules/select2/dist/css/select2.min.css" />
<script src="node_modules/select2/dist/js/select2.min.js"></script>
In your JavaScript file, you can now use the Select2 library like this:
import $ from 'jquery';
import 'select2';
$(document).ready(function() {
$('#my-select').select2();
});
Note: Make sure to also import the jQuery library in your JavaScript file if you haven't already.
Asked: 2023-06-07 11:31:45 +0000
Seen: 7 times
Last updated: Jun 07 '23