jalla 1.0.0-38 → 1.0.0-39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/document.js +15 -11
  2. package/package.json +2 -2
package/lib/document.js CHANGED
@@ -4,9 +4,9 @@ var documentify = require('documentify')
4
4
  var { Readable } = require('stream')
5
5
  var hyperstream = require('hstream')
6
6
  var caniuse = require('caniuse-api')
7
+ var purgecss = require('purgecss')
7
8
  var through = require('through2')
8
9
  var resolve = require('resolve')
9
- var dropcss = require('dropcss')
10
10
  var jsesc = require('jsesc')
11
11
  var path = require('path')
12
12
 
@@ -176,17 +176,17 @@ function prependCriticalCSS (getStyles) {
176
176
  var self = this
177
177
 
178
178
  getStyles().then(function (css) {
179
- try {
180
- var critical = dropcss({ html: html, css: css.toString() })
181
- } catch (err) {
182
- // fail silently and skip inline styles
183
- self.push(html)
184
- return cb()
185
- }
186
-
179
+ css = css.toString().replace(/\/\*#\s*sourceMappingURL=.+?\s*\*\//g, '')
180
+ return new purgecss.PurgeCSS().purge({
181
+ content: [{ raw: html, extension: 'html' }],
182
+ css: [{ raw: css }]
183
+ }).then(function (result) {
184
+ return result.reduce((acc, { css }) => acc + css, '')
185
+ })
186
+ }).then(function (css) {
187
187
  var prepend = hyperstream({
188
188
  head: {
189
- _prependHtml: `<style>${critical.css}</style>`
189
+ _prependHtml: `<style>${css}</style>`
190
190
  }
191
191
  })
192
192
  var stream = new Readable()
@@ -196,7 +196,11 @@ function prependCriticalCSS (getStyles) {
196
196
  stream.pipe(prepend).pipe(through(write, end))
197
197
  stream.push(html)
198
198
  stream.push(null)
199
- }, cb)
199
+ }).catch(function () {
200
+ // fail silently and skip inline styles
201
+ self.push(html)
202
+ return cb()
203
+ })
200
204
 
201
205
  // collect the resulting html with inlined CSS
202
206
  // (str, str, fn) -> void
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jalla",
3
- "version": "1.0.0-38",
3
+ "version": "1.0.0-39",
4
4
  "description": "A web compiler and server in one",
5
5
  "main": "index.js",
6
6
  "bin": "bin.js",
@@ -56,7 +56,6 @@
56
56
  "convert-source-map": "^1.7.0",
57
57
  "dedent": "^0.7.0",
58
58
  "documentify": "^3.2.2",
59
- "dropcss": "^1.0.16",
60
59
  "envify": "^4.1.0",
61
60
  "exorcist": "^2.0.0",
62
61
  "get-port": "^5.1.1",
@@ -84,6 +83,7 @@
84
83
  "posthtml-minifier": "^0.1.0",
85
84
  "posthtmlify": "^0.2.0",
86
85
  "pretty-bytes": "^5.2.0",
86
+ "purgecss": "^4.1.3",
87
87
  "read-pkg-up": "^7.0.1",
88
88
  "regenerator-runtime": "^0.13.5",
89
89
  "resolve": "^1.15.1",