Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to require jquery with webpack

How to require jquery file with webpack should I have to install from npm, or can I just require the file download from jquery website?

directory

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'
  }
};
like image 227
user1775888 Avatar asked Aug 09 '15 20:08

user1775888


1 Answers

Have you tried:

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

There is a related answer which shows all options of importing jQuery here: Managing jQuery plugin dependency in webpack

like image 133
Meligy Avatar answered Oct 21 '22 07:10

Meligy