How to require jquery with webpack

How do I require the jquery file from webpack, should I install from npm, or can I just require the file to be downloaded from the jquery website?

Catalog

app/
./assets/javascripts/article/create/base.js
./assets/javascripts/lib/jquery-1.11.1.min.js
webpack.config.js

      

base.js error

require('../../../lib/jquery-1.11.1.min.js'); 
var Content = function() {
};
module.exports = Content;

      

webpack.config.js

module.exports = {
  entry: {
    'ArticleCreate':['./assets/javascripts/Article/Create/Base.js']
  },
  output: {
    path: './assets/javascripts/bundle/',
    filename: '[name].js'
  }
};

      

+3


source to share


2 answers


You tried:

module.exports = {
    ...
    resolve: {
        alias: {
            jquery: "jquery/src/jquery"
        }
    }
};

      



There is a related answer that shows all the jQuery import options here: Managing jQuery plugin dependencies in WebPack

+2


source


I had success installing jQuery with npm

npm install jquery --save



Then

var $ = require('jquery'), jQuery = $, ...

0


source







All Articles