-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
82 lines (73 loc) · 2.08 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
/* eslint-disable */
var gulp = require("gulp")
var rollup = require('rollup-stream')
var source = require('vinyl-source-stream')
var webserver = require("gulp-webserver")
var del = require("del")
var env = process.env.NODE_ENV
var isProduction = env === 'production'
// var analyzerOptions = { limit: 15, filter: null }
// bug with rollup-common-js 9.1.3 see https://github.com/dherges/ng-packagr/issues/657
gulp.task("clean", function() {
return del('dist/**', {force:true})
})
gulp.task("copy", function() {
return gulp.src("examples/*.html")
.pipe(gulp.dest("dist"))
})
var plugins = [
require("rollup-plugin-babel")({
exclude: 'node_modules/**'
}),
require("rollup-plugin-node-resolve")({
jsnext: true,
main: true,
browser: true
}),
require("rollup-plugin-replace")({
'process.env.NODE_ENV': JSON.stringify(env),
})
]
if(isProduction) {
plugins.push(require("rollup-plugin-commonjs")({
include: 'node_modules/**'
}))
plugins.push(require("rollup-plugin-uglify")())
// plugins.push(require("rollup-analyzer-plugin")())
} else {
plugins.push(require("rollup-plugin-commonjs")({
include: 'node_modules/**',
namedExports: {
'node_modules/react/index.js': [
'Component',
'PureComponent',
'Fragment',
'Children',
'createElement',
]
},
}))
}
gulp.task("rollup", function() {
return rollup({
input: isProduction ? "src/index.js" : "examples/index.js",
format: isProduction ? "cjs" : "iife",
name: 'pgn',
plugins: plugins,
external: isProduction ? ['react', 'react-dom'] : [],
}).pipe(source("index.js"))
.pipe(gulp.dest("dist"));
})
gulp.task("server", function() {
return gulp.src("dist")
.pipe(webserver({
livereload: true,
port: 8000
}))
})
gulp.task("watch", function() {
gulp.watch("src/**/*.js", gulp.series("rollup"))
gulp.watch("examples/**/*.js", gulp.series("rollup"))
});
gulp.task("dev", gulp.series("clean", gulp.parallel("copy", "rollup"), "server", "watch"));
gulp.task("prod", gulp.series("clean", "rollup"));