Gulpfile.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * load plugins
  3. */
  4. const pkg = require('./package.json')
  5. const banner = [
  6. '/**',
  7. ' * <%= pkg.name %> - <%= pkg.description %>',
  8. ' * @version v<%= pkg.version %>',
  9. ' * @link <%= pkg.homepage %>',
  10. ' * @license <%= pkg.license %>',
  11. ' */',
  12. ''
  13. ].join('\n')
  14. // gulp
  15. const gulp = require('gulp')
  16. // load all plugins in "devDependencies" into the letiable $
  17. const $ = require('gulp-load-plugins')({
  18. pattern: ['*'],
  19. scope: ['devDependencies']
  20. })
  21. /*
  22. * clean task
  23. */
  24. gulp.task('clean', () => {
  25. return $.del(['**/.DS_Store', './build/*', './dist/*'])
  26. })
  27. /*
  28. * scripts tasks
  29. */
  30. gulp.task('scripts', () => {
  31. return gulp
  32. .src(['./src/scripts/what-input.js'])
  33. .pipe($.standard())
  34. .pipe(
  35. $.standard.reporter('default', {
  36. breakOnError: true,
  37. quiet: false
  38. })
  39. )
  40. .pipe(
  41. $.webpackStream({
  42. module: {
  43. loaders: [
  44. {
  45. test: /.jsx?$/,
  46. loader: 'babel-loader',
  47. exclude: /node_modules/,
  48. query: {
  49. presets: ['env']
  50. }
  51. }
  52. ]
  53. },
  54. output: {
  55. chunkFilename: '[name].js',
  56. library: 'whatInput',
  57. libraryTarget: 'umd',
  58. umdNamedDefine: true
  59. }
  60. })
  61. )
  62. .pipe($.rename('what-input.js'))
  63. .pipe($.header(banner, { pkg: pkg }))
  64. .pipe(gulp.dest('./dist/'))
  65. .pipe(gulp.dest('./build/scripts/'))
  66. .pipe($.sourcemaps.init())
  67. .pipe($.uglify())
  68. .pipe(
  69. $.rename({
  70. suffix: '.min'
  71. })
  72. )
  73. .pipe($.header(banner, { pkg: pkg }))
  74. .pipe($.sourcemaps.write('./maps'))
  75. .pipe(gulp.dest('./dist/'))
  76. .pipe($.notify('Build complete'))
  77. })
  78. /*
  79. * stylesheets
  80. */
  81. gulp.task('styles', () => {
  82. let processors = [
  83. $.autoprefixer({
  84. browsers: ['last 3 versions', '> 1%', 'ie >= 10']
  85. }),
  86. $.cssMqpacker({
  87. sort: true
  88. })
  89. ]
  90. return gulp
  91. .src(['./src/styles/index.scss'])
  92. .pipe(
  93. $.plumber({
  94. errorHandler: $.notify.onError('Error: <%= error.message %>')
  95. })
  96. )
  97. .pipe($.sourcemaps.init())
  98. .pipe($.sassGlob())
  99. .pipe($.sass())
  100. .pipe($.postcss(processors))
  101. .pipe(
  102. $.cssnano({
  103. minifySelectors: false,
  104. reduceIdents: false,
  105. zindex: false
  106. })
  107. )
  108. .pipe($.sourcemaps.write('maps'))
  109. .pipe(gulp.dest('./build/styles'))
  110. .pipe($.browserSync.stream())
  111. .pipe($.notify('Styles task complete'))
  112. })
  113. /*
  114. * images task
  115. */
  116. gulp.task('images', () => {
  117. return gulp.src(['./src/images/**/*']).pipe(gulp.dest('./build/images'))
  118. })
  119. /*
  120. * markup task
  121. */
  122. gulp.task('markup', () => {
  123. return gulp.src(['./src/markup/*']).pipe(gulp.dest('./build'))
  124. })
  125. /*
  126. * deploy task
  127. */
  128. gulp.task('deploy', () => {
  129. return gulp.src('./build/**/*').pipe($.ghPages())
  130. })
  131. /*
  132. * default task
  133. */
  134. gulp.task('default', () => {
  135. $.runSequence('clean', ['markup', 'scripts', 'styles', 'images'], () => {
  136. $.browserSync.init({
  137. server: {
  138. baseDir: './build/'
  139. }
  140. })
  141. gulp
  142. .watch(
  143. ['./src/scripts/what-input.js', './src/scripts/polyfills/*.js'],
  144. ['scripts']
  145. )
  146. .on('change', $.browserSync.reload)
  147. gulp.watch(['./src/styles/{,*/}{,*/}*.scss'], ['styles'])
  148. gulp
  149. .watch(['./src/markup/*.html'], ['markup'])
  150. .on('change', $.browserSync.reload)
  151. })
  152. })