Skip to content

Commit 76d9dac

Browse files
committed
Merge branch 'release/1.0.7'
2 parents 64f51cd + b3f7dad commit 76d9dac

File tree

14 files changed

+397
-227
lines changed

14 files changed

+397
-227
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## 1.0.7 - 2021-06-02
6+
### Changed
7+
* Switched to `tsup` for bundling
8+
59
## 1.0.6 - 2021-06-01
610
### Fixed
711
* Fixed build of `dist/index.d.ts` to have the correct default export by sourcing `index.ts`

config/base.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

config/cjs.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

config/esm.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

config/types.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

dist/cjs/index.js

Lines changed: 0 additions & 71 deletions
This file was deleted.

dist/esm/index.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

dist/index.js

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.mjs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var __require = (x) => {
2+
if (typeof require !== "undefined")
3+
return require(x);
4+
throw new Error('Dynamic require of "' + x + '" is not supported');
5+
};
6+
7+
// src/index.ts
8+
import path from "path";
9+
var critical = __require("critical");
10+
var criticalSuffix = "_critical.min.css";
11+
var defaultCriticalConfig = {
12+
inline: false,
13+
minify: true,
14+
extract: false,
15+
width: 1200,
16+
height: 1200,
17+
penthouse: {
18+
blockJSRequests: false
19+
}
20+
};
21+
function PluginCritical(pluginConfig, callback) {
22+
return {
23+
name: "critical",
24+
async writeBundle(outputOptions, bundle) {
25+
const css = [];
26+
for (const chunk of Object.values(bundle)) {
27+
if (chunk.type === "asset" && chunk.fileName.endsWith(".css")) {
28+
const cssFile = path.join(outputOptions.dir || "", chunk.fileName);
29+
css.push(cssFile);
30+
}
31+
}
32+
if (!css.length) {
33+
return;
34+
}
35+
for (const page of pluginConfig.criticalPages) {
36+
const criticalBase = pluginConfig.criticalBase;
37+
const criticalSrc = pluginConfig.criticalUrl + page.uri;
38+
const criticalDest = page.template + criticalSuffix;
39+
const options = Object.assign({css}, defaultCriticalConfig, {
40+
base: criticalBase,
41+
src: criticalSrc,
42+
target: criticalDest
43+
}, pluginConfig.criticalConfig);
44+
console.log(`Generating critical CSS from ${criticalSrc} to ${criticalDest}`);
45+
await critical.generate(options, (err) => {
46+
if (err) {
47+
console.error(err);
48+
}
49+
if (callback) {
50+
callback(err);
51+
}
52+
});
53+
}
54+
}
55+
};
56+
}
57+
var src_default = PluginCritical;
58+
export {
59+
src_default as default
60+
};
61+
//# sourceMappingURL=index.mjs.map

dist/index.mjs.map

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": 3,
3+
"sources": ["../src/index.ts"],
4+
"sourcesContent": ["import {Plugin} from 'rollup';\nimport path from 'path';\nimport { CriticalConfig } from './@types/critical';\nimport { CriticalPluginConfig } from './@types/rollup-plugin-critical';\nconst critical = require('critical');\n\nconst criticalSuffix = '_critical.min.css';\n\n/**\n * Default `criticalConfig` passed in to `critical`\n */\nconst defaultCriticalConfig: Partial<CriticalConfig> = {\n inline: false,\n minify: true,\n extract: false,\n width: 1200,\n height: 1200,\n penthouse: {\n blockJSRequests: false\n }\n};\n\n/**\n * [Vite.js](https://vitejs.dev/) & [Rollup](https://rollupjs.org/) plugin for generating critical CSS\n * that uses the [critical](https://github.com/addyosmani/critical) generator under the hood.\n *\n * @param {CriticalPluginConfig} pluginConfig - the plugin configuration object\n * @param {Function} callback - callback upon completion of the critical CSS generation\n * @constructor\n */\nfunction PluginCritical(pluginConfig: CriticalPluginConfig, callback?: Function): Plugin {\n return {\n name: 'critical',\n async writeBundle(outputOptions, bundle) {\n const css: Array<string> = [];\n // Find all of the generated CSS assets\n for (const chunk of Object.values(bundle)) {\n if (chunk.type === 'asset' && chunk.fileName.endsWith('.css')) {\n const cssFile = path.join(outputOptions.dir || '', chunk.fileName);\n css.push(cssFile);\n }\n }\n // If we have no CSS, skip bundle\n if (!css.length) {\n return;\n }\n // Iterate through the pages\n for (const page of pluginConfig.criticalPages) {\n const criticalBase = pluginConfig.criticalBase;\n const criticalSrc = pluginConfig.criticalUrl + page.uri;\n const criticalDest = page.template + criticalSuffix;\n // Merge in our options\n const options = Object.assign(\n { css },\n defaultCriticalConfig,\n {\n base: criticalBase,\n src: criticalSrc,\n target: criticalDest,\n },\n pluginConfig.criticalConfig\n );\n // Generate the Critical CSS\n console.log(`Generating critical CSS from ${criticalSrc} to ${criticalDest}`);\n await critical.generate(options, (err: string) => {\n if (err) {\n console.error(err);\n }\n if (callback) {\n callback(err);\n }\n });\n }\n }\n }\n}\n\nexport default PluginCritical;\n"],
5+
"mappings": ";;;;;;;AACA;AAGA,IAAM,WAAW,UAAQ;AAEzB,IAAM,iBAAiB;AAKvB,IAAM,wBAAiD;AAAA,EACrD,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,WAAW;AAAA,IACT,iBAAiB;AAAA;AAAA;AAYrB,wBAAwB,cAAoC,UAA6B;AACvF,SAAO;AAAA,IACL,MAAM;AAAA,UACA,YAAY,eAAe,QAAQ;AACvC,YAAM,MAAqB;AAE3B,iBAAW,SAAS,OAAO,OAAO,SAAS;AACzC,YAAI,MAAM,SAAS,WAAW,MAAM,SAAS,SAAS,SAAS;AAC7D,gBAAM,UAAU,KAAK,KAAK,cAAc,OAAO,IAAI,MAAM;AACzD,cAAI,KAAK;AAAA;AAAA;AAIb,UAAI,CAAC,IAAI,QAAQ;AACf;AAAA;AAGF,iBAAW,QAAQ,aAAa,eAAe;AAC7C,cAAM,eAAe,aAAa;AAClC,cAAM,cAAc,aAAa,cAAc,KAAK;AACpD,cAAM,eAAe,KAAK,WAAW;AAErC,cAAM,UAAU,OAAO,OACnB,CAAE,MACF,uBACA;AAAA,UACE,MAAM;AAAA,UACN,KAAK;AAAA,UACL,QAAQ;AAAA,WAEV,aAAa;AAGjB,gBAAQ,IAAI,gCAAgC,kBAAkB;AAC9D,cAAM,SAAS,SAAS,SAAS,CAAC,QAAgB;AAChD,cAAI,KAAK;AACP,oBAAQ,MAAM;AAAA;AAEhB,cAAI,UAAU;AACZ,qBAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQrB,IAAO,cAAQ;",
6+
"names": []
7+
}

0 commit comments

Comments
 (0)