1
- //! rev-web-assets v1.3.5 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License
1
+ //! rev-web-assets v1.4.0 ~~ https://github.com/center-key/rev-web-assets ~~ MIT License
2
2
3
3
import chalk from 'chalk' ;
4
4
import crypto from 'crypto' ;
@@ -7,7 +7,7 @@ import log from 'fancy-log';
7
7
import path from 'path' ;
8
8
import slash from 'slash' ;
9
9
const revWebAssets = {
10
- manifest ( source , target ) {
10
+ manifest ( source , target , skip ) {
11
11
const files = fs . readdirSync ( source , { recursive : true } )
12
12
. map ( file => slash ( path . join ( source , file . toString ( ) ) ) )
13
13
. filter ( file => fs . statSync ( file ) . isFile ( ) )
@@ -33,6 +33,7 @@ const revWebAssets = {
33
33
destPath : null ,
34
34
usedIn : isHtml ? null : [ ] ,
35
35
references : isHtml ? null : 0 ,
36
+ skipped : ! isHtml && ! ! skip && file . includes ( skip ) ,
36
37
} ;
37
38
} ;
38
39
const manifest = files . map ( process ) ;
@@ -42,7 +43,7 @@ const revWebAssets = {
42
43
const lastDot = / \. (? = [ ^ . ] * $ ) / ;
43
44
return slash ( path . normalize ( ! hash ? filename : filename . replace ( lastDot , '.' + hash + '.' ) ) ) ;
44
45
} ,
45
- removeHash ( filename ) {
46
+ stripHash ( filename ) {
46
47
return filename . replace ( / [ . ] [ 0 - 9 a - f ] { 8 } [ . ] / , '.' ) ;
47
48
} ,
48
49
calcAssetHash ( detail ) {
@@ -56,13 +57,15 @@ const revWebAssets = {
56
57
return detail ;
57
58
} ,
58
59
hashAssetPath ( manifest , detail , settings ) {
60
+ const webPages = [ '.html' , '.htm' , '.php' ] ;
59
61
const replacer = ( matched , pre , uri , post ) => {
60
62
const ext = path . extname ( uri ) ;
61
- const doNotHash = uri . includes ( ':' ) || [ '.html' , '.htm' , '.php' ] . includes ( ext ) || ext . length < 2 ;
63
+ const doNotHash = uri . includes ( ':' ) || webPages . includes ( ext ) || ext . length < 2 ;
62
64
const canonicalPath = detail . canonicalFolder ? detail . canonicalFolder + '/' : '' ;
63
65
const canonical = slash ( path . normalize ( canonicalPath + uri ) ) ;
64
66
const assetDetail = doNotHash ? null : manifest . find ( detail => detail . canonical === canonical ) ;
65
- if ( assetDetail && ! assetDetail . hash )
67
+ const skipAsset = ! ! settings . skip && uri . includes ( settings . skip ) ;
68
+ if ( assetDetail && ! assetDetail . hash && ! skipAsset )
66
69
revWebAssets . calcAssetHash ( assetDetail ) ;
67
70
if ( assetDetail )
68
71
assetDetail . references ++ ;
@@ -121,6 +124,7 @@ const revWebAssets = {
121
124
force : false ,
122
125
metaContentBase : null ,
123
126
saveManifest : false ,
127
+ skip : null ,
124
128
} ;
125
129
const settings = { ...defaults , ...options } ;
126
130
const startTime = Date . now ( ) ;
@@ -139,10 +143,10 @@ const revWebAssets = {
139
143
null ;
140
144
if ( errorMessage )
141
145
throw Error ( '[rev-web-assets] ' + errorMessage ) ;
142
- const manifest = revWebAssets . manifest ( source , target ) ;
146
+ const manifest = revWebAssets . manifest ( source , target , settings . skip ) ;
143
147
revWebAssets . processHtml ( manifest , settings ) ;
144
148
revWebAssets . processCss ( manifest , settings ) ;
145
- const hashUnusedAsset = ( detail ) => ! detail . hash && ! detail . isHtml && revWebAssets . calcAssetHash ( detail ) ;
149
+ const hashUnusedAsset = ( detail ) => ! detail . hash && ! detail . isHtml && ! detail . skipped && revWebAssets . calcAssetHash ( detail ) ;
146
150
if ( settings . force )
147
151
manifest . forEach ( hashUnusedAsset ) ;
148
152
revWebAssets . copyAssets ( manifest ) ;
0 commit comments