-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
gulpfile.js
90 lines (75 loc) · 2.61 KB
/
gulpfile.js
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
import gulp from 'gulp';
import { createGulpEsbuild } from 'gulp-esbuild';
import { default as throught2 } from 'through2';
import { deleteAsync } from 'del';
import stylus from 'gulp-stylus';
import concat from 'gulp-concat';
import cleanCSS from 'gulp-clean-css';
import minimist from 'minimist';
// eslint-disable-next-line import/no-unresolved
import gulpEslint from 'gulp-eslint-new';
import livereload from 'gulp-livereload';
import NodeResolve from '@esbuild-plugins/node-resolve';
import sveltePlugin from 'esbuild-svelte';
const { series, parallel, src, dest } = gulp;
const noop = throught2.obj;
const DIST_PATH = 'dist/';
const isProd = minimist(process.argv.slice(2)).prod;
let gulpEsbuild = createGulpEsbuild({ incremental: false });
const cleanup = () => deleteAsync(['dist/*']);
const assets = () => src(['src/assets/**/*.*']).pipe(dest(DIST_PATH));
const htmls = () => src(['src/*.html', 'src/*.json']).pipe(dest(DIST_PATH));
export function eslint () {
return src(['src/**/*.js', 'src/**/*.svelte', '*.js'])
.pipe(gulpEslint({ fix: true })) // Lint files, create fixes.
.pipe(gulpEslint.fix()) // Fix files if necessary.
.pipe(gulpEslint.format())
.pipe(gulpEslint.results(results => {
if (results.errorCount) console.log('\x07'); // beep
}));
}
export function css () {
return src('src/**/*.styl', { sourcemaps: !isProd })
.pipe(stylus({ 'include css': true }))
.pipe(concat('index.css'))
.pipe(isProd ? cleanCSS() : noop())
.pipe(dest(DIST_PATH, { sourcemaps: '.' }))
.pipe(livereload());
}
export function js () {
const cfg = {
outfile: 'index.js',
mainFields: ['svelte', 'browser', 'module', 'main'],
bundle: true,
minify: isProd,
sourcemap: !isProd,
loader: { '.svg': 'text' },
logLevel: 'warning',
legalComments: 'none',
format: 'iife',
treeShaking: true,
color: true,
plugins: [
sveltePlugin({ compilerOptions: { dev: !isProd, css: 'external' } }),
// @ts-ignore
NodeResolve.default({ extensions: ['.js', '.svelte'] }),
],
};
return src('./src/index.js', { sourcemaps: !isProd })
// @ts-ignore
.pipe(gulpEsbuild(cfg))
.pipe(dest(DIST_PATH, { sourcemaps: '.' }))
.pipe(livereload());
}
export function watch (done) {
if (isProd) return done();
livereload.listen();
gulpEsbuild = createGulpEsbuild({ incremental: true });
gulp.watch('src/**/*.styl', css);
gulp.watch('src/**/*.{js,svelte}', series(eslint, js));
gulp.watch('src/*.html', htmls);
gulp.watch('src/assets/**/*.*', assets);
}
export const lint = parallel(eslint);
export const build = series(cleanup, parallel(js, css, assets, htmls, eslint));
export default series(build, watch);