Skip to content

Commit

Permalink
Merge branch 'release/1.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jun 1, 2021
2 parents c07074e + c7d8c79 commit 1468f47
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 180 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 1.0.3 - 2021-05-31
### Fixed
* Fixed `dist/index.d.ts` to have complete type definitions

## 1.0.2 - 2021-05-31
### Changed
* Administrivia
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ This is the full [config for critical](https://github.com/addyosmani/critical#op

You may optionally override any properties you like here. The default values passed in are:

```js
const defaultCriticalConfig = {
inline: false,
minify: true,
extract: false,
width: 1200,
height: 1200,
penthouse: {
blockJSRequests: false
}
```ts
const defaultCriticalConfig: Partial<CriticalConfig> = {
inline: false,
minify: true,
extract: false,
width: 1200,
height: 1200,
penthouse: {
blockJSRequests: false
}
};
```

Expand Down
138 changes: 134 additions & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,141 @@
import { Plugin } from 'rollup';
interface CriticalPages {
import {Plugin} from 'rollup';

export interface PenthouseConfig {
/** Accessible url. Use file:/// protocol for local html files. */
url: string;
/** Original css to extract critical css from */
cssString: string;
/** Path to original css file on disk (if using instead of `cssString`) */
css: string;
/** Width for critical viewport */
width: number;
/** Height for critical viewport */
height: number;
/** Configuration for screenshots (not used by default). See [Screenshot example](https://github.com/pocketjoso/penthouse/blob/master/examples/screenshots.js) */
screenshots: object;
/** Keep media queries even for width/height values larger than critical viewport. */
keepLargerMediaQueries: boolean;
/**
* Array of css selectors to keep in critical css, even if not appearing in critical viewport.
* Strings or regex (f.e. `['.keepMeEvenIfNotSeenInDom', /^\.button/]`)
*/
forceInclude: Array<string>;
/**
* Array of css selectors to remove in critical css, even if appearing in critical viewport.
* Strings or regex (f.e. `['.doNotKeepMeEvenIfNotSeenInDom', /^\.button/]`)
*/
forceExclude: Array<string>;
/** Css properties to filter out from critical css */
propertiesToRemove: Array<string>;
/** Ms; abort critical CSS generation after this time */
timeout: number;
/** Settings for puppeteer. See [Custom puppeteer browser example](https://github.com/pocketjoso/penthouse/blob/master/examples/custom-browser.js) */
puppeteer: object;
/** Ms; stop waiting for page load after this time (for sites when page load event is unreliable) */
pageLoadSkipTimeout: number;
/**
* ms; wait time after page load before critical css extraction starts
* (also before "before" screenshot is taken, if used)
*/
renderWaitTime: number;
/** set to false to load JS (not recommended) */
blockJSRequests: boolean;
/** characters; strip out inline base64 encoded resources larger than this */
maxEmbeddedBase64Length: number;
/** Can be specified to limit nr of elements to inspect per css selector, reducing execution time. */
maxElementsToCheckPerSelector: number;
/** specify which user agent string when loading the page */
userAgent: string;
/** Set extra http headers to be sent with the request for the url. */
customPageHeaders: object;
/** For formatting of each cookie, see [Puppeteer setCookie docs](https://github.com/puppeteer/puppeteer/blob/v1.9.0/docs/api.md#pagesetcookiecookies) */
cookies: Array<string>;
/** Make Penthouse throw on errors parsing the original CSS. Legacy option, not recommended */
strict: boolean;
/**
* Let Penthouse stop if the server response code is not matching this value. number and
* regex types are tested against the [response.status()](https://github.com/puppeteer/puppeteer/blob/v1.14.0/docs/api.md#responsestatus). A function is also allowed and
* gets [Response](https://github.com/puppeteer/puppeteer/blob/v1.14.0/docs/api.md#class-response) as argument. The function should return a boolean.
*/
allowedResponseCode: number | RegExp | Function;
}

export type DeclCallback = (node: object, value: string) => boolean;

export interface CriticalConfig {
/** Inline critical-path CSS using filamentgroup's loadCSS. Pass an object to configure `inline-critical` */
inline: boolean;
/** Base directory in which the source and destination are to be written */
base: string;
/** HTML source to be operated against. This option takes precedence over the `src` option */
html: string;
/** An array of paths to css files, file globs or Vinyl file objects. */
css: Array<string>;
/** Location of the HTML source to be operated against */
src: string;
/**
* Location of where to save the output of an operation.
* Use an object with 'html' and 'css' props if you want to store both
*/
target: string | Partial<{
css: string;
html: string;
uncritical: string;
}>;
/** Width of the target viewport */
width: number;
/** Height of the target viewport */
height: number;
/** Enable minification of generated critical-path */
minify: boolean;
/**
* Remove the inlined styles from any stylesheets referenced in the HTML.
* It generates new references based on extracted content so it's safe to use for
* multiple HTML files referencing the same stylesheet. Use with caution.
* Removing the critical CSS per page results in a unique async loaded CSS file for every page.
* Meaning you can't rely on cache across multiple pages
*/
extract: boolean;
/** Inline images */
inlineImages: boolean;
/** List of directories/urls where the inliner should start looking for assets */
assetPaths: Array<string>;
/** Sets a max file size (in bytes) for base64 inlined images */
maxImageFileSize: number;
/**
* Critical tries it's best to rebase the asset paths relative to the document.
* If this doesn't work as expected you can always use this option to control the rebase paths.
* See postcss-url for details. (https://github.com/pocketjoso/penthouse#usage-1).
*/
rebase: object | Function;
/** ignore CSS rules */
ignore: Partial<{
atrule: Array<string>;
rule: Array<string>;
decl: DeclCallback;
}>;
/** User agent to use when fetching a remote src */
userAgent: string;
/** Configuration options for `penthouse`. */
penthouse: Partial<PenthouseConfig>;
/** Configuration options for `got`. */
request: object;
/** RFC2617 basic authorization: `user` */
user: string;
/** RFC2617 basic authorization: `pass` */
pass: string;
/** Throw an error if no css is found */
strict: boolean;
}

export interface CriticalPages {
/** Combined with `criticalUrl` to determine the URLs to scrape for Critical CSS */
uri: string;
/** Critical CSS files are named with the `template` path, and saved to the `criticalBase` directory */
template: string;
}
interface CriticalPluginConfig {

export interface CriticalPluginConfig {
/**
* The base URL to use in combination with the `criticalPages` `uri`s to determine the URLs to scrape for Critical CSS.
* This can also be a file system path. This is combined with `criticalPages.uri`
Expand Down Expand Up @@ -33,6 +163,7 @@ interface CriticalPluginConfig {
*/
criticalConfig?: Partial<CriticalConfig>;
}

/**
* [Vite.js](https://vitejs.dev/) & [Rollup](https://rollupjs.org/) plugin for generating critical CSS
* that uses the [critical](https://github.com/addyosmani/critical) generator under the hood.
Expand All @@ -42,4 +173,3 @@ interface CriticalPluginConfig {
* @constructor
*/
declare function PluginCritical(pluginConfig: CriticalPluginConfig, callback?: Function): Plugin;
export default PluginCritical;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-critical",
"version": "1.0.2",
"version": "1.0.3",
"description": "Rollup plugin to generate critical CSS.",
"author": "nystudio107",
"license": "MIT",
Expand Down Expand Up @@ -30,7 +30,7 @@
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
"build:cjs": "tsc -p config/cjs.json",
"build:esm": "tsc -p config/esm.json",
"build:types": "tsc -p config/types.json",
"build:types": "cp src/types.d.ts dist/index.d.ts",
"check": "tsc -p config/base.json --noEmit",
"lint": "eslint -p .",
"test": "jest --passWithNoTests --coverage"
Expand Down
67 changes: 0 additions & 67 deletions src/@types/critical.d.ts

This file was deleted.

59 changes: 0 additions & 59 deletions src/@types/penthouse.d.ts

This file was deleted.

Loading

0 comments on commit 1468f47

Please sign in to comment.