Adds preload & polyfill option

This commit is contained in:
Ben Zörb 2020-05-20 00:31:59 +02:00
parent 5306dcecd4
commit e1408b4070
No known key found for this signature in database
GPG Key ID: B5022087DA9E02FF
2 changed files with 23 additions and 3 deletions

12
cli.js
View File

@ -22,10 +22,13 @@ Options:
-h, --html Path to HTML file
-i, --ignore Skip matching stylesheets
-m, --minify Minify the styles before inlining (default)
-p, --preload Adds preload tags
-e, --extract Remove the inlined styles from any stylesheets referenced in the HTML
-b, --base Is used when extracting styles to find the files references by href attributes
-s, --selector Optionally defines the element used by loadCSS as a reference for inlining
--polyfill Use loadCSS polyfill instead of media=print
--noscript Position of noscript fallback ('body' - end of body, 'head' - end of head, false - no noscript)
`;
@ -62,6 +65,15 @@ const cli = meow(help, {
type: 'string',
alias: 's',
},
preload: {
type: 'boolean',
alias: 'p',
default: false,
},
polyfill: {
type: 'boolean',
default: false,
},
noscript: {
type: 'string',
},

View File

@ -19,7 +19,7 @@ describe('acceptance', () => {
});
test('should work well with the critical CSS & html file passed as input', async () => {
const expected = await read('expected/index-inlined-async-final.html');
const expected = await read('expected/index-inlined-async-final-print.html');
const {stdout, code} = await run(['test/fixtures/index.html', 'test/fixtures/critical.css', '--no-minify']);
expect(code).toBe(0);
@ -33,6 +33,7 @@ describe('acceptance', () => {
'test/fixtures/index.html',
'test/fixtures/critical.css',
'--no-minify',
'--polyfill',
]);
expect(code).toBe(0);
@ -46,6 +47,7 @@ describe('acceptance', () => {
'test/fixtures/critical.css',
'test/fixtures/index.html',
'--no-minify',
'--polyfill',
]);
expect(code).toBe(0);
@ -53,7 +55,7 @@ describe('acceptance', () => {
});
test('Work well with the critical CSS file piped to inline-critical and html file as input', async () => {
const expected = await read('expected/index-inlined-async-final.html');
const expected = await read('expected/index-inlined-async-final-print.html');
const {stdout, code} = await pipe('fixtures/critical.css', ['test/fixtures/index.html', '--no-minify']);
expect(code).toBe(0);
@ -61,7 +63,7 @@ describe('acceptance', () => {
});
test('Work well with the html file piped to inline-critical and critical CSS file as input', async () => {
const expected = await read('expected/index-inlined-async-final.html');
const expected = await read('expected/index-inlined-async-final-print.html');
const {stdout, code} = await pipe('fixtures/index.html', ['test/fixtures/critical.css', '--no-minify']);
expect(code).toBe(0);
@ -100,6 +102,7 @@ describe('Mocked', () => {
'selector',
'-m',
'-e',
'-p',
]);
const cssExpected = await read('fixtures/critical.css');
@ -111,6 +114,7 @@ describe('Mocked', () => {
ignore: ['ignore-me', /regexp/],
minify: true,
extract: true,
preload: true,
});
});
@ -130,6 +134,8 @@ describe('Mocked', () => {
'selector',
'--minify',
'--extract',
'--preload',
'--polyfill',
'--noscript',
'head',
]);
@ -143,6 +149,8 @@ describe('Mocked', () => {
ignore: ['ignore-me', /regexp/],
minify: true,
extract: true,
preload: true,
polyfill: true,
noscript: 'head',
});
});