-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
110 lines (105 loc) · 2.84 KB
/
gulpfile.ts
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
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import autoprefixer from 'autoprefixer';
import { dest, parallel, series, src, task, watch } from 'gulp';
import cleanCSS from 'gulp-clean-css';
import less from 'gulp-less';
import postcss from 'gulp-postcss';
import pxtorem from 'postcss-pxtorem';
import { rollup } from 'rollup';
import { dts } from 'rollup-plugin-dts';
import svg from 'rollup-plugin-svg-import';
const __dirname = dirname(fileURLToPath(import.meta.url));
const distBundle = resolve(__dirname, './dist');
const demoBundle = resolve(__dirname, './docs');
const buildDts = async () => {
const bundle = await rollup(
{
input: './src/index.ts',
external: [/^quill/],
treeshake: true,
plugins: [dts()],
},
);
return bundle.write({
file: resolve(distBundle, 'index.d.ts'),
sourcemap: false,
format: 'es',
});
};
const buildTs = async (isDev: boolean = false) => {
const plugins = [
typescript({ tsconfig: './tsconfig.json' }),
svg({
stringify: true,
}),
];
!isDev && plugins.push(terser());
const bundle = await rollup(
{
input: './src/index.ts',
external: [/^quill/],
treeshake: true,
plugins,
},
);
if (isDev) {
await bundle.write({
file: resolve(demoBundle, 'dev.js'),
sourcemap: true,
format: 'umd',
name: 'TableUp',
globals: {
quill: 'Quill',
},
exports: 'named',
});
}
return bundle.write({
file: resolve(distBundle, 'index.js'),
sourcemap: true,
format: 'es',
});
};
const buildTheme = async (isDev: boolean = false) => {
const bunlde = await src(['./src/style/index.less', './src/style/table-creator.less'])
.pipe(less())
.pipe(
postcss([
autoprefixer(),
pxtorem({
rootValue: 16,
propList: ['*'],
selectorBlackList: ['.ql-'],
}),
]),
);
if (!isDev) {
await bunlde
.pipe(
cleanCSS({}, (details) => {
console.log(
`${details.name}: ${details.stats.originalSize / 1000} KB -> ${
details.stats.minifiedSize / 1000
} KB`,
);
}),
)
.pipe(dest(distBundle));
}
return bunlde.pipe(dest(demoBundle));
};
const dev = () => {
watch('./src/**/*.ts', parallel(buildTs.bind(undefined, true), buildDts));
watch('./src/**/*.less', buildTheme.bind(undefined, true));
};
task('dev', series(dev));
task('default', parallel(
buildTs.bind(undefined, false),
buildDts,
buildTheme.bind(undefined, false),
buildTs.bind(undefined, true),
buildTheme.bind(undefined, true),
));