将Bookblock与Webpacker Rails 6.1结合使用

时间:2020-08-31 00:32:06

标签: ruby-on-rails webpack

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

0 个答案:

没有答案