Skip to content

Commit

Permalink
Merge f71e22d into 7f5d59c
Browse files Browse the repository at this point in the history
  • Loading branch information
kimulaco committed Aug 19, 2019
2 parents 7f5d59c + f71e22d commit 390d3ae
Show file tree
Hide file tree
Showing 3 changed files with 1,189 additions and 1,084 deletions.
65 changes: 36 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,34 @@

Optimize CSS source for AMP HTML.

## Install
## CLI

Install package

```shell
npm install -g amp-custom
```

Run amp-custom by CLI.

```shell
npm install --save amp-custom
amp-custom input.css output.css
```

## Use
## API

Install package

```shell
npm install --save-dev amp-custom
```

### API
Run amp-custom by API.

```js
const AmpCustom = require('amp-custom');
const ampCustom = new AmpCustom();
let cssSource = `@charset "UTF-8";
const AmpCustom = require('amp-custom')
const ampCustom = new AmpCustom()
const cssSource = `@charset "UTF-8";
body {
font-size: 16px;
}
Expand All @@ -42,23 +56,17 @@ a {
.flexbox div {
float: left;
}
}`;
}`

ampCustom.optimize(cssSource); // 'body{font-size:16px}a{color:#39c;text-decoration:none}'
ampCustom.optimize(cssSource) // 'body{font-size:16px}a{color:#39c;text-decoration:none}'
```

### CLI
### optimize(cssSource: String): String

```shell
amp-custom input.css output.css
```

## Method

### optimize(cssSource:string)
Optimize CSS for AMP.

```js
let cssSource = `@charset "UTF-8";
const cssSource = `@charset "UTF-8";
body {
font-size: 16px;
}
Expand All @@ -81,26 +89,25 @@ a {
.flexbox div {
float: left;
}
}`;
}`

ampCustom.optimize(cssSource); // 'body{font-size:16px}a{color:#39c;text-decoration:none}'
ampCustom.optimize(cssSource) // 'body{font-size:16px}a{color:#39c;text-decoration:none}'
```

### getSize(cssSource:string);
### isOverMaxByte(cssSource: String): Boolean

Check the CSS string size meets the AMP rules (50KB).

```js
let cssSource = 'body{font-size:16px}a{color:#39c;text-decoration:none}';
const cssSource = 'body{font-size:16px}a{color:#39c;text-decoration:none}'

ampCustom.getSize(cssSource); // 54
ampCustom.isOverMaxByte(cssSource) // false
```

### isOverMaxByte(cssSource:string)

```js
let cssSource = 'body{font-size:16px}a{color:#39c;text-decoration:none}';
## Plugins

ampCustom.isOverMaxByte(cssSource); // false
```
- [gulp-amp-custom](https://github.com/kimulaco/gulp-amp-custom)
- [postcss-amp-custom](https://github.com/kimulaco/postcss-amp-custom)

## License

Expand Down
Loading

0 comments on commit 390d3ae

Please sign in to comment.