Monday 25 February 2019

Webpack jQuery and jQuery.lazy() TypeError: q is undefined

how can I bundle jquery and jquery.lazy with webpack? - Everytime I try this, I got an error.

My error is the following in the debug console of my browser:

TypeError: q is undefined

The rest is working fine. Maybe you can see that I've done something wrong.

My package.json:

{
      "name": "mrd-apple",
      "version": "1i.0.0",
      "description": "mrd Apple",
      "main": "webpack.config.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "",
      "license": "ISC",
      "dependencies": {
        "jquery": "^3.3.1",
        "jquery-lazy": "^1.7.10",
        "postcss-loader": "^3.0.0",
        "webpack": "^4.29.3"
      },
      "devDependencies": {
        "css-loader": "^2.1.0",
        "style-loader": "^0.23.1",
        "webpack-cli": "^3.2.3"
      }
    }
}

My webpack.config.js

var webpack = require('webpack');
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
var OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');

module.exports = function(env) {
    return {
        entry: ['./src/js/index.js'],
        output: {
            path: __dirname + '/dist',
            filename: 'bundle.js'
        },
        plugins: [
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery'
            }),
            new MiniCssExtractPlugin({
                // Options similar to the same options in webpackOptions.output
                // both options are optional
                filename: "[name].css",
                chunkFilename: "[id].css"
            }),
            new OptimizeCSSAssetsPlugin({
                assetNameRegExp: /\.optimize\.css$/g,
                cssProcessor: require('cssnano'),
                cssProcessorPluginOptions: {
                    preset: ['default', { discardComments: { removeAll: true } }],
                },
                canPrint: true
            })
        ],
        module: {
            rules: [
                {
                    test: /\.css$/,
                    use: [
                        {
                            loader: MiniCssExtractPlugin.loader,
                            options: {
                                // you can specify a publicPath here
                                // by default it use publicPath in webpackOptions.output
                                publicPath: '../'
                            }
                        },
                        "css-loader"
                    ]
                }
            ]
        },
        optimization: {
            minimizer: [
                new UglifyJsPlugin({
                    cache: true,
                    parallel: true,
                    sourceMap: true // set to true if you want JS source maps
                }),
                new OptimizeCSSAssetsPlugin({})
            ]
        },
    }
}



from Webpack jQuery and jQuery.lazy() TypeError: q is undefined

No comments:

Post a Comment