rev-static
features
add version in file name for css and js files
index.js
becomes:
index-caa02e8ba0c5af68e9ac7728da2bed75.js
change file name of css and js files in html files
<script src="index.js"></script>
becomes:
<script src="index-caa02e8ba0c5af68e9ac7728da2bed75.js"></script>
integrity
property
calculate sha for css and js files, then add it in <script src="index.js" crossOrigin="anonymous"></script>
becomes:
<script src="index-caa02e8ba0c5af68e9ac7728da2bed75.js" crossOrigin="anonymous" integrity="sha256-cHLd68M3ekn8P2d8tYdJIV91nSbWrWsu02yI8MEVvYU="></script>
support glob
support config file for options
rev-static --config rev-static.debug.js
inline small js or css file
install
yarn global add rev-static
usage
rev-static --config rev-static.config.js // config the config file pathrev-static -vrev-static --versionrev-static --watchrev-static --config rev-static.config.ts
options
key | description |
---|---|
-w,--watch | watch mode |
--config | config file |
-h,--help | Print this message. |
-v,--version | Print the version |
config file
key | type | use case | description |
---|---|---|---|
inputFiles |
string[] |
demo/index.js |
the js, css, html and image file paths, can be glob |
excludeFiles |
string[]? |
node_modules/foo/bar.js |
the files will be excluded, can be glob |
revisedFiles |
string[]? |
demo/foo-caa02eaf68e9a.js |
the files will be regarded as revised files, can be glob |
inlinedFiles |
string[]? |
demo/index.css |
the files will be inlined to html files, can be glob |
outputFiles |
(file: string) => string |
demo/index.ejs.html ->demo/index.html |
the output files mapping function |
ejsOptions |
EjsOption |
rm whitespace | the options to ejs |
sha |
256 or 384 or 512 or undefined |
subresource integrity | the sha type for subresource integrity |
customNewFileName |
(filePath: string, fileString: string, md5String: string, baseName: string, extensionName: string) => string |
demo/index.js ->demo/index-caa02eaf68e9a.js |
the rule of generated js, css, image file |
customOldFileName |
(filePath: string, baseName: string, extensionName: string) => string |
demo/index-caa02eaf68e9a.js ->{ demoIndexJs: demo/index-caa02eaf68e9a.js } |
the rule to get revised file's key |
json |
string? |
generate json file for other use | |
es6 |
string? |
generate es6 file for image resources | |
less |
string? |
generate es6 file for image resources | |
scss |
string? |
generate es6 file for image resources | |
base |
string? |
for example, if no base , the key will be demoFooJs or demoBarCss , if the base is demo , the key will be fooJs or barCss |
|
fileSize |
string? |
generate a json file to show the resource file size | |
context |
any? |
will be available when render html template, eg, context: { foo: 1 } , then context.foo === 1 |
core structure
demo in this repository
- download or clone this repository
- run
rev-static
(the options is already inrev-static.config.js
)
develop
check scripts
part in package.json
file, then run npm run [a script name]
.
change logs
v3
noOutputFiles
removedUsage from nodejs
removed- All cli command except
-v
,--version
,--config
removed, in favor of config file - the
outputFiles
cannot bestring[]
any more
v2
// before// default configuration file path: rev-static.config.json // after// default configuration file path: rev-static.config.js
// beforerev; // afterconst variables = rev;