grunt-usemin
Advanced tools
Comparing version 0.1.2 to 0.1.4
@@ -180,3 +180,3 @@ 'use strict'; | ||
/*jshint regexp:false */ | ||
[/<script.+src=['"]([^"']+)["'][\/>]?><[\\]?\/script>/gm, | ||
[/<script.+src=['"]([^"']+)["']/gm, | ||
'Update the HTML to reference our concat/min/revved script files' | ||
@@ -183,0 +183,0 @@ ], |
@@ -7,7 +7,16 @@ 'use strict'; | ||
// | ||
// +base_dir+ : the base repository which will be the root for our search | ||
// +expandfn+ : a function that will return a list of file matching a given pattern (for example grunt.file.expand) | ||
// +dirs+: restrict the search to these subdirectories | ||
// | ||
var RevvedFinder = module.exports = function (expandfn) { | ||
var RevvedFinder = module.exports = function (expandfn, dirs) { | ||
this.expandfn = expandfn; | ||
this.dirs = dirs; | ||
if (!dirs || dirs.length === 0) { | ||
this.dirs_string = ''; | ||
} else if (dirs.length == 1) { | ||
this.dirs_string = dirs[0] + '/'; | ||
} else { | ||
this.dirs_string = '{' + dirs.join(',') + '}/'; | ||
} | ||
}; | ||
@@ -62,6 +71,6 @@ | ||
// a images/misc/4567.test.png for example) | ||
var filepaths = this.expandfn('**/*' + basename); | ||
var re = new RegExp('\\d+\\.' + basename + '$'); | ||
var filepaths = this.expandfn(this.dirs_string + '**/*' + basename); | ||
var re = new RegExp('[0-9a-fA-F]+\\.' + basename + '$'); | ||
var filepath = filepaths.filter(function (f) { | ||
return f.match(re) && (normalizedDirname === path.dirname(f)); | ||
return f.match(re) && (path.dirname(f).match(normalizedDirname)); | ||
})[0]; | ||
@@ -68,0 +77,0 @@ |
{ | ||
"name": "grunt-usemin", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"description": "Grunt task replaces references to non-optimized scripts or stylesheets into a set of HTML files (or any templates/views).", | ||
"keywords": [ | ||
"gruntplugin", | ||
"grunt", | ||
"usemin", | ||
"yeoman", | ||
"html" | ||
"gruntplugin", | ||
"grunt", | ||
"usemin", | ||
"yeoman", | ||
"html" | ||
], | ||
@@ -17,21 +17,21 @@ "homepage": "https://github.com/yeoman/grunt-usemin", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/yeoman/grunt-usemin.git" | ||
"type": "git", | ||
"url": "git://github.com/yeoman/grunt-usemin.git" | ||
}, | ||
"scripts": { | ||
"test": "node node_modules/mocha/bin/mocha test/test-*.js" | ||
"test": "node node_modules/mocha/bin/mocha test/test-*.js" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.4.0", | ||
"mocha": "~1.7.4", | ||
"mkdirp": "~0.3.1", | ||
"rimraf": "~2.0.1", | ||
"grunt-contrib-jshint": "~0.1.1" | ||
"grunt": "~0.4.0", | ||
"mocha": "~1.7.4", | ||
"mkdirp": "~0.3.1", | ||
"rimraf": "~2.0.1", | ||
"grunt-contrib-jshint": "~0.1.1" | ||
}, | ||
"engines": { | ||
"node": ">=0.8.0" | ||
"node": ">=0.8.0" | ||
}, | ||
"licenses": { | ||
"type": "BSD" | ||
"type": "BSD" | ||
} | ||
} |
@@ -20,6 +20,6 @@ # grunt-usemin [![Build Status](https://secure.travis-ci.org/yeoman/grunt-usemin.png?branch=master)](http://travis-ci.org/yeoman/grunt-usemin) | ||
- **useminPrepare**: detects special construction (blocks) in the HTML files and update the `grunt` config to run `concat`/`min`/`css`/`requirejs` on the files referenced in the block. It does not changes the HTML files it is working on. | ||
- **useminPrepare**: detects special construction (blocks) in the HTML files and update the `grunt` config to run `concat`/`uglify`/`cssmin`/`requirejs` on the files referenced in the block. It does not changes the HTML files it is working on. | ||
- **usemin**: in the HTML and CSS files it treats, it replaces the blocks by a reference to a single file, as well as all references to images, scripts, CSS files, by their minified/revved/.. version if it is found on the disk. As such this target rewrites the HTML and CSS files it is working on. | ||
Usually, `useminPrepare` is launched first, then the `concat`, `min`, `css` and `requirejs` tasks are launched (they will created the minified/revved version of the referenced files), and then, in the end `usemin` is launched. | ||
Usually, `useminPrepare` is launched first, then the `concat`, `uglify`, `cssmin` and `requirejs` tasks are launched (they will created the minified/revved version of the referenced files), and then, in the end `usemin` is launched. | ||
@@ -52,3 +52,3 @@ ## The useminPrepare task | ||
Internally, the task parses your HTML markup to find each of these blocks, and initializes for you the corresponding Grunt config for the concat / min tasks when `type=js`, the concat / css tasks when `type=css`. | ||
Internally, the task parses your HTML markup to find each of these blocks, and initializes for you the corresponding Grunt config for the concat / uglify tasks when `type=js`, the concat / cssmin tasks when `type=css`. | ||
@@ -63,3 +63,3 @@ The task also handles use of RequireJS, for the scenario where you specify the main entry point for your application using the "data-main" attribute as follows: | ||
One doesn't need to specify a concat/min/css or RequireJS configuration anymore. | ||
One doesn't need to specify a concat/uglify/cssmin or RequireJS configuration anymore. | ||
@@ -74,3 +74,22 @@ It is using only one target: `html`, with a list of the concerned files. For example, in your `Gruntfile.js`: | ||
### Options | ||
#### uglify | ||
Type: 'string' | ||
Default: 'uglify' | ||
Name of the tool used to uglify the JavaScript. | ||
#### cssmin | ||
Type: 'string' | ||
Default: 'cssmin' | ||
Name of the tool used to minify the CSS. | ||
### dirs | ||
Type: 'array of strings' | ||
Default: nil | ||
Used to limit the directories that will be looked for revved files when replacing reference. By default all subdirectories are looked at. | ||
## The usemin task | ||
@@ -83,3 +102,6 @@ | ||
html: ['**/*.html'], | ||
css: ['**/*.css'] | ||
css: ['**/*.css'], | ||
options: { | ||
dirs: ['temp', 'dist'] | ||
} | ||
} | ||
@@ -86,0 +108,0 @@ ``` |
@@ -51,4 +51,4 @@ 'use strict'; | ||
// Internally, the task parses your HTML markup to find each of these blocks, and | ||
// initializes for you the corresponding Grunt config for the concat / min tasks | ||
// when `type=js`, the concat / css tasks when `type=css`. | ||
// initializes for you the corresponding Grunt config for the concat / uglify tasks | ||
// when `type=js`, the concat / cssmin tasks when `type=css`. | ||
// | ||
@@ -63,3 +63,3 @@ // The task also handles use of RequireJS, for the scenario where you specify | ||
// | ||
// One doesn't need to specify a concat/min/css or requirejs configuration anymore. | ||
// One doesn't need to specify a concat/uglify/cssmin or requirejs configuration anymore. | ||
// | ||
@@ -82,2 +82,3 @@ // Inspired by previous work in https://gist.github.com/3024891 | ||
var data = this.data; | ||
var options = this.options(); | ||
var files = grunt.file.expand(data); | ||
@@ -96,3 +97,3 @@ | ||
// Our revved version locator | ||
var revvedfinder = new RevvedFinder(grunt.file.expand); | ||
var revvedfinder = new RevvedFinder(grunt.file.expand, options.dirs); | ||
@@ -111,9 +112,12 @@ // ext-specific directives handling and replacement of blocks | ||
grunt.registerMultiTask('useminPrepare', 'Using HTML markup as the primary source of information', function () { | ||
var options = this.options(); | ||
// collect files | ||
var files = grunt.file.expand({filter: 'isFile'}, this.data); | ||
var uglifyName = options.uglify || 'uglify'; | ||
var cssminName = options.cssmin || 'cssmin'; | ||
// concat / min / css / requirejs config | ||
// concat / uglify / cssmin / requirejs config | ||
var concat = grunt.config('concat') || {}; | ||
var min = grunt.config('min') || {}; | ||
var css = grunt.config('css') || {}; | ||
var uglify = grunt.config(uglifyName) || {}; | ||
var cssmin = grunt.config(cssminName) || {}; | ||
var requirejs = grunt.config('requirejs') || {}; | ||
@@ -150,19 +154,46 @@ | ||
// updated it on data-main attribute | ||
if (block.requirejs) { | ||
requirejs.out = requirejs.out || block.requirejs.dest; | ||
requirejs.baseUrl = requirejs.baseUrl || block.requirejs.baseUrl; | ||
requirejs.name = requirejs.name || block.requirejs.name; | ||
var hasTasks; | ||
for (var i in requirejs) { | ||
if (requirejs.hasOwnProperty(i)) { | ||
hasTasks = true; | ||
var task = requirejs[i]; | ||
var options = task.options; | ||
if (options) { | ||
options.name = options.name || block.requirejs.name; | ||
options.out = options.out || block.requirejs.dest; | ||
options.baseUrl = options.baseUrl || block.requirejs.baseUrl; | ||
} else { | ||
task.options = { | ||
name: block.requirejs.name, | ||
out: block.requirejs.dest, | ||
baseUrl: block.requirejs.baseUrl | ||
}; | ||
} | ||
} | ||
} | ||
if (!hasTasks) { | ||
requirejs.default = { | ||
options: { | ||
name: block.requirejs.name, | ||
out: block.requirejs.dest, | ||
baseUrl: block.requirejs.baseUrl | ||
} | ||
}; | ||
} | ||
grunt.config('requirejs', requirejs); | ||
} | ||
// min config, only for js type block | ||
// uglify config, only for js type block | ||
if (block.type === 'js') { | ||
min[block.dest] = block.dest; | ||
grunt.config('min', min); | ||
uglify[block.dest] = block.dest; | ||
grunt.config(uglifyName, uglify); | ||
} | ||
// css config, only for css type block | ||
// cssmin config, only for cssmin type block | ||
if (block.type === 'css') { | ||
css[block.dest] = block.dest; | ||
grunt.config('css', css); | ||
cssmin[block.dest] = block.dest; | ||
grunt.config(cssminName, cssmin); | ||
} | ||
@@ -174,8 +205,8 @@ }); | ||
grunt.log.subhead('Configuration is now:') | ||
.subhead(' css:') | ||
.writeln(' ' + inspect(css)) | ||
.subhead(' cssmin:') | ||
.writeln(' ' + inspect(cssmin)) | ||
.subhead(' concat:') | ||
.writeln(' ' + inspect(concat)) | ||
.subhead(' min:') | ||
.writeln(' ' + inspect(min)) | ||
.subhead(' uglify:') | ||
.writeln(' ' + inspect(uglify)) | ||
.subhead(' requirejs:') | ||
@@ -182,0 +213,0 @@ .writeln(' ' + inspect(requirejs)); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24782
531
109