1
1
const pkg = require ( './package.json' )
2
+ const TerserPlugin = require ( 'terser-webpack-plugin' )
2
3
const areas = {
3
4
constructWp : {
4
5
path : './plugins/construct-wp' ,
5
6
name : 'construct-wp' ,
6
7
title : 'ConstructWP' ,
7
- version : '0.1.0' ,
8
+ version : '0.2.0' ,
9
+ } ,
10
+ }
11
+
12
+ const translatePipes = {
13
+ checktextdomain : {
14
+ text_domain : 'text-domain' ,
15
+ keywords : [
16
+ '__:1,2d' ,
17
+ '_e:1,2d' ,
18
+ '_x:1,2c,3d' ,
19
+ '_ex:1,2c,3d' ,
20
+ '_n:1,2,4d' ,
21
+ '_nx:1,2,4c,5d' ,
22
+ '_n_noop:1,2,3d' ,
23
+ '_nx_noop:1,2,3c,4d' ,
24
+ 'esc_html__:1,2d' ,
25
+ 'esc_html_e:1,2d' ,
26
+ 'esc_html_x:1,2c,3d' ,
27
+ 'esc_attr__:1,2d' ,
28
+ 'esc_attr_e:1,2d' ,
29
+ 'esc_attr_x:1,2c,3d' ,
30
+ ] ,
31
+ report_missing : true ,
32
+ report_success : false ,
33
+ report_variable_domain : true ,
34
+ correct_domain : true ,
35
+ create_report_file : false ,
36
+ force : false ,
37
+ } ,
38
+ pot : {
39
+ domain : 'text-domain' ,
40
+ package : 'Package Name' ,
41
+ team : `${ pkg . author . name } <${ pkg . author . email } >` ,
42
+ lastTranslator : `${ pkg . author . name } <${ pkg . author . email } >` ,
8
43
} ,
9
44
}
10
45
@@ -15,7 +50,6 @@ module.exports = {
15
50
paths : [
16
51
`${ areas . constructWp . path } /assets` ,
17
52
`${ areas . constructWp . path } /dist` ,
18
- `${ areas . constructWp . path } /languages` ,
19
53
] ,
20
54
pipes : {
21
55
del : {
@@ -43,7 +77,7 @@ module.exports = {
43
77
src : {
44
78
allowEmpty : true ,
45
79
base : `${ areas . constructWp . path } /src/scss` ,
46
- sourcemaps : process . env . NODE_ENV ! == 'development' ,
80
+ sourcemaps : process . env . NODE_ENV = == 'development' ,
47
81
} ,
48
82
dest : {
49
83
sourcemaps : '.' ,
@@ -103,6 +137,92 @@ module.exports = {
103
137
} ,
104
138
} ,
105
139
} ,
140
+ scripts : {
141
+ process : true ,
142
+ watch : true ,
143
+ logColor : 'magenta' ,
144
+ areas : [
145
+ {
146
+ paths : {
147
+ src : `${ areas . constructWp . path } /src/js/**/*` ,
148
+ watch : `${ areas . constructWp . path } /src/js/**/*` ,
149
+ dest : `${ areas . constructWp . path } /assets/js` ,
150
+ } ,
151
+ minify : {
152
+ process : process . env . NODE_ENV !== 'development' ,
153
+ separate : false ,
154
+ } ,
155
+ pipes : {
156
+ // Put any pipe overrides here
157
+ src : {
158
+ allowEmpty : true ,
159
+ base : `${ areas . constructWp . path } /src/js` ,
160
+ sourcemaps : process . env . NODE_ENV === 'development' ,
161
+ } ,
162
+ dest : {
163
+ sourcemaps : '.' ,
164
+ } ,
165
+ } ,
166
+ } ,
167
+ ] ,
168
+ pipes : {
169
+ filters : {
170
+ lint : [
171
+ '**/*.js' ,
172
+ ] ,
173
+ build : [
174
+ '**/*.js' ,
175
+ '!**/libs/**/*.js' ,
176
+ ] ,
177
+ } ,
178
+ watch : {
179
+ events : 'all' ,
180
+ } ,
181
+ eslint : {
182
+ // Overrides the version of eslint used
183
+ eslint : null ,
184
+ formatter : 'stylish' ,
185
+ options : {
186
+ fix : false ,
187
+ } ,
188
+ } ,
189
+ rollup : {
190
+ // Overrides the version of rollup used.
191
+ // Make sure to pass through the rollup function
192
+ // e.g. require( 'rollup' ).rollup
193
+ rollup : null ,
194
+ input : {
195
+ plugins : [
196
+ require ( '@rollup/plugin-babel' ) . babel ( {
197
+ exclude : 'node_modules/**' ,
198
+ babelHelpers : 'bundled' ,
199
+ } ) ,
200
+ require ( '@rollup/plugin-node-resolve' ) . nodeResolve ( ) ,
201
+ ] ,
202
+ treeshake : false ,
203
+ onwarn ( e ) {
204
+ if ( e . code === 'THIS_IS_UNDEFINED' ) {
205
+ return
206
+ }
207
+
208
+ console . warn ( e . message )
209
+ } ,
210
+ } ,
211
+ output : {
212
+ file : 'scripts.js' ,
213
+ name : 'Scripts' ,
214
+ format : 'umd' ,
215
+ generatedCode : 'es2015' ,
216
+ globals : { } ,
217
+ } ,
218
+ } ,
219
+ uglify : {
220
+ output : {
221
+ comments : '/^!|@preserve|@license|@cc_on/i' ,
222
+ } ,
223
+ } ,
224
+ } ,
225
+ } ,
106
226
webpack : {
107
227
process : true ,
108
228
watch : true ,
@@ -123,7 +243,7 @@ module.exports = {
123
243
src : {
124
244
allowEmpty : true ,
125
245
base : `${ areas . constructWp . path } /src/gutenberg` ,
126
- sourcemaps : process . env . NODE_ENV ! == 'development' ,
246
+ sourcemaps : process . env . NODE_ENV = == 'development' ,
127
247
} ,
128
248
dest : {
129
249
sourcemaps : '.' ,
@@ -192,7 +312,9 @@ module.exports = {
192
312
} ,
193
313
] ,
194
314
] ,
195
- plugins : [ ] ,
315
+ plugins : [
316
+ '@automattic/babel-plugin-preserve-i18n' ,
317
+ ] ,
196
318
} ,
197
319
} ,
198
320
} ,
@@ -201,8 +323,42 @@ module.exports = {
201
323
resolve : {
202
324
extensions : [ '.js' , '.jsx' , '.json' ] ,
203
325
} ,
204
- devtool : process . env . NODE_ENV == 'development' ? 'source-map' : false ,
205
- mode : process . env . NODE_ENV == 'development' ? 'development' : 'production' ,
326
+ optimization : {
327
+ minimizer : [
328
+ new TerserPlugin ( {
329
+ parallel : true ,
330
+ terserOptions : {
331
+ output : {
332
+ comments : / t r a n s l a t o r s : / i,
333
+ } ,
334
+ compress : {
335
+ passes : 2 ,
336
+ } ,
337
+ mangle : {
338
+ reserved : [
339
+ '__' ,
340
+ '_e' ,
341
+ '_x' ,
342
+ '_ex' ,
343
+ '_n' ,
344
+ '_nx' ,
345
+ '_n_noop' ,
346
+ '_nx_noop' ,
347
+ 'esc_html__' ,
348
+ 'esc_html_e' ,
349
+ 'esc_html_x' ,
350
+ 'esc_attr__' ,
351
+ 'esc_attr_e' ,
352
+ 'esc_attr_x' ,
353
+ ] ,
354
+ } ,
355
+ } ,
356
+ extractComments : false ,
357
+ } ) ,
358
+ ] ,
359
+ } ,
360
+ devtool : process . env . NODE_ENV === 'development' ? 'source-map' : false ,
361
+ mode : process . env . NODE_ENV === 'development' ? 'development' : 'production' ,
206
362
} ,
207
363
} ,
208
364
uglify : {
@@ -229,43 +385,59 @@ module.exports = {
229
385
allowEmpty : true ,
230
386
} ,
231
387
dest : { } ,
388
+ checktextdomain : {
389
+ ...translatePipes . checktextdomain ,
390
+ text_domain : areas . constructWp . name ,
391
+ } ,
392
+ pot : {
393
+ ...translatePipes . pot ,
394
+ domain : areas . constructWp . name ,
395
+ package : areas . constructWp . title ,
396
+ relativeTo : areas . constructWp . path ,
397
+ } ,
232
398
} ,
233
399
} ,
234
- ] ,
235
- pipes : {
236
- checktextdomain : {
237
- text_domain : areas . constructWp . name ,
238
- keywords : [
239
- '__:1,2d' ,
240
- '_e:1,2d' ,
241
- '_x:1,2c,3d' ,
242
- '_ex:1,2c,3d' ,
243
- '_n:1,2,4d' ,
244
- '_nx:1,2,4c,5d' ,
245
- '_n_noop:1,2,3d' ,
246
- '_nx_noop:1,2,3c,4d' ,
247
- 'esc_html__:1,2d' ,
248
- 'esc_html_e:1,2d' ,
249
- 'esc_html_x:1,2c,3d' ,
250
- 'esc_attr__:1,2d' ,
251
- 'esc_attr_e:1,2d' ,
252
- 'esc_attr_x:1,2c,3d' ,
253
- ] ,
254
- report_missing : true ,
255
- report_success : false ,
256
- report_variable_domain : true ,
257
- correct_domain : true ,
258
- create_report_file : false ,
259
- force : false ,
260
- } ,
261
- pot : {
262
- domain : areas . constructWp . name ,
263
- package : areas . constructWp . title ,
264
- lastTranslator : `${ pkg . author . name } <${ pkg . author . email } >` ,
265
- headers : {
266
- 'Language-Team' : `${ pkg . author . name } <${ pkg . author . email } >` ,
400
+ {
401
+ paths : {
402
+ src : `${ areas . constructWp . path } /assets/js/**/*.js` ,
403
+ watch : `${ areas . constructWp . path } /assets/js/**/*.js` ,
404
+ dest : `${ areas . constructWp . path } /languages/js/${ areas . constructWp . name } .pot` ,
405
+ } ,
406
+ pipes : {
407
+ // Put any pipe overrides here
408
+ src : {
409
+ allowEmpty : true ,
410
+ } ,
411
+ dest : { } ,
412
+ checktextdomain : {
413
+ ...translatePipes . checktextdomain ,
414
+ text_domain : areas . constructWp . name ,
415
+ } ,
416
+ pot : {
417
+ ...translatePipes . pot ,
418
+ domain : areas . constructWp . name ,
419
+ package : areas . constructWp . title ,
420
+ relativeTo : areas . constructWp . path ,
421
+ parser : 'js' ,
422
+ parserOptions : {
423
+ ecmaVersion : 9 ,
424
+ } ,
425
+ } ,
267
426
} ,
268
427
} ,
428
+ ] ,
429
+ pipes : translatePipes ,
430
+ } ,
431
+ po2json : {
432
+ process : true ,
433
+ watch : true ,
434
+ paths : [
435
+ `${ areas . constructWp . path } /languages/**/*.po` ,
436
+ ] ,
437
+ bin : 'vendor/bin/wp' ,
438
+ pretty : true ,
439
+ execSync : {
440
+ shell : 'C:\\Program Files\\Git\\bin\\bash.exe' ,
269
441
} ,
270
442
} ,
271
443
browsersync : {
@@ -275,8 +447,9 @@ module.exports = {
275
447
port : 4000 ,
276
448
ui : false ,
277
449
files : [
278
- '**/*' ,
279
- '!**/src/**/*'
450
+ 'plugins/**/*' ,
451
+ 'themes/**/*' ,
452
+ '!**/src/**/*' ,
280
453
] ,
281
454
ghostmode : false ,
282
455
open : false ,
0 commit comments