I
I
ildar-meyker2018-07-23 13:09:57
JavaScript
ildar-meyker, 2018-07-23 13:09:57

What is the correct way to export jQuery to the global scope in webpack including plugins?

Now I do this:

module: {
        rules: [{
            test: require.resolve('jquery'),
            use: [{
                loader: 'expose-loader',
                options: '$'
            }, {
                loader: 'expose-loader',
                options: 'jQuery'
            }]
        }],
    },

But why, for example, when plugins are imported next, do they not become available in jQuery.fn?
import $ from 'jquery';
import 'jquery.maskedinput';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
roginvs, 2018-08-03
@roginvs

I did this with such a crutch in one project , I just added a file to the entrypoint

import * as $ from "jquery";
(window as any).jQuery = $; // A workaround for 'bootstrap'
(window as any).$ = $; // A workaround to use $ in console

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question