Simple implementation of referencing jquery in webpack

  • 2021-06-28 10:07:15
  • OfStack

1. First you need to add the dependencies of jquery in your project

npm install jquery --save-dev

2. Reference configuration code:


var webpack = require("webpack");
var path = require("path");

module.exports = {
  entry:{
    home:"./src/js/home.js",
     ... 
  },
  output:{
    path:__dirname+"/dist/js",
    filename:"[name].min.js"
  },
  module:{
    loaders:[
      {test:/\.css$/,loader:"style-loader!css-loader"},
       ... 
    ]
  },
  plugins:[
    new webpack.ProvidePlugin({
      $:"jquery",
      jQuery:"jquery",
      "window.jQuery":"jquery"
    })
  ]
}

Install the jquery dependency in the project, 1 must not be less.


Related articles: