Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit 960a432

Browse files
committedJul 27, 2014
second commit
1 parent aed059d commit 960a432

File tree

9 files changed

+5982
-50
lines changed

9 files changed

+5982
-50
lines changed
 

‎.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

‎Gruntfile.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,18 @@ module.exports = function(grunt) {
4242
}
4343
},
4444
critical: {
45-
options: {
46-
47-
},
4845
test: {
46+
options: {
47+
base: './',
48+
css: [
49+
'test/fixture/styles/main.css',
50+
'test/fixture/styles/bootstrap.css'
51+
],
52+
width: 320,
53+
height: 70
54+
},
4955
src: 'test/fixture/index.html',
50-
dest: 'test/generated/critical.css',
51-
width: 320,
52-
height: 480
56+
dest: 'test/generated/critical.css'
5357
}
5458
}
5559
});

‎README.md

+54-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,65 @@
11
# grunt-critical
22

3-
Grunt plugin to extract & inline critical-path CSS from HTML WiP WiP WiP
3+
Grunt plugin to extract & inline critical-path CSS from HTML (WiP alpha version)
44

55
[![build status](https://secure.travis-ci.org/bezoerb/grunt-critical.png)](http://travis-ci.org/bezoerb/grunt-critical)
66

7-
## Installation
7+
## Getting Started
88

9-
This module is installed via npm:
9+
This plugin requires Grunt `~0.4.0`
1010

11-
``` bash
12-
$ npm install grunt-critical
11+
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
12+
13+
```shell
14+
npm install grunt-critical --save-dev
1315
```
1416

15-
## Example Usage
17+
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
18+
19+
```js
20+
grunt.loadNpmTasks('grunt-critical');
21+
22+
23+
## Critical task
24+
25+
_Run this task with the `grunt critical` command._
26+
27+
Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide.
28+
29+
Generate critical path css and inline it with [critical](https://github.com/addyosmani/critical).
30+
31+
### Usage
1632

17-
``` js
18-
var gruntCritical = require('grunt-critical');
33+
Use the `grunt-critical` task by specifying a target destination (file) for your critical CSS. Below this is `test/generated/critical.css`.
34+
35+
Along-side, specify the input HTML file you would like scanned as well as the width and height of the critical viewport.
36+
In this case `test/fixture/index.html`.
37+
38+
```shell
39+
critical: {
40+
test: {
41+
options: {
42+
base: './',
43+
css: [
44+
'test/fixture/styles/main.css',
45+
'test/fixture/styles/bootstrap.css'
46+
],
47+
width: 320,
48+
height: 70
49+
},
50+
src: 'test/fixture/index.html',
51+
dest: 'test/generated/critical.css'
52+
}
53+
}
1954
```
55+
56+
## Options
57+
58+
Sample use of all supported options:
59+
```shell
60+
TODO
61+
```
62+
63+
## License
64+
65+
(C) Ben Zörb 2014, released under an MIT license

‎package.json

+36-32
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
{
2-
"name": "grunt-critical",
3-
"version": "1.0.0",
4-
"description": "Grunt plugin to extract & inline critical-path CSS from HTML",
5-
"main": "index.js",
6-
"scripts": {
7-
"test": "node_modules/.bin/grunt ci"
8-
},
9-
"repository": {
10-
"type": "git",
11-
"url": "https://github.com/bezoerb/grunt-critical"
12-
},
13-
"keywords": [
14-
"critical-path css perf gruntplugin"
15-
],
16-
"author": "Ben Zörb <ben@sommerlaune.com>",
17-
"license": "BSD-3-Clause",
18-
"bugs": {
19-
"url": "https://github.com/bezoerb/grunt-critical/issues"
20-
},
21-
"dependencies": {
22-
"critical": "^0.1.5"
23-
},
24-
"devDependencies": {
25-
"chai": "~1.8.1",
26-
"grunt": "~0.4.1",
27-
"grunt-cli": "~0.1.9",
28-
"grunt-complexity": "~0.1.3",
29-
"grunt-contrib-jshint": "~0.6.4",
30-
"grunt-contrib-watch": "~0.5.3",
31-
"grunt-simple-mocha": "^0.4.0",
32-
"load-grunt-tasks": "^0.6.0"
33-
}
2+
"name": "grunt-critical",
3+
"version": "1.0.0",
4+
"description": "Grunt task to extract & inline critical-path CSS from HTML",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "node_modules/.bin/grunt ci"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/bezoerb/grunt-critical"
12+
},
13+
"keywords": [
14+
"critical-path css perf gruntplugin"
15+
],
16+
"author": "Ben Zörb <ben@sommerlaune.com>",
17+
"licenses": [
18+
{
19+
"type": "MIT"
20+
}
21+
],
22+
"bugs": {
23+
"url": "https://github.com/bezoerb/grunt-critical/issues"
24+
},
25+
"dependencies": {
26+
"critical": "git+https://github.com/addyosmani/critical.git"
27+
},
28+
"devDependencies": {
29+
"chai": "~1.8.1",
30+
"grunt": "~0.4.1",
31+
"grunt-cli": "~0.1.9",
32+
"grunt-complexity": "~0.1.3",
33+
"grunt-contrib-jshint": "~0.6.4",
34+
"grunt-contrib-watch": "~0.5.3",
35+
"grunt-simple-mocha": "^0.4.0",
36+
"load-grunt-tasks": "^0.6.0"
37+
}
3438
}

‎tasks/critical.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ module.exports = function (grunt) {
4040
options.base = path.normalize(options.base || '');
4141

4242

43+
// absolutize filepath
44+
var basereplace = path.resolve(options.base || './') + '/';
45+
46+
47+
4348
grunt.util.async.concatSeries(src, function(file, next) {
4449
try {
45-
options.src = file;
46-
options.dest = f.dest;
50+
51+
options.src = path.resolve(file).replace(basereplace,'');
52+
// options.dest = path.resolve(f.dest).replace(basereplace,'');
4753

4854
critical.generate(options, function (err, output){
4955
if (err) {

‎test/fixture/scripts/main.js

-1
This file was deleted.

0 commit comments

Comments
 (0)
This repository has been archived.