packaton 0.0.12 → 0.0.13
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/README.md +9 -9
- package/package.json +1 -1
- package/src/app-prod.js +2 -2
- package/src/plugins-dev/watcherDev.js +1 -12
- package/src/router.js +2 -17
package/README.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Static Pages Bundler.
|
|
4
4
|
|
|
5
|
+
## Limitations
|
|
6
|
+
- `src` and `href` URLs must be absolute
|
|
7
|
+
- can't write inline scripts or css (all must be in an external file, packaton inlines them)
|
|
8
|
+
- must have an index
|
|
9
|
+
- Ignored Documents start with `_`, so you can't have routes that begin with _
|
|
10
|
+
- Non-Documents and Files outside config.assetsDir are not automatically copied over,
|
|
11
|
+
you need to specify them.
|
|
12
|
+
|
|
13
|
+
|
|
5
14
|
## HTML Template
|
|
6
15
|
Optionally, you can create an HTML template.
|
|
7
16
|
For example, to handle the common header, navigation, and footer.
|
|
@@ -39,12 +48,3 @@ Packaton({
|
|
|
39
48
|
```
|
|
40
49
|
|
|
41
50
|
To avoid minifying, you can pass `a=>a`
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
## Caveats
|
|
45
|
-
- can't write inline scripts or css (all must be in an external file, packaton inlines them)
|
|
46
|
-
- must have an index
|
|
47
|
-
- Ignored Documents start with `_`, so you can't have routes that begin with _
|
|
48
|
-
- Non-Documents and Files outside config.assetsDir are not automatically copied over,
|
|
49
|
-
you need to specify them.
|
|
50
|
-
- assets/media only files at the top level get hashed-named. But files within subdirs are not (by design).
|
package/package.json
CHANGED
package/src/app-prod.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cpSync } from 'node:fs'
|
|
2
2
|
import { createServer } from 'node:http'
|
|
3
|
-
import { basename, join
|
|
3
|
+
import { basename, join } from 'node:path'
|
|
4
4
|
|
|
5
5
|
import { docs } from './app.js'
|
|
6
6
|
import { router } from './router.js'
|
|
@@ -46,7 +46,7 @@ export async function buildStaticPages(config) {
|
|
|
46
46
|
|
|
47
47
|
const cspByRoute = []
|
|
48
48
|
for (const [route, rawHtml] of pages) {
|
|
49
|
-
const doc = new HtmlCompiler(rawHtml,
|
|
49
|
+
const doc = new HtmlCompiler(rawHtml, pSource, {
|
|
50
50
|
minifyJS: config.minifyJS,
|
|
51
51
|
minifyCSS: config.minifyCSS,
|
|
52
52
|
minifyHTML: config.minifyHTML,
|
|
@@ -24,18 +24,7 @@ async function longPollDevChanges() {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function hotReloadCSS(file) {
|
|
27
|
-
let link = document.querySelector(`link[href^="
|
|
28
|
-
|
|
29
|
-
// Fallback: construct relative path based on current pathname
|
|
30
|
-
if (!link) {
|
|
31
|
-
const parts = window.location.pathname.split('/').filter(Boolean)
|
|
32
|
-
if (parts.length > 1)
|
|
33
|
-
parts.pop()
|
|
34
|
-
const urlDir = parts.join('/') + '/'
|
|
35
|
-
const r = file.split(urlDir).pop()
|
|
36
|
-
link = document.querySelector(`link[href^="${r}"]`)
|
|
37
|
-
}
|
|
38
|
-
|
|
27
|
+
let link = document.querySelector(`link[href^="/${file}"]`)
|
|
39
28
|
if (link) {
|
|
40
29
|
const [url] = link.getAttribute('href').split('?')
|
|
41
30
|
link.href = url + '?' + Date.now()
|
package/src/router.js
CHANGED
|
@@ -3,7 +3,6 @@ import { readFile } from 'node:fs/promises'
|
|
|
3
3
|
|
|
4
4
|
import { docs } from './app.js'
|
|
5
5
|
import { mimeFor } from './utils/mimes.js'
|
|
6
|
-
import { isDirectory } from './utils/fs-utils.js'
|
|
7
6
|
import { devClientWatcher } from './plugins-dev/WatcherDevClient.js'
|
|
8
7
|
import { sendError, sendJSON, servePartialContent, serveAsset } from './utils/http-response.js'
|
|
9
8
|
|
|
@@ -35,10 +34,10 @@ export function router({ srcPath, ignore, mode }) {
|
|
|
35
34
|
await serveDocument(response, docs.fileFor(join(url, 'index')), isDev)
|
|
36
35
|
|
|
37
36
|
else if (req.headers.range)
|
|
38
|
-
await servePartialContent(response, req.headers,
|
|
37
|
+
await servePartialContent(response, req.headers, join(srcPath, url))
|
|
39
38
|
|
|
40
39
|
else
|
|
41
|
-
serveAsset(response,
|
|
40
|
+
serveAsset(response, join(srcPath, url))
|
|
42
41
|
}
|
|
43
42
|
catch (error) {
|
|
44
43
|
sendError(response, error)
|
|
@@ -57,20 +56,6 @@ async function serveDocument(response, file, isDev) {
|
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
|
|
60
|
-
function resolveUrl(req, srcPath, url) {
|
|
61
|
-
return join(srcPath, dirFor(req.headers.referer, srcPath), url)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function dirFor(referer = '/', srcPath) {
|
|
65
|
-
if (referer.endsWith('/'))
|
|
66
|
-
return ''
|
|
67
|
-
const p = new URL(referer).pathname
|
|
68
|
-
return isDirectory(join(srcPath, p))
|
|
69
|
-
? p
|
|
70
|
-
: ''
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
59
|
const LONG_POLL_SERVER_TIMEOUT = 8000
|
|
75
60
|
|
|
76
61
|
function longPollDevHotReload(req, response) {
|