1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
| Skip to content Search or jump to…
Pull requests Issues Marketplace Explore
@pythongyj pythongyj / gulp-temp-demo 1 00 Code Issues Pull requests Actions Projects Wiki Security Insights Settings gulp-temp-demo/gulpfile.js / @pythongyj pythongyj init Latest commit 6926e3b 6 minutes ago History 1 contributor 204 lines (187 sloc) 4.94 KB
const gulp = require("gulp");
const cssmin = require("gulp-cssmin");
const htmlmin = require("gulp-htmlmin");
const uglify = require("gulp-uglify");
const imagemin = require("gulp-imagemin");
const cleanCSS = require("gulp-clean-css");
const less = require("gulp-less");
const LessAutoprefix = require("less-plugin-autoprefix"); const autoprefix = new LessAutoprefix({ browsers: ["last 2 versions"] }); const clearDist = require("gulp-clean");
const path = require("path"); const rename = require("gulp-rename"); const server = require("gulp-webserver");
const fileinclude = require("gulp-file-include");
const cssHandler = function () { return gulp .src("./src/pages/**/*.less") .pipe( less({ paths: [path.join(__dirname, "less", "includes")], plugins: [autoprefix], }) ) .pipe(cleanCSS()) .pipe(cssmin()) .pipe(rename({ extname: ".min.css" })) .pipe(gulp.dest("./dist/pages/")); };
const cssPubHandler = function () { return gulp .src("./src/accets/*.less") .pipe( less({ paths: [path.join(__dirname, "less", "includes")], plugins: [autoprefix], }) ) .pipe(cleanCSS()) .pipe(cssmin()) .pipe(rename({ extname: ".min.css" })) .pipe(gulp.dest("./dist/accets/")); };
const htmlHomeHandler = function (cb) { cb(); return gulp .src("./src/*.html") .pipe( fileinclude({ prefix: "@@", }) ) .pipe( htmlmin({ collapseWhitespace: true, removeEmptyAttributes: true, minifyCSS: true, minifyJS: true, minifyURLs: true, }) ) .pipe(rename({ extname: ".min.html" })) .pipe(gulp.dest("./dist/")); };
const htmlProductsHandler = function () { return gulp .src("./src/pages/**/*.html") .pipe( fileinclude({ prefix: "@@", basepath: "@file", }) ) .pipe( htmlmin({ collapseWhitespace: true, removeEmptyAttributes: true, minifyCSS: true, minifyJS: true, minifyURLs: true, }) ) .pipe(rename({ extname: ".min.html" })) .pipe(gulp.dest("./dist/pages/")); };
const jsHandler = function () { return gulp .src("./src/pages/**/*.js") .pipe(uglify()) .pipe(rename({ extname: ".min.js" })) .pipe(gulp.dest("./dist/pages")); };
const jsCompontHandler = function () { return gulp .src("./src/components/**/*.js") .pipe(uglify()) .pipe(rename({ extname: ".min.js" })) .pipe(gulp.dest("./dist/components")); };
const cssCompontHandler = function () { return gulp .src("./src/components/**/*.less") .pipe( less({ paths: [path.join(__dirname, "less", "includes")], plugins: [autoprefix], }) ) .pipe(cleanCSS()) .pipe(cssmin()) .pipe(rename({ extname: ".min.css" })) .pipe(gulp.dest("./dist/components/")); };
const jQueryHandler = function () { return gulp .src("./node_modules/jquery/dist/jquery.min.js") .pipe(gulp.dest("./dist/lib")); };
const otherHandler = function () { return gulp .src("./src/lib/**") .pipe(gulp.dest("./dist/lib")); };
const imgHandler = function () { return gulp .src("./src/assets/img/*.*") .pipe(imagemin()) .pipe(gulp.dest("./dist/assets/img")); };
const clearDistFile = function () { return gulp.src(["dist/*"]).pipe(clearDist()); };
const watchFile = function () { gulp.watch("src/**/*.less", cssHandler); gulp.watch("src/**/*.js", jsHandler); gulp.watch("src/**/*.html", htmlProductsHandler, htmlHomeHandler); };
const serverHandler = function () { return gulp.src("./dist").pipe( server({ host: "127.0.0.1", prot: "8080", livereload: true, open: "./pages/index/index.min.html", proxies: [ { source: "/api/v1", target: "http://192.168.101.13:8080/api/v1/", }, ], }) ); }; module.exports.dev = gulp.series( clearDistFile, gulp.parallel( cssHandler, cssPubHandler, otherHandler, htmlHomeHandler, jsHandler, htmlProductsHandler, jsCompontHandler, cssCompontHandler, imgHandler, jQueryHandler ), serverHandler, watchFile );
|