When building a project using a webpack, the question arose. How to import jquery into the necessary modules.

I can do this globally using webpack.ProvidePlugin, according to the instructions from the webpack documentation:

plugins: [ new webpack.ProvidePlugin({ $: "jquery/dist/jquery.min.js" }), ], resolve: { moduleDirectories: ['node_modules'], extension: ['', '.js', '.styl'] }, 

But how to do it explicitly for the right modules?

    1 answer 1

    I would do it using the capabilities of es6, for example:

     import $ from 'pathOfJquery' 

    This in turn requires using a babel-polyfill in a webpack, like this:

      module: { loaders: [{ loaders: ['babel-loader'], include: [ path.resolve(__dirname, "src"), ], test: /\.js$/, ..... 

    and preset for Babel .babelrc

     { "presets": ["es2015"] } 

    Probably, there are still some less cumbersome ways.

    • thank! I will try - while1pass