This repository demonstrates how to use Grunt
to
download a css file from a public url, replace text in file paths, and save
the modified file to a specified directory.
npm
: to useGrunt
its necessary to installnode
andnpm
.grunt-cli
: withnpm
installed, runnpm install -g grunt-cli
.
- Customize the
cssDownloads
variable inGruntfile.js
. - Navigate to the directory containing
Gruntfile.js
in a terminal. - Run
npm install
. - Grun
grunt css
.
To use this in a project, it will be necessary to copy Gruntfile.js
and package.json
(if the project does not already use grunt
), or add
the contents of Gruntfile.js
and package.json
into the project's
existing Gruntfile.js
and package.json
files.
There are several variables used in Gruntfile.js
. Some or all of these will
need to be customized:
Name | Type | Default Value | Description |
---|---|---|---|
cssDownloads |
Array | [ http://example.com/assets/css/app.css ] |
An array of urls to publicly available files to download. |
tempDownloadDir |
String | tmp/ |
Path (relative to the directory containing Gruntfile.js ) to a temporary directory to download files to. Should be added to .gitignore . |
assetPathPattern |
RegExp | /(\/assets\/)/g |
Regular expression for the pattern of text to replace in file paths in downloaded files. |
assetPathReplacement |
String | /path/to/application$1 |
Text to replace in file paths in downloaded files. May include backreferences to assetPathPattern . |
applicationCssdir |
String | build/ |
Path to directory where modified files should be written. |
With the required software installed, and variables customized, navigate
to the directory containing Gruntfile.js
in a terminal, and run npm install
.
With the required software installed, variables customized, and
dependencies installed, navigate to the directory containing Gruntfile.js
in a terminal, and run grunt css
.