gulpfile.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var gulp = require('gulp');
  2. var livereload = require('gulp-livereload')
  3. var uglify = require('gulp-uglifyjs');
  4. var sass = require('gulp-sass');
  5. var autoprefixer = require('gulp-autoprefixer');
  6. var sourcemaps = require('gulp-sourcemaps');
  7. var imagemin = require('gulp-imagemin');
  8. var pngquant = require('imagemin-pngquant');
  9. const webpack = require('webpack');
  10. const webpackStream = require('webpack-stream');
  11. const compiler = require('webpack')
  12. gulp.task('imagemin', function () {
  13. return gulp.src('./images/*')
  14. .pipe(imagemin({
  15. progressive: true,
  16. svgoPlugins: [{removeViewBox: false}],
  17. use: [pngquant()]
  18. }))
  19. .pipe(gulp.dest('./images'));
  20. });
  21. gulp.task('sass', function () {
  22. gulp.src('./sass/**/*.scss')
  23. .pipe(sourcemaps.init())
  24. .pipe(sass({
  25. //outputStyle: 'compressed',
  26. includePaths: ['node_modules/foundation-sites/scss']
  27. }).on('error', sass.logError))
  28. .pipe(sourcemaps.write('./'))
  29. .pipe(gulp.dest('./css'));
  30. });
  31. /*gulp.task('uglify', function() {
  32. gulp.src('./lib/*.js')
  33. .pipe(uglify('main.js'))
  34. .pipe(gulp.dest('./js'))
  35. });*/
  36. gulp.task('packing', function () {
  37. return gulp
  38. .src('./lib/*.js')
  39. .pipe(webpackStream({
  40. mode: "production",
  41. plugins: [
  42. new webpack.ProvidePlugin({
  43. $: 'jquery',
  44. jQuery: 'jquery',
  45. 'window.jQuery': 'jquery'
  46. }),
  47. ],
  48. output: {
  49. filename: "main.js",
  50. },
  51. module: {
  52. rules: [
  53. {
  54. test: /\.css$/,
  55. use: ['style-loader', 'css-loader']
  56. }
  57. ],
  58. },
  59. }, compiler, function(err, stats) {
  60. }
  61. ))
  62. .pipe(gulp.dest('js/'));
  63. });
  64. gulp.task('watch', function(){
  65. livereload.listen();
  66. gulp.watch('./sass/**/*.scss', ['sass']);
  67. gulp.watch('./lib/*.js', ['packing']);
  68. gulp.watch(['./css/style.css', './**/*.twig', './js/*.js'], function (files){
  69. livereload.changed(files)
  70. });
  71. });