-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
126 lines (113 loc) · 3.16 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import autoprefixer from 'autoprefixer'
import gulp from 'gulp'
import livereload from 'gulp-livereload'
import postcss from 'gulp-postcss'
// import readmeToMD from 'gulp-readme-to-markdown'
import rename from 'gulp-rename'
import sass from 'gulp-sass'
import sourcemaps from 'gulp-sourcemaps'
import gutil from 'gulp-util'
import merge from 'merge-stream'
import webpack from 'webpack'
import webpackStream from 'webpack-stream'
const PRODUCTION = process.argv.indexOf('--production') > -1
// gulp.task('readme', readme)
gulp.task('build', /*['readme'], */build)
gulp.task('watch', /*['readme'], */watch)
gulp.task('default', ['watch'])
function build() {
return merge(
styles(),
scripts(getWebpackBaseConfig())
)
}
function watch() {
livereload.listen()
// gulp.watch('discgolfmetrix/readme.txt', readme)
gulp.watch('styles/*.scss', styles)
gulp.watch(['discgolfmetrix/scripts/*.js', 'discgolfmetrix/styles/**/*.css', 'discgolfmetrix/**/*.php'], (evt) =>
livereload.changed(evt.path)
)
return merge(
styles(),
scripts({
...getWebpackBaseConfig(),
watch: true
})
)
}
function styles() {
return gulp.src('styles/[^_]*.scss')
.pipe(rename(path => path.basename = `discgolfmetrix-${path.basename}`))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(postcss([autoprefixer(/* project-wide options are in browserslist file in project root */)]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('discgolfmetrix/styles'))
}
function scripts(config) {
return webpackStream(config)
.on('error', function (err) {
console.error(err.stack || err)
this.emit('end')
})
.pipe(gulp.dest('discgolfmetrix/scripts'))
}
function getWebpackBaseConfig() {
const config = {
target: 'web',
plugins: [
new webpack.DefinePlugin({
PRODUCTION,
/**
* Keeping it "production" for Redux
* @see https://github.com/reactjs/redux/issues/1029
*/
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin()
],
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}, {
test: /\.(jpg|jpeg|png|woff|woff2|eot|ttf|svg)/,
loader: 'url-loader?limit=100000'
}]
},
devtool: 'source-map'
}
return {
config: [{
...config,
entry: './scripts/results.js',
output: {
filename: 'discgolfmetrix-results.js'
}
}, {
...config,
entry: './scripts/settings.js',
output: {
filename: 'discgolfmetrix-settings.js'
}
}]
}
}
/*function readme() {
return gulp
.src('discgolfmetrix/readme.txt')
.pipe(readmeToMD({
screenshot_url: 'screenshots/{screenshot}.{ext}',
screenshot_ext: 'gif',
extract: {}
}))
.pipe(gulp.dest('.'))
/* add screenshots to README.md manually:
![](discgolfmetrix/screenshot-1.gif)<br>
1. Results table with filter
![](discgolfmetrix/screenshot-2.gif)<br>
2. Results filter options
*
}*/