Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update gulp4 #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 79 additions & 93 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,112 +2,98 @@

const del = require('del');
const gulp = require('gulp');

const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const concat = require('gulp-concat');
const imagemin = require('gulp-imagemin');
const replace = require('gulp-replace');
const server = require('gulp-webserver');
const terser = require('gulp-terser');
const server = require('gulp-webserver');

gulp.task('clean', function() {
return del('dist/*');
});

gulp.task('html', ['clean'], function() {
gulp.src([
'src/index.html',
'src/small.html',
'src/embed.html'
])
.pipe(replace(/\.\.\/dist\//g, ''))
.pipe(gulp.dest('./dist/'));

gulp.src([
'src/index.html'
])
.pipe(replace(/\.\.\/dist\//g, '../'))
.pipe(gulp.dest('./dist/embed/'));
});
const paths = {
html: [
'src/index.html',
'src/small.html',
'src/embed.html'
],
css: [
'node_modules/leaflet/dist/leaflet.css',
'src/_css/leaflet.coordinates.css',
'src/_css/leaflet.buttons.css',
'node_modules/leaflet-fullscreen/dist/leaflet.fullscreen.css',
'src/_css/map.css'
],
js: [
require.resolve('leaflet'),
'src/_js/leaflet.coordinates.js',
'src/_js/leaflet.crosshairs.js',
'src/_js/leaflet.levelbuttons.js',
'src/_js/leaflet.exivabutton.js',
'src/_js/leaflet.markersbutton.js',
require.resolve('leaflet-fullscreen'),
'src/_js/map.js'
],
images: [
'node_modules/leaflet-fullscreen/dist/*.png',
'src/_css/*.png',
'src/_img/marker-icons/*.png'
],
favicon: 'src/favicon.ico',
dist: 'dist'
};

gulp.task('css', function() {
gulp.src([
require.resolve('leaflet/dist/leaflet.css'),
'src/_css/leaflet.coordinates.css',
'src/_css/leaflet.buttons.css',
'node_modules/leaflet-fullscreen/dist/leaflet.fullscreen.css',
'src/_css/map.css'
])
.pipe(concat('map.css'))
.pipe(autoprefixer()) // This (also) removes unneeded prefixes.
.pipe(cleanCSS())
.pipe(gulp.dest('./dist/'));
});
function clean() {
return del([paths.dist]);
}

gulp.task('js', function() {
gulp.src([
require.resolve('leaflet'),
'src/_js/leaflet.coordinates.js',
'src/_js/leaflet.crosshairs.js',
'src/_js/leaflet.levelbuttons.js',
'src/_js/leaflet.exivabutton.js',
'src/_js/leaflet.markersbutton.js',
require.resolve('leaflet-fullscreen'),
'src/_js/map.js'
])
.pipe(concat('map.js'))
.pipe(terser())
.pipe(gulp.dest('./dist/'));
});
function html() {
return gulp.src(paths.html)
.pipe(replace(/\.\.\/dist\//g, ''))
.pipe(gulp.dest(`${paths.dist}/`));
}

gulp.task('css-img', function() {
gulp.src([
'node_modules/leaflet-fullscreen/dist/*.png',
'src/_css/*.png',
])
//.pipe(imagemin({
// 'optimizationLevel': 7
//}))
.pipe(gulp.dest('./dist/'));
function css() {
return gulp.src(paths.css)
.pipe(concat('map.css'))
.pipe(autoprefixer())
.pipe(cleanCSS())
.pipe(gulp.dest(`${paths.dist}/`));
}

gulp.src([
'src/_img/marker-icons/*.png',
])
//.pipe(imagemin({
// 'optimizationLevel': 7
//}))
.pipe(gulp.dest('./dist/_img/marker-icons/'));
});
function js() {
return gulp.src(paths.js)
.pipe(concat('map.js'))
.pipe(terser())
.pipe(gulp.dest(`${paths.dist}/`));
}

gulp.task('img-img', function() {
gulp.src([
'src/_img/marker-icons/*.png',
])
//.pipe(imagemin({
// 'optimizationLevel': 7
//}))
.pipe(gulp.dest('./dist/_img/marker-icons/'));
});
function images() {
return gulp.src(paths.images)
.pipe(imagemin())
.pipe(gulp.dest(`${paths.dist}/`));
}

gulp.task('copy', function() {
gulp.src(
'src/favicon.ico'
)
.pipe(gulp.dest('./dist/'));
});
function copyFavicon() {
return gulp.src(paths.favicon)
.pipe(gulp.dest(paths.dist));
}

//gulp.task('watch', function() {
// gulp.watch('src/**', ['default']);
//});
function serve() {
return gulp.src(paths.dist)
.pipe(server({
livereload: false,
open: true
}));
}

gulp.task('serve', function() {
gulp.src('dist')
.pipe(server({
'livereload': false,
'open': true
}));
});
const build = gulp.series(clean, gulp.parallel(html, css, js, images, copyFavicon));

gulp.task('build', ['clean', 'html', 'css', 'js', 'css-img', 'img-img', 'copy']);
gulp.task('default', ['build', 'serve']);
gulp.task('clean', clean);
gulp.task('html', html);
gulp.task('css', css);
gulp.task('js', js);
gulp.task('images', images);
gulp.task('copyFavicon', copyFavicon);
gulp.task('serve', serve);
gulp.task('build', build);
gulp.task('default', gulp.series('build', 'serve'));
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"private": true,
"dependencies": {
"gulp": "^5.0.0",
"gulp-cli": "^3.0.0",
"leaflet": "^1.0.2",
"leaflet-fullscreen": "^1.0.1"
},
"devDependencies": {
"@alrra/travis-scripts": "^3.0.1",
"del": "^2.2.0",
"gulp": "^3.9.0",
"gulp-autoprefixer": "^3.1.0",
"gulp-clean-css": "^2.0.10",
"gulp-concat": "^2.6.0",
Expand Down
Loading