diff --git a/README.md b/README.md index f5c50910..148c812b 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,7 @@ key is `urls`. Other optional options are: * `viewport` - viewport object as specified in [page.setViewport](https://github.com/GoogleChrome/puppeteer/blob/v1.0.0/docs/api.md#pagesetviewportviewport) * `puppeteerArgs` - Args sent to puppeteer when launching. [List of strings for headless Chrome](https://peter.sh/experiments/chromium-command-line-switches/). +* `cssoOptions` - CSSO compress function [options](https://github.com/css/csso#compressast-options) ## Warnings diff --git a/src/run.js b/src/run.js index 0524db39..af8d143b 100644 --- a/src/run.js +++ b/src/run.js @@ -319,12 +319,13 @@ const processPage = ({ /** * - * @param {{ urls: Array, debug: boolean, loadimages: boolean, skippable: function, browser: any, userAgent: string, withoutjavascript: boolean, viewport: any, puppeteerArgs: Array }} options + * @param {{ urls: Array, debug: boolean, loadimages: boolean, skippable: function, browser: any, userAgent: string, withoutjavascript: boolean, viewport: any, puppeteerArgs: Array, cssoOptions: Object }} options * @return Promise<{ finalCss: string, stylesheetContents: { [key: string]: string } }> */ const minimalcss = async options => { const { urls } = options; const debug = options.debug || false; + const cssoOptions = options.cssoOptions || {}; const puppeteerArgs = options.puppeteerArgs || []; const browser = options.browser || @@ -502,7 +503,7 @@ const minimalcss = async options => { // When ultimately, what was need is `p { color: blue; font-weight: bold}`. // The csso.minify() function will solve this, *and* whitespace minify // it too. - csso.compress(allCombinedAst); + csso.compress(allCombinedAst, cssoOptions); postProcessOptimize(allCombinedAst); const returned = { diff --git a/tests/examples/comments.css b/tests/examples/comments.css new file mode 100644 index 00000000..d516f400 --- /dev/null +++ b/tests/examples/comments.css @@ -0,0 +1,4 @@ +/*! test css comment */ +p { + color: red; +} diff --git a/tests/examples/comments.html b/tests/examples/comments.html new file mode 100644 index 00000000..9e0db9c0 --- /dev/null +++ b/tests/examples/comments.html @@ -0,0 +1,10 @@ + + + + + + + +

Only a P tag in this document. And images too.

+ + diff --git a/tests/main.test.js b/tests/main.test.js index c326c5dc..4d6bd512 100644 --- a/tests/main.test.js +++ b/tests/main.test.js @@ -206,3 +206,13 @@ test('avoids link tags that is css data', async () => { // See https://github.com/peterbe/minimalcss/issues/158 expect(finalCss).toMatch(''); }); + +test('accept CSSO options', async () => { + const cssoOptions = {}; + let { finalCss } = await runMinimalcss('comments', { cssoOptions }); + expect(finalCss).toMatch('test css comment'); + + cssoOptions.comments = false; + ({ finalCss } = await runMinimalcss('comments', { cssoOptions })); + expect(finalCss).not.toMatch('test css comment'); +});