gulpfile.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. const {
  2. src,
  3. dest,
  4. parallel,
  5. series,
  6. watch
  7. } = require('gulp');
  8. const uglify = require('gulp-uglify');
  9. const rename = require('gulp-rename');
  10. const sass = require('gulp-sass')(require('sass'));
  11. const autoprefixer = require('gulp-autoprefixer');
  12. const cssnano = require('gulp-cssnano');
  13. const concat = require('gulp-concat');
  14. const clean = require('gulp-clean');
  15. //const imagemin = require('gulp-imagemin');
  16. const changed = require('gulp-changed');
  17. const browsersync = require('browser-sync').create();
  18. const webpack = require('webpack');
  19. const webpackStream = require('webpack-stream');
  20. const compiler = require('webpack')
  21. function clear() {
  22. return src('./assets/*', {
  23. read: false
  24. })
  25. .pipe(clean());
  26. }
  27. // JS function
  28. function js() {
  29. const source = './lib/*.js';
  30. return src(source)
  31. .pipe(webpackStream({
  32. mode: "production",
  33. plugins: [
  34. new webpack.ProvidePlugin({
  35. $: 'jquery',
  36. jQuery: 'jquery',
  37. 'window.jQuery': 'jquery'
  38. }),
  39. ],
  40. output: {
  41. filename: "main.js",
  42. },
  43. module: {
  44. rules: [
  45. {
  46. test: /\.css$/,
  47. use: ['style-loader', 'css-loader']
  48. }
  49. ],
  50. },
  51. }, compiler, function(err, stats) {
  52. }
  53. ))
  54. .pipe(dest('./assets/js/'));
  55. }
  56. // CSS function
  57. function css() {
  58. const source = './sass/**/*.scss';
  59. return src(source)
  60. .pipe(changed(source))
  61. .pipe(sass({
  62. outputStyle: 'compressed',
  63. includePaths: ['./node_modules/foundation-sites/scss']}
  64. ))
  65. .pipe(autoprefixer({
  66. overrideBrowserslist: ['last 2 versions', 'ie >= 9', 'android >= 4.4', 'ios >= 7'],
  67. cascade: false
  68. }))
  69. .pipe(rename({
  70. extname: '.min.css'
  71. }))
  72. .pipe(cssnano())
  73. .pipe(dest('./assets/css/'))
  74. .pipe(browsersync.stream());
  75. }
  76. function watchFiles() {
  77. watch('./sass/**/**/*.scss', css);
  78. watch('./lib/*.js', js);
  79. }
  80. exports.default = series(clear, parallel(js, css));
  81. exports.watch = parallel(watchFiles);