You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
4.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. let fs = require('fs'),
  2. gulp = require('gulp'),
  3. concat = require('gulp-concat'),
  4. minify = require('gulp-minify'),
  5. cleanCSS = require('gulp-clean-css'),
  6. size = require('gulp-size'),
  7. sass = require('gulp-sass'),
  8. sourcemaps = require('gulp-sourcemaps');
  9. let packageFile = JSON.parse(fs.readFileSync('source.info.json'));
  10. let theme = packageFile.source;
  11. let destPath = packageFile.destPath;
  12. let watchPath = packageFile.watch;
  13. gulp.task('minify-desktop-css', function () {
  14. let dest = destPath.root + "/" + destPath.assets + "/" + destPath.css;
  15. let fileName = "desktop.min.css";
  16. return gulp.src( theme.desktop.css )
  17. .pipe(sourcemaps.init())
  18. .pipe( sass({outputStyle: 'compact'}).on('error', sass.logError))
  19. .pipe( concat(fileName)) //병합하고
  20. .pipe(cleanCSS().on('error', function(e){console.log(e);}))
  21. .pipe(size({ gzip: true, showFiles: true }))
  22. .pipe(sourcemaps.write('.'))
  23. .pipe(gulp.dest(dest));
  24. });
  25. // Javascript 합치기 실행
  26. gulp.task('minify-desktop-js', function(){
  27. let dest = destPath.root + "/" + destPath.assets + "/" + destPath.js;
  28. let fileName = "desktop.js";
  29. return gulp.src( theme.commonJs.concat( theme.desktop.js ) )
  30. .pipe(sourcemaps.init())
  31. .pipe(concat(fileName))
  32. .pipe(minify({ext: {min : '.min.js'},noSource:true}))
  33. .pipe(size({ gzip: true, showFiles: true }))
  34. .pipe(sourcemaps.write('.'))
  35. .pipe(gulp.dest(dest));
  36. });
  37. gulp.task('minify-mobile-css', function () {
  38. let dest = destPath.root + "/" + destPath.assets + "/" + destPath.css;
  39. let fileName = "mobile.min.css";
  40. return gulp.src( theme.mobile.css )
  41. .pipe(sourcemaps.init())
  42. .pipe( sass({outputStyle: 'compact'}).on('error', sass.logError))
  43. .pipe( concat(fileName)) //병합하고
  44. .pipe(cleanCSS().on('error', function(e){console.log(e);}))
  45. .pipe(size({ gzip: true, showFiles: true }))
  46. .pipe(sourcemaps.write('.'))
  47. .pipe(gulp.dest(dest));
  48. });
  49. gulp.task('minify-mobile-js', function(){
  50. let dest = destPath.root + "/" + destPath.assets + "/" + destPath.js;
  51. let fileName = "mobile.js";
  52. return gulp.src( theme.commonJs.concat( theme.mobile.js ) )
  53. .pipe(sourcemaps.init())
  54. .pipe(concat(fileName))
  55. .pipe(minify({ext: {min : '.min.js'},noSource:true}))
  56. .pipe(size({ gzip: true, showFiles: true }))
  57. .pipe(sourcemaps.write('.'))
  58. .pipe(gulp.dest(dest));
  59. });
  60. gulp.task('minify-admin-css', function () {
  61. let dest = destPath.root + "/" + destPath.assets + "/" + destPath.css;
  62. let fileName = "admin.min.css";
  63. return gulp.src( theme.admin.css )
  64. .pipe(sourcemaps.init())
  65. .pipe( sass({outputStyle: 'compact'}).on('error', sass.logError))
  66. .pipe( concat(fileName)) //병합하고
  67. .pipe(cleanCSS().on('error', function(e){console.log(e);}))
  68. .pipe(size({ gzip: true, showFiles: true }))
  69. .pipe(sourcemaps.write('.'))
  70. .pipe(gulp.dest(dest));
  71. });
  72. gulp.task('minify-admin-js', function(){
  73. let dest = destPath.root + "/" + destPath.assets + "/" + destPath.js;
  74. let fileName = "admin.js";
  75. return gulp.src( theme.commonJs.concat( theme.admin.js ) )
  76. .pipe(sourcemaps.init())
  77. .pipe(concat(fileName))
  78. .pipe(minify({ext: {min : '.min.js'},noSource:true}))
  79. .pipe(size({ gzip: true, showFiles: true }))
  80. .pipe(sourcemaps.write('.'))
  81. .pipe(gulp.dest(dest));
  82. });
  83. gulp.task('scss-watch', function() {
  84. gulp.watch(watchPath.desktop.css, gulp.series(['minify-desktop-css']));
  85. //gulp.watch(watchPath.desktop.js, ['minify-desktop-js']);
  86. gulp.watch(watchPath.mobile.css, gulp.series(['minify-mobile-css']));
  87. //gulp.watch(watchPath.mobile.js, ['minify-mobile-js']);
  88. gulp.watch(watchPath.admin.css, gulp.series(['minify-admin-css']));
  89. //gulp.watch(watchPath.admin.js, ['minify-admin-js']);
  90. });
  91. gulp.task('default', gulp.series(['minify-desktop-js', 'minify-desktop-css', 'minify-mobile-js', 'minify-mobile-css','minify-admin-js', 'minify-admin-css']));