forked from scullyio/scully
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(lib): plugin to inlice critical css * WIP criticalCSS * feat(lib): add plugin to inline critical CSS * docs(lib): fix settings for criticalCss * fix(lib): add missing dep to package.json * fix(lib): add tsconfig optiosn * add key for package.lock * add nrwl/cli * add nrwl/cli Co-authored-by: jorgeucano <[email protected]>
- Loading branch information
1 parent
43c52a2
commit 4367831
Showing
27 changed files
with
1,454 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "../../../.eslintrc", "rules": {}, "ignorePatterns": ["!**/*"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# scully-plugin-critical-css | ||
|
||
This plugins uses the [critcal](https://github.com/addyosmani/critical#critical) script to inline and defer unneeded CSS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
name: 'plugins-scully-plugin-critical-css', | ||
preset: '../../../jest.config.js', | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], | ||
coverageDirectory: '../../../coverage/libs/plugins/scully-plugin-critical-css', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "@scullyio/scully-plugin-critical-css", | ||
"version": "0.0.1", | ||
"peerDependencies": { | ||
"@scullyio/scully": "*", | ||
"jsdom": "*" | ||
}, | ||
"repository": { | ||
"type": "GIT", | ||
"url": "https://github.com/scullyio/scully/tree/main/libs/plugins/scully-plugin-critical-css" | ||
}, | ||
"keywords": [ | ||
"angular", | ||
"scully", | ||
"seo", | ||
"scully-plugin", | ||
"plugin" | ||
], | ||
"dependencies": { | ||
"critical": "^2.0.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib/plugins-scully-plugin-critical-css'; |
7 changes: 7 additions & 0 deletions
7
libs/plugins/scully-plugin-critical-css/src/lib/plugins-scully-plugin-critical-css.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { pluginsScullyPluginCriticalCss } from './plugins-scully-plugin-critical-css'; | ||
|
||
describe('pluginsScullyPluginCriticalCss', () => { | ||
it('should work', () => { | ||
expect(pluginsScullyPluginCriticalCss()).toEqual('plugins-scully-plugin-critical-css'); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
libs/plugins/scully-plugin-critical-css/src/lib/plugins-scully-plugin-critical-css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { HandledRoute, logWarn, registerPlugin, scullyConfig, createFolderFor } from '@scullyio/scully'; | ||
import * as critical from 'critical'; | ||
import { join } from 'path'; | ||
|
||
export const criticalCSS = 'criticalCss'; | ||
|
||
registerPlugin('render', criticalCSS, async (incomingHtml: string, route: HandledRoute) => { | ||
try { | ||
const base = join(scullyConfig.outDir, route.route); | ||
const file = join(base, '/pagestyle.css'); | ||
const assetPaths = [scullyConfig.outDir, join(scullyConfig.outDir, '/assets')]; | ||
createFolderFor(file); | ||
const { html } = await critical.generate({ | ||
html: incomingHtml, | ||
base, | ||
css: join(scullyConfig.outDir, '/styles.css'), | ||
assetPaths, | ||
// target: { | ||
// css: file, | ||
// }, | ||
rebase: () => undefined, | ||
// extract: true, | ||
inlineImages: true, | ||
height: 1400, | ||
width: 1800, | ||
inline: { | ||
preload: true, | ||
}, | ||
}); | ||
return html; | ||
// console.log(css); | ||
} catch (e) { | ||
logWarn(`route: "${route.route}" could not inline CSS`, e); | ||
} | ||
return incomingHtml; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../../dist/out-tsc", | ||
"declaration": true, | ||
"rootDir": "./src", | ||
"types": ["node"] | ||
}, | ||
"exclude": ["**/*.spec.ts"], | ||
"include": ["**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js", "**/*.spec.jsx", "**/*.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.