Skip to content
Permalink
develop
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
title taxonomy process
Builds and modules
category
docs
twig
true

The different Select2 builds

Select2 provides multiple builds that are tailored to different environments where it is going to be used. If you think you need to use Select2 in a nonstandard environment, like when you are using AMD, you should read over the list below.

Build name When you should use it
Standard (select2.js / select2.min.js) This is the build that most people should be using for Select2. It includes the most commonly used features.
Full (select2.full.js / select2.full.min.js) You should only use this build if you need the recommended includes like jquery.mousewheel

Using Select2 with AMD or CommonJS loaders

Select2 should work with most AMD- or CommonJS-compliant module loaders, including RequireJS and almond. Select2 ships with a modified version of the UMD jQuery template that supports both CommonJS and AMD environments.

Configuration

For most AMD and CommonJS setups, the location of the data files used by Select2 will be automatically determined and handled without you needing to do anything.

Select2 internally uses AMD and the r.js build tool to build the files located in the dist folder. These are built using the files in the src folder, so you can just point your modules to the Select2 source and load in jquery.select2 or select2/core when you want to use Select2. The files located in the dist folder are also AMD-compatible, so you can point to that file if you want to load in all of the default Select2 modules.

If you are using Select2 in a build environment where preexisting module names are changed during a build step, Select2 may not be able to find optional language files. You can manually set the prefixes to use for these files using the amdLanguageBase options.

$.fn.select2.defaults.set('amdLanguageBase', 'select2/i18n/');

amdLanguageBase

Specifies the base AMD loader language path to be used for select2 language file resolution. This option typically doesn't need to be changed, but is available for situations where module names may change as a result of certain build environments.

Due to a bug in older versions of the r.js build tool, Select2 was sometimes placed before jQuery in the compiled build file. Because of this, Select2 will trigger an error because it won't be able to find or load jQuery. By upgrading to version 2.1.18 or higher of the r.js build tool, you will be able to fix the issue.