T
T
The Dragger2016-09-28 21:05:26
webpack
The Dragger, 2016-09-28 21:05:26

How to correctly connect jquery to the assembly?

webpack.config.js:

'use strict';

const NODE_ENV = process.env.NODE_ENV || 'dev';
const webpack = require('webpack');
module.exports = {
    entry: './js/main',
    output: {
        filename: './js/app.js'
    },
    // watch: NODE_ENV == 'dev',
    plugins: [
        new webpack.EnvironmentPlugin('NODE_ENV')
    ],
    resolve: {
        alias: {
            jquery: "jquery/src/jquery"
        }
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                loader: 'babel?presets[]=es2015'
            }
        ]
    }
};

Installed jquery via npm: npm i jquery . After that, I type webpack in the terminal , but, in app.js, jquery is not connected. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2016-09-30
@IPD2

I hope app.js has require('jquery') :-)
In plugins , you can try to add ProvidePlugin , specifying jQuery alternative names , so that webpack treats these names as jQuery :

plugins: [
  new webpack.EnvironmentPlugin('NODE_ENV'),

  new webpack.ProvidePlugin({
    '$': 'jquery',
    'jQuery': 'jquery'
  })
]

There is no need to specify jQuery in alias . But adding node_modules to modulesDirectories might help:
resolve: {
  modulesDirectories: ['./', 'node_modules'],
  // ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question