forked from g21589/PPTX2HTML
-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
96 lines (88 loc) · 2.47 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
91
92
93
94
95
96
'use strict'
const babel = require('rollup-plugin-babel')
const buffer = require('vinyl-buffer')
const commonJs = require('rollup-plugin-commonjs')
const gulp = require('gulp')
const merge = require('merge-stream')
const nodeResolve = require('rollup-plugin-node-resolve')
const rollup = require('rollup-stream')
const source = require('vinyl-source-stream')
const jetpack = require('fs-jetpack')
const composer = require('gulp-uglify/composer')
const uglifyES = require('uglify-es')
const sourcemaps = require('gulp-sourcemaps')
const rename = require('gulp-rename')
const minify = composer(uglifyES, console)
const destDir = jetpack.cwd('./dist')
const jsFiles = [
{path: 'src/main.js', name: 'pptx2html.js'},
{path: 'src/worker.js', name: 'pptx2html_worker.js'}
]
gulp.task('clean', () =>
destDir.dir('.', {empty: true})
)
const buildClientJsFile = (filePath, fileName, destPath) =>
rollup({
input: filePath,
format: 'iife',
name: 'pptx2html',
plugins: [
babel({
exclude: 'node_modules/core-js/**',
presets: [
['@babel/preset-env',
{
useBuiltIns: 'usage',
modules: false
}
]
]
}),
nodeResolve({
module: true,
main: true
}),
commonJs({
include: 'node_modules/**',
sourceMap: true
})
],
sourcemap: true
})
.pipe(source(fileName))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(destPath))
.on('error', console.error.bind(console))
gulp.task('build', ['clean'], () =>
merge(jsFiles.map(({path, name}) => buildClientJsFile(path, name, destDir.path())))
)
gulp.task('build-full', ['build'], () => destDir.write(
'pptx2html.full.js',
[
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/jszip/dist/jszip.min.js',
'./node_modules/d3/build/d3.min.js',
'./node_modules/dimple/dist/dimple.latest.min.js',
destDir.path('pptx2html.js')
]
.map(filePath => jetpack.read(filePath))
.join(';'))
)
gulp.task('minify', ['build-full'], () =>
gulp.src('dist/**/*.js')
.pipe(rename(p => { p.extname = '.min.js' }))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(minify({
compress: {
passes: 2,
typeofs: false
},
ie8: true
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(destDir.path()))
.on('error', console.error.bind(console))
)