-
Notifications
You must be signed in to change notification settings - Fork 67
/
gulpfile.babel.js
80 lines (70 loc) · 1.73 KB
/
gulpfile.babel.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
import {writeFile, mkdirSync} from 'fs';
import gulp from 'gulp';
import del from 'del';
import sequence from 'run-sequence';
import {rollup} from 'rollup';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babelRollup from 'rollup-plugin-babel';
import {Bundler} from 'polymer-bundler';
import {serialize} from 'parse5';
import pify from 'pify';
gulp.task('default', ['dist']);
gulp.task('clean', () => del(['lib', 'dist']));
gulp.task('build', done => sequence(['clean'], ['build:lib', 'build:copy'], done));
gulp.task('build:lib', () => {
return rollup({
entry: 'src/index.js',
plugins: [
nodeResolve({
jsnext: true,
main: true
}),
commonjs({
include: 'node_modules/**'
}),
babelRollup({
babelrc: false,
presets: [['env', {
targets: {
browsers: [
'last 2 versions',
'not ie 10'
]
},
modules: false,
exclude: [
'transform-es2015-classes'
]
}]],
plugins: [
'transform-object-assign'
]
})
]
}).then(bundle => {
return bundle.write({
format: 'iife',
moduleName: 'PolymerRedux',
dest: 'lib/index.js'
});
});
});
gulp.task('build:copy', () => gulp.src(['src/**.html']).pipe(gulp.dest('lib')));
gulp.task('dist', ['build'], () => {
const entry = 'lib/index.html';
const b = new Bundler({
inlineScripts: true
});
return b.generateManifest([entry])
.then(manifest => b.bundle(manifest))
.then(bundles => {
const {ast} = bundles.documents.get(entry);
const html = serialize(ast);
mkdirSync('dist');
return pify(writeFile)('dist/polymer-redux.html', `${html}\n`);
});
});
gulp.task('develop', ['dist'], () => {
gulp.watch(['src/**/*'], ['dist']);
});