@@ -58,6 +58,38 @@ module.exports = (src, dest, preview) => () => {
58
58
. pipe ( terser ( ) )
59
59
// NOTE concat already uses stat from newest combined file
60
60
. pipe ( concat ( 'js/site.js' ) ) ,
61
+ vfs
62
+ . src ( 'js/vendor/enlighterjs/*.js' , { ...opts , read : false } )
63
+ . pipe (
64
+ // see https://gulpjs.org/recipes/browserify-multiple-destination.html
65
+ map ( ( file , enc , next ) => {
66
+ if ( file . relative . endsWith ( '.bundle.js' ) ) {
67
+ const mtimePromises = [ ]
68
+ const bundlePath = file . path
69
+ browserify ( file . relative , { basedir : src , detectGlobals : false } )
70
+ . plugin ( 'browser-pack-flat/plugin' )
71
+ . on ( 'file' , ( bundledPath ) => {
72
+ if ( bundledPath !== bundlePath ) mtimePromises . push ( fs . stat ( bundledPath ) . then ( ( { mtime } ) => mtime ) )
73
+ } )
74
+ . bundle ( ( bundleError , bundleBuffer ) =>
75
+ Promise . all ( mtimePromises ) . then ( ( mtimes ) => {
76
+ const newestMtime = mtimes . reduce ( ( max , curr ) => ( ! max || curr > max ? curr : max ) )
77
+ if ( newestMtime > file . stat . mtime ) file . stat . mtimeMs = + ( file . stat . mtime = newestMtime )
78
+ if ( bundleBuffer !== undefined ) file . contents = bundleBuffer
79
+ file . path = file . path . slice ( 0 , file . path . length - 10 ) + '.js'
80
+ next ( bundleError , file )
81
+ } )
82
+ )
83
+ } else {
84
+ fs . readFile ( file . path , 'UTF-8' ) . then ( ( contents ) => {
85
+ file . contents = Buffer . from ( contents )
86
+ next ( null , file )
87
+ } )
88
+ }
89
+ } )
90
+ )
91
+ . pipe ( buffer ( ) )
92
+ . pipe ( terser ( ) ) ,
61
93
vfs
62
94
. src ( 'js/vendor/gcx-contact-form/*.js' , { ...opts , read : false } )
63
95
. pipe (
0 commit comments