1

I seem to be getting an error within the console of my website saying "jQuery is not defined" I think the problem is to do with Webpack and Gulp.

My files:

Gulpfile:

import webpack from 'webpack';
import WebpackStream from 'webpack-stream';
import WebpackConfig from './webpack.config.babel.js';

var build = {
    live: '../TheICC.Site/assets',
    dev: 'html/assets',
    cshtml: '../TheICC.Site'
}

gulp.task( 'js', function() {

    gulp.src( 'js/*.js' )
        .pipe( $.wait(500) )
        .pipe( WebpackStream({}, webpack ))
        .pipe( WebpackStream( WebpackConfig ))
        .pipe( gulp.dest( build.dev + '/js' ) )
        .pipe( gulp.dest( build.live + '/js' ) )

} );

Webpack File:

import path from 'path';
import webpack from 'webpack';

const BUILD_DIR = path.resolve(__dirname, './html/assets/js')

module.exports = {
    cache: true,
    entry: './js/app.js',
    output: {
        path: BUILD_DIR,
        filename: 'script.bundle.js'
    },
    plugins: [
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            // In case you imported plugins individually, you must also require them here:
            Util: 'exports-loader?Util!js/bootstrap/util',
            Modal: 'exports-loader?Modal!js/bootstrap/modal',
        }),
    ],
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            }
        ]
    }
};

I have already seen Webpackstream issues with babel-loader and even followed the source on the page but for some reason I am still getting the undefined error in the console.

I am getting no errors in the console and it is compiling correctly

Stephen
  • 515
  • 1
  • 14
  • 31
  • Hi Stephen. Did you ever find out what the issue was? – klewis Mar 25 '22 at 20:33
  • Hi @klewis, ah man this was so long ago now that even if I did figure it out at the time I've 100% forgotten now. Looking at the question it was probably something to do with setting globals within the JS file. Sorry I couldn't of been of more help – Stephen Apr 06 '22 at 10:53
  • 1
    Its all good. Early last week, I found out what I had to do with set a webpack configuration file through web pack stream, and use the plugin area to call jQuery. Many thanks on getting back! – klewis Apr 06 '22 at 14:10

0 Answers0