-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
122 lines (114 loc) · 3.04 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
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
/**
* Gulp Config
*/
// Import modules
import Gulp from 'gulp'
import autoPrefixer from 'gulp-autoprefixer'
import concat from 'gulp-concat'
import gulpCssnano from 'gulp-cssnano'
import rename from 'gulp-rename'
import sass from 'sass'
import gulpSass from 'gulp-sass'
import webpack from 'webpack'
import webpackStream from 'webpack-stream'
import TerserPlugin from 'terser-webpack-plugin'
const sassCompiler = gulpSass(sass)
// Implement functions
function compileAdminJS () {
return Gulp
.src('./admin/js/ninja-forms-spn-addon-admin.js')
.pipe(
webpackStream({
mode: 'production',
output: {
filename: 'spn-back-[name].min.js'
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
]
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
}, webpack),
)
.pipe(Gulp.dest('./dist/admin/'))
}
function compilePublicJS () {
return Gulp
.src('./public/js/ninja-forms-spn-addon-public.js')
.pipe(
webpackStream({
mode: 'production',
output: {
filename: 'spn-front-[name].min.js'
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
]
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
}, webpack),
)
.pipe(Gulp.dest('./dist/public/'))
}
function compileCss () {
return Gulp.src('./public/scss/ninja-forms-spn-addon-public.scss')
.pipe(sassCompiler({
outputStyle: 'compressed',
includePaths: [
'./node_modules'
]
}).on('error', sassCompiler.logError))
.pipe(gulpCssnano())
.pipe(concat('addon-public.css'))
.pipe(rename({ suffix: '.min' }))
.pipe(autoPrefixer('last 2 versions'))
.pipe(Gulp.dest('./dist/public/'))
}
function watchFiles () {
Gulp.watch('./admin/js/**/*.js', compileAdminJS)
Gulp.watch('./public/js/**/*.js', compilePublicJS)
Gulp.watch('./public/scss/**/*.scss', compileCss)
}
const build = Gulp.series(compileAdminJS, compilePublicJS, compileCss, watchFiles)
// Export
export { compileAdminJS, compilePublicJS, compileCss, watchFiles as watch, build, build as default }