我正在尝试在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没有加载。
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