Answer the question
In order to leave comments, you need to log in
How to include jQuery in Gulp4 using webpack-stream and webpack.ProvidePlugin?
I decided to get confused and cross Gulp with Webpack. Whether this is good or bad, let's leave it out of the question.
In webpack, this is done via the webpack plugin webpack.ProvidePlugin()
module.exports = {
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
]
};
...
webpack = require('webpack'),
webpackStream = require('webpack-stream');
...
// Сбор js
gulp.task('js:build', function () {
return gulp.src(path.src.js)
.pipe(webpackStream({
output: {
filename: 'main.js',
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ['@babel/env']
}
},
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
],
mode: "production",
// externals: {
// jquery: 'jQuery'
// }
}))
.pipe(gulp.dest(path.build.js))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(path.build.js))
.pipe(webserver.reload({ stream: true }));
});
[21:40:41] 'js:build' errored after 7.55 s
[21:40:41] Error: module property was removed from Dependency (use compilation.m
oduleGraph.updateModule(dependency, module) instead)
at ProvidedDependency.set (C:\.........\node_modules\we
bpack\lib\Dependency.js:226:9)
Answer the question
In order to leave comments, you need to log in
You can see how it was done here or even use this template, it seems to be well done.
https://github.com/agragregra/OptimizedHTML-5
I either usually connect es6 with modules, and configure babel in webpack
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question