Bookblock试图对jquery使用其自己的$引用,并导致整个插件失败。如何使Bookblock使用其自己的自定义jquery文件并避免与Rails 6应用程序所使用的原始文件冲突?
application.js
window.jQuery = $;
window.$ = $;
import 'core-js/stable'
import '@paxperscientiam/bookblock'
import "@paxpercientiam/bookblock/dist/bc9761b1-bookblock.js';
import ".....js/jquerypp.custom.js'
import "....src/js/modernizr.custom.js"
environment.js
const {environment} = require('@rails/webpacker')
const webpack = require('webpack')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}), new CleanWebpackPlugin()
);
module.exports = {
module: {
rules: [{
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: '$'
}, {
loader: 'expose-loader',
options: 'jQuery'
}]
}]
}
}
module.exports = {
module: {
rules: [
{
test: /\.erb$/,
enforce: 'pre',
loader: 'rails-erb-loader'
}
]
}
}
module.exports = environment