From 4002aee18e5998110134206e6c7e932495c9ca31 Mon Sep 17 00:00:00 2001 From: Jonas Kirkemyr Date: Fri, 2 Jul 2021 00:17:17 +0200 Subject: [PATCH 1/2] add gulp development scripts Introduced gulp development tasks to watch source files, serve built project using browser-sync, and automatically reload the server upon changes --- gulpfile.js | 33 ++++++++++++++++++++++++++++++++- package.json | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 7298db29..9ea18f7e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,6 +4,9 @@ const useref = require('gulp-useref'); const replace = require('gulp-replace'); const cachebust = require('gulp-cache-bust'); const minify = require('gulp-minify'); +const browserSync = require("browser-sync"); + +const server = browserSync.create(); gulp.task('css', function () { return gulp.src('src/css/*.css') @@ -78,4 +81,32 @@ gulp.task('build', 'shapelib', 'canvg' ) -); \ No newline at end of file +); + +gulp.task('serve', function () { + server.init({ + server: { + baseDir: './dist', + }, + }); +}); + +gulp.task('reload', function (done) { + server.reload(); + done(); +}); + +gulp.task('watch', function () { + gulp.watch('src/css/*.css', gulp.series('css', 'reload')); + gulp.watch(['src/js/*.js', 'src/lib/*.js'], gulp.series('js', 'reload')); + gulp.watch('src/js/loading.js', gulp.series('loading', 'reload')); + gulp.watch('src/*.html', gulp.series('index', 'reload')); + gulp.watch('src/site.webmanifest', gulp.series('manifest', 'reload')); + gulp.watch('src/images/**/*', gulp.series('images', 'reload')); + gulp.watch('src/font-files/**/*', gulp.series('fonts', 'reload')); + gulp.watch('src/extensions/**/*', gulp.series('extensions', 'reload')); + gulp.watch('src/shapelib/**/*', gulp.series('shapelib', 'reload')); + gulp.watch(['src/js/lib/canvg.js', 'src/js/lib/rgbcolor.js'], gulp.series('canvg', 'reload')); +}); + +gulp.task('dev', gulp.series('build', gulp.parallel('watch', 'serve'))); diff --git a/package.json b/package.json index 3e38fc12..b5a29e77 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ }, "homepage": "https://github.com/methodofaction/Method-Draw#readme", "devDependencies": { + "browser-sync": "2.27.4", "gulp": "^4.0.2", "gulp-cache-bust": "^1.4.1", "gulp-concat": "^2.6.1", From cf0eb5a91ec2ddd6934bb3fc5dfe0f9d8c95b894 Mon Sep 17 00:00:00 2001 From: Jonas Kirkemyr Date: Fri, 2 Jul 2021 00:24:41 +0200 Subject: [PATCH 2/2] add npm scripts for common operations Added npm script for building the project, and running the project in development mode Updated README describing the usage of the new npm scripts --- package.json | 2 ++ readme.md | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b5a29e77..70f43da3 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "test": "test" }, "scripts": { + "build": "gulp build", + "dev": "gulp dev", "test": "test" }, "repository": { diff --git a/readme.md b/readme.md index 483bb428..3d667b9c 100644 --- a/readme.md +++ b/readme.md @@ -28,6 +28,12 @@ cd src python -m http.server 8000 ``` +or using npm: + +```sh +npm run dev +``` + ## Build Install dev dependencies: @@ -36,7 +42,7 @@ Install dev dependencies: Then you can build into `dist` by running: -`gulp build` +`npm run build` Deploy `dist` to your static file server of choice.