forked from jepser/typeform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
93 lines (80 loc) · 2.31 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
'use strict'
const path = require('path')
const _ = require('lodash')
const gulp = require('gulp')
const sass = require('gulp-sass')
const cssnano = require('gulp-cssnano')
const autoprefixer = require('gulp-autoprefixer')
const rollup = require('rollup').rollup
const watch = require('rollup-watch')
const commonjs = require('rollup-plugin-commonjs')
const nodeResolve = require('rollup-plugin-node-resolve')
const babel = require('rollup-plugin-babel')
const uglify = require('rollup-plugin-uglify')
const replace = require('rollup-plugin-replace')
const args = process.argv
.slice(2)
.filter(arg => arg.indexOf('--') !== -1)
.reduce((result, arg) => {
const [ name, value ] = arg.match(/--(.+)=(.+)/).slice(1)
result[_.camelCase(name)] = value
return result
}, {})
const SRC = './src/'
const DEST = './assets'
let cache
function buildApplication () {
return rollup({
entry: `${SRC}/js/index.js`,
cache: cache,
plugins: [
babel({
exclude: 'node_modules/**',
babelrc: false,
presets: ['react', 'es2015-rollup'],
}),
nodeResolve({ jsnext: true }),
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/react/react.js': ['PropTypes', 'createElement', 'Component'],
},
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
uglify(),
],
}).then((bundle) => {
cache = bundle
return bundle.write({
format: 'iife',
dest: `${DEST}/js/typeform-tinymce.js`,
})
})
}
function buildStyles () {
return gulp.src(`${SRC}/sass/main.scss`)
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['> 10%'],
cascade: false,
}))
.pipe(cssnano())
.pipe(gulp.dest(`${DEST}/css/`))
}
const copyAssets = () => {
if (!args.copyPath) return
gulp.src([ path.resolve('assets/**/*') ])
.pipe(gulp.dest(`${args.copyPath}/assets`))
}
const watchFiles = () => {
gulp.watch('./src/js/**/*.{js,jsx}', ['scripts'])
gulp.watch('./src/sass/**.scss', ['styles'])
if (args.copyPath) gulp.watch('./assets/**/**', ['copy-to-blog'])
}
gulp.task('default', ['scripts', 'styles'])
gulp.task('scripts', buildApplication)
gulp.task('styles', buildStyles)
gulp.task('watch', watchFiles)
gulp.task('copy-to-blog', copyAssets)