Answer the question
In order to leave comments, you need to log in
How to import packages into js file using Gulp and Webpack?
Now I can import, I have the main js file script.js and I can import all my scripts there via the export default function. It looks like this:
"use strict";
import mainSliders from './main__sliders.js';
document.addEventListener("DOMContentLoaded", function () {
mainSliders();
});
<script src="assets/js/lib/swiper/swiper.min.js"></script>
<script src="assets/js/script.min.js"></script>
<script src="assets/js/script.min.js"></script>
function scripts(modeName) {
return gulp.src(src.js)
.pipe(webpack({
watch: false,
mode: modeName,
module: {
rules: [
{ test: /\.(js)$/ },
],
},
stats: 'errors-only'
}))
.pipe(babel())
.on('error', console.error.bind(console))
.pipe(concat(`script.js`))
.pipe(gulp.dest(build.js))
.pipe(uglify({
toplevel: true
}))
.pipe(
rename({
extname: ".min.js"
})
)
.pipe(gulp.dest(build.js))
.pipe(browserSync.stream())
}
const buildScripts = () => scripts('production');
const devScripts = () => scripts('development');
gulp.task('build', gulp.series(clean, grid, gulp.parallel(fonts, html, styles, buildScripts, compress, retina, libraries)));
gulp.task('watch', gulp.series(clean, grid, gulp.parallel(fonts, html, styles, devScripts, compress, libraries), watch));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question