Managing jQuery plugin dependency in webpack

前端 未结 11 1235
陌清茗
陌清茗 2020-11-22 01:17

I\'m using Webpack in my application, in which I create two entry points - bundle.js for all my JavaScript files/codes, and vendors.js for all libraries like jQuery and Reac

11条回答
  •  心在旅途
    2020-11-22 01:31

    In your webpack.config.js file add below:

     var webpack = require("webpack");
     plugins: [
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
        })
     ],
    

    Install jQuery using npm:

    $ npm i jquery --save
    

    In app.js file add below lines:

    import $ from 'jquery';
    window.jQuery = $;
    window.$ = $;
    

    This worked for me. :)

提交回复
热议问题