diff --git a/README.md b/README.md index e538b2b..2367f05 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,18 @@ usemin src/index.html -d dist -o dist/index.html --htmlmin true -c config.js ``` ### Example HTML +#### Blocks +Blocks are expressed as: +```html + +... HTML Markup, list of script / link tags. + +``` + +- **pipelineId**: pipeline id for options or remove to remove a section +- **alternate search path**: (optional) By default the input files are relative to the treated file. Alternate search path allows one to change that +- **path**: the file path of the optimized file, the target output + ```html @@ -65,6 +77,19 @@ Running the command with `--rmlr true` will output: ``` +#### Alternate search path +```html + + + + + + + + + +``` + ### Config file Please check the relevant documentations for the available options: [ UglifyJS](https://github.com/mishoo/UglifyJS2), [CleanCSS](https://github.com/jakubpawlowicz/clean-css) and [HTML minifier](https://github.com/kangax/html-minifier). diff --git a/lib/getBlocks.js b/lib/getBlocks.js index eea7f01..035eacc 100644 --- a/lib/getBlocks.js +++ b/lib/getBlocks.js @@ -1,5 +1,6 @@ 'use strict'; var path = require('path'); +var fs = require('fs'); module.exports = function (src, content, removeLivereload) { var buildReg = //; @@ -24,9 +25,14 @@ module.exports = function (src, content, removeLivereload) { type: build[1], dest: build[3], indent: indent, + searchPath: [''], src: [], raw: [] }; + + if (build[2]) { + block.searchPath = build[2].split(','); + } } if (removeLivereload && livereload) { @@ -47,7 +53,19 @@ module.exports = function (src, content, removeLivereload) { var asset = l.match(/(href|src)=["']([^'"]+)["']/); if (asset && asset[2]) { - block.src.push(path.join(srcDir, asset[2])); + var numSearchPath = block.searchPath.length; + + for (var i = 0; i < numSearchPath; i++) { + var assetPath = path.join(srcDir, block.searchPath[i], asset[2]); + + try { + fs.accessSync(assetPath, fs.F_OK); + block.src.push(assetPath); + break; + } catch (e) { + continue; + } + } // Preserve defer attribute var defer = / defer/.test(l); diff --git a/package.json b/package.json index 7fda9da..a1e998f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "usemin-cli", - "version": "0.1.0", + "version": "0.2.0", "description": "Replaces references to non-optimized scripts or stylesheets into a set of HTML files (or any templates/views).", "main": "index.js", "bin": { diff --git a/test/fixtures/alt-search-path.html b/test/fixtures/alt-search-path.html new file mode 100644 index 0000000..88f71ed --- /dev/null +++ b/test/fixtures/alt-search-path.html @@ -0,0 +1,15 @@ + + +
+ +