как я могу связать jquery
и jquery.lazy
с веб-пакетом?- Каждый раз, когда я пытаюсь это сделать, я получаю сообщение об ошибке.
Моя ошибка заключается в следующем в консоли отладки моего браузера:
TypeError: q is undefined
Остальное работает нормально.Может быть, вы видите, что я сделал что-то не так.
Мой 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"
}
}
}
Мой 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({})
]
},
}
}
Содержание индекса.js
// JS
// require('./jquery.lazy');
require('./lightslider');
require('./simple-lightbox');
require('./init');
// CSS
require('./../css/index.css');