Webpacker滑轨6(正在加载猎犬并提前输入)

问题描述 投票:0回答:1

我正在尝试在Ruby的webpacker中加载Bloodhound和typeahead.query.js。我让Bloodhound在environment.rb文件中工作,并且摆脱了该错误。但是,提前输入仍无法正常工作,并引发此错误。

Uncaught TypeError: $(...).typeahead is not a function

const { environment } = require('@rails/webpacker')

const webpack = require('webpack')
environment.plugins.append('Provide', new webpack.ProvidePlugin({
  $: 'jquery',
  jQuery: 'jquery',
  Popper: ['popper.js', 'default'],
  Typeahead: 'typeahead.js/dist/typeahead.jquery.js',
  Bloodhound: 'typeahead.js/dist/bloodhound.js'
}))

module.exports = environment

我尝试将其加载到webpack applicaton.js文件中的application.js文件夹中,但是Bloodhound和typeahead.js没有加载。

jquery ruby-on-rails webpack typeahead.js bloodhound
1个回答
0
投票

config / webpack / environment.js需要看起来如下:

const { environment } = require('@rails/webpacker')

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

const aliasConfig = {
  'typeahead': 'typeahead.js/dist/typeahead.jquery.js'
};

environment.config.set('resolve.alias', aliasConfig);

module.exports = environment
© www.soinside.com 2019 - 2024. All rights reserved.