ruby-on-railswebpackbootstrap-tokenfield

We recently updated from sprockets to webpack, but I am struggling to update the bootstrap-tokenfield library


We recently changed our rails application from sprockets to webpack, and everything seems to have ported over fine, with the exception of bootstrap-tokenfield. On the dev environment server it says that everything has compiled but the tokenfield is not rendering as it should.

I have tried to switch up the location/name of the corresponding css and I have tried appending the JS library to the environment plugins to no avail.

environment.js

// for loading css ...
const merge = require('webpack-merge')
const myCssLoaderOptions = {
  modules: true,
  sourceMap: true,
  localIdentName: '[name]__[local]___[hash:base64:5]'
}
const CSSLoader = environment.loaders.get('sass').use.find(el => el.loader === 'css-loader')
CSSLoader.options = merge(CSSLoader.options, myCssLoaderOptions)


const webpack = require('webpack');
environment.plugins.append('Provide', new webpack.ProvidePlugin({
  $: 'jquery',
  jQuery: 'jquery',
  Popper: ['popper.js', 'default']
}));

module.exports = environment

application.js

import Turbolinks from 'turbolinks';
import 'bootstrap/dist/js/bootstrap';
import 'trix';
import 'chosen-js';
import '@coreui/coreui';
import 'jquery-ui';
import 'bootstrap-tokenfield'

Rails.start();
Turbolinks.start();

$(document).ready(function(){

    $('form').on('click', '.remove_record', function(event) {
        $(this).prev('input[type=hidden]').val('1');
        $(this).closest('tr').hide();
        return event.preventDefault();
      });

    $('form').on('click', '.add_fields', function(event) {
      var regexp, time;
      time = new Date().getTime();
      regexp = new RegExp($(this).data('id'), 'g');
      $('.fields').append($(this).data('fields').replace(regexp, time));
      return event.preventDefault();
    });

  });


  $(document).on('click', "tr[data-link]", function(){
    window.location = $(this).data("link")
  });

   $(document).on('turbolinks:load', function() {
    $('.chosen-select').chosen({
      disable_search_threshold: 10, 
      width: '140px'
    })

    $('.chosen-select-form').chosen({
      disable_search_threshold: 7, 
      width: '100%'
    })

    $('[data-toggle="tooltip"]').tooltip()
  })

application.scss (still being compiled by sprockets)

/*

*= require_tree .
*= require chosen
*= require jquery-ui
*= require bootstrap-tokenfield
//*= require trix 

 *
 */

 // "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap";
@import "font-awesome";
@import '@coreui/coreui/dist/css/coreui.min';

I expect that the views with tokenfield built in render a tokenfield input, but they currently just show a regular text input.


Solution

  • I just included the jquery ui and bootstrap tokenfield libraries directly on the layout.html.erb page and it fixed it.