jalla 1.0.0-40 → 1.0.0-41
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.
- package/lib/document.js +1 -72
- package/package.json +1 -2
package/lib/document.js
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
var minifier = require('posthtml-minifier')
|
2
2
|
var posthtmlify = require('posthtmlify')
|
3
3
|
var documentify = require('documentify')
|
4
|
-
var { Readable } = require('stream')
|
5
4
|
var hyperstream = require('hstream')
|
6
5
|
var caniuse = require('caniuse-api')
|
7
|
-
var purgecss = require('purgecss')
|
8
|
-
var through = require('through2')
|
9
6
|
var resolve = require('resolve')
|
10
7
|
var jsesc = require('jsesc')
|
11
8
|
var path = require('path')
|
@@ -83,12 +80,10 @@ function document (body, state, app, cb) {
|
|
83
80
|
}
|
84
81
|
|
85
82
|
d.transform(prependToHead, `
|
86
|
-
<link rel="
|
83
|
+
<link rel="stylesheet" href="${styles.url}">
|
87
84
|
<script src="https://polyfill.io/v3/polyfill.min.js${features ? `?features=${features}` : ''}"></script>
|
88
85
|
<script src="${script.url}" defer></script>
|
89
86
|
`)
|
90
|
-
|
91
|
-
d.transform(prependCriticalCSS(styles.read.bind(styles)))
|
92
87
|
}
|
93
88
|
|
94
89
|
if (state.meta) {
|
@@ -152,69 +147,3 @@ function stringify (data) {
|
|
152
147
|
function prependToHead (str) {
|
153
148
|
return hyperstream({ head: { _prependHtml: str } })
|
154
149
|
}
|
155
|
-
|
156
|
-
// create documentify transform inlining critical CSS
|
157
|
-
// str -> Stream
|
158
|
-
function prependCriticalCSS (getStyles) {
|
159
|
-
var html = ''
|
160
|
-
|
161
|
-
return function () {
|
162
|
-
return through(collect, compose)
|
163
|
-
}
|
164
|
-
|
165
|
-
// collect html but push nothing
|
166
|
-
// (str, str, fn) -> void
|
167
|
-
function collect (chunk, enc, cb) {
|
168
|
-
html += chunk
|
169
|
-
cb(null)
|
170
|
-
}
|
171
|
-
|
172
|
-
// compose middleman stream for inlining the CSS
|
173
|
-
// fn -> void
|
174
|
-
function compose (cb) {
|
175
|
-
var res = ''
|
176
|
-
var self = this
|
177
|
-
|
178
|
-
getStyles().then(function (css) {
|
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
|
-
var prepend = hyperstream({
|
188
|
-
head: {
|
189
|
-
_prependHtml: `<style>${css}</style>`
|
190
|
-
}
|
191
|
-
})
|
192
|
-
var stream = new Readable()
|
193
|
-
stream._read = Function.prototype
|
194
|
-
|
195
|
-
// pipe the collected html through hyperstream forwarding to self
|
196
|
-
stream.pipe(prepend).pipe(through(write, end))
|
197
|
-
stream.push(html)
|
198
|
-
stream.push(null)
|
199
|
-
}).catch(function () {
|
200
|
-
// fail silently and skip inline styles
|
201
|
-
self.push(html)
|
202
|
-
return cb()
|
203
|
-
})
|
204
|
-
|
205
|
-
// collect the resulting html with inlined CSS
|
206
|
-
// (str, str, fn) -> void
|
207
|
-
function write (chunk, enc, cb) {
|
208
|
-
res += chunk
|
209
|
-
cb(null, chunk)
|
210
|
-
}
|
211
|
-
|
212
|
-
// resolve self with the complete HTML (with inlined CSS)
|
213
|
-
// fn -> void
|
214
|
-
function end (done) {
|
215
|
-
self.push(res)
|
216
|
-
done()
|
217
|
-
cb()
|
218
|
-
}
|
219
|
-
}
|
220
|
-
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jalla",
|
3
|
-
"version": "1.0.0-
|
3
|
+
"version": "1.0.0-41",
|
4
4
|
"description": "A web compiler and server in one",
|
5
5
|
"main": "index.js",
|
6
6
|
"bin": "bin.js",
|
@@ -83,7 +83,6 @@
|
|
83
83
|
"posthtml-minifier": "^0.1.0",
|
84
84
|
"posthtmlify": "^0.2.0",
|
85
85
|
"pretty-bytes": "^5.2.0",
|
86
|
-
"purgecss": "^4.1.3",
|
87
86
|
"read-pkg-up": "^7.0.1",
|
88
87
|
"regenerator-runtime": "^0.13.5",
|
89
88
|
"resolve": "^1.15.1",
|