grunt-node-modules-cachebuster
v0.1.1
Published
Generates a file containing node module versions for node_modules defined in your package.json.
Downloads
3
Readme
Grunt Node Modules Cachebuster
This tasks reads a folder of node package names subfolders and creates a file (json
or php
) with key (package name) value (version) pairs. An example use case is a project where you copy js
and css
files to a library
folder from the node_modules
folder. The webapp clients should then always load the latest version of the package files whenever they change (npm update
). The plugin requires grunt.
Getting started
Simply install via:
$ npm install grunt-node-modules-cachebuster --save-dev
Example task
Imagine the public/lib
folder contains this subfolders (copied from node_modules
via grunt-contrib-copy
): react
, react-dom
. Your Gruntfile.js
can define a task like the below:
node_modules_cachebuster: {
'publiclib': {
options: {
banner: '/* This file was automatically generated (' + new Date().toString() + '). */',
format: 'php'
},
src: ['public/lib/*'],
dest: 'inc/others/cachebuster-lib.php'
}
}
The task above can result in (cachebuster-lib.php
):
<?php
/* This file was automatically generated (Tue Nov 07 2017 21:52:14 GMT+0000 (UTC)). */
return array(
'react' => '16.0.0',
'react-dom' => '16.0.0'
);
API
options.format
(string):php
orjson
format. This format will be the output for thedest
file.options.banner
(string): This text will be prepended to the output.options.altNodeModules
(string): Relative path to anothernode_modules
folder, for example to work with hoisting (lerna, yarn workspaces)
License
This grunt task is MIT licensed. The project is inspired by this project: grunt-cachebuster.