-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.babel.js
178 lines (159 loc) · 3.88 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import gulp from 'gulp';
import path from 'path';
import webpack from 'webpack';
import BrowserSync from 'browser-sync';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import VueLoaderPlugin from 'vue-loader/lib/plugin';
import copyCodeMirror from './gulp-build-codemirror';
// let uglify = uglifyES.default;
// On 'webpack-hot-middleware/client', `?reload=true` tells client to reload if HMR fails.
const devServer = [ 'webpack/hot/dev-server', 'webpack-hot-middleware/client?reload=true' ];
let rules = [];
rules.push({
test: /\.vue$/,
loader: 'vue-loader'
});
rules.push({
test: /\.babel.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}
});
rules.push({
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
});
rules.push({
test: /\.(jpe?g|png|ttf|eot|svg|woff(2)?)$/,
use: 'base64-inline-loader'
});
rules.push({
test: /\.less$/,
use: [
'vue-style-loader',
'css-loader',
'less-loader'
]
});
rules.push({
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
]
});
let config = {
entry: {
'js/settings-page.min': [ './dist/js/settings-page.babel.js' ],
'js/global-page.min': [ './dist/js/global-page.babel.js' ],
'js/hoops-page.min': [ './dist/js/hoops-page.babel.js' ],
'js/meta-box.min': [ './dist/js/meta-box.babel.js' ],
'js/block.min': [ './dist/js/block.babel.js' ],
'js/sidebar.min': [ './dist/js/sidebar.babel.js' ],
'js/theme-page.min': [ './dist/js/theme-page.babel.js' ],
'js/rest.min': [ './dist/js/rest.babel.js' ]
},
output: {
filename: '[name].js',
path: path.resolve( __dirname, 'dist' ),
publicPath: '/wp-content/plugins/scripts-n-styles'
},
context: path.resolve( __dirname ),
module: {
rules: rules
},
resolve: {
extensions: [ '*', '.js', '.vue', '.json' ]
},
externals: {
wpjquery: 'jQuery'
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'wpjquery',
'window.$': 'wpjquery'
}),
new VueLoaderPlugin()
],
mode: 'production'
};
let devConfig = {
entry: {
'js/settings-page.min': [ ...devServer, './dist/js/settings-page.babel.js' ],
'js/global-page.min': [ ...devServer, './dist/js/global-page.babel.js' ],
'js/hoops-page.min': [ ...devServer, './dist/js/hoops-page.babel.js' ],
'js/meta-box.min': [ ...devServer, './dist/js/meta-box.babel.js' ],
'js/block.min': [ ...devServer, './dist/js/block.babel.js' ],
'js/sidebar.min': [ ...devServer, './dist/js/sidebar.babel.js' ],
'js/theme-page.min': [ ...devServer, './dist/js/theme-page.babel.js' ],
'js/rest.min': [ ...devServer, './dist/js/rest.babel.js' ]
},
output: config.output,
context: config.context,
externals: config.externals,
resolve: config.resolve,
module: config.module,
mode: 'development',
devtool: 'eval',
plugins: [
...config.plugins,
new webpack.HotModuleReplacementPlugin()
]
};
const server = BrowserSync.create();
const compiler = webpack( config );
const devCompiler = webpack( devConfig );
function reload( done ) {
server.reload();
done();
}
function compile( done ) {
compiler.run( done );
}
function serve( done ) {
server.init({
proxy: 'https://scriptsnstyles.test',
host: 'scriptsnstyles.test',
open: 'external',
https: {
key: './ssl/localhost.key',
cert: './ssl/localhost.crt'
},
middleware: [
webpackDevMiddleware( devCompiler, {
publicPath: devConfig.output.publicPath,
stats: { colors: true }
}),
webpackHotMiddleware( devCompiler )
]
}, done );
}
function watch( done ) {
gulp.watch([ 'dist/**/*.php' ], reload );
done();
}
const build = gulp.series( compile );
const buildFull = gulp.series( copyCodeMirror, build );
const dev = gulp.series( build, serve, watch );
export {
watch,
copyCodeMirror,
compile,
serve,
reload,
dev,
build,
buildFull
};
export default dev;