Webpacker rails 6 (loading Bloodhound and typeahead)



我正在尝试在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

我尝试将其加载到我的应用程序中.js webpackapplicaton.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

最新更新