@rebuildjs/tailwindcss 0.1.0 → 0.1.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebuildjs/tailwindcss",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Tailwindcss integration with rebuildjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tailwindcss",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"files": [
|
|
27
27
|
"*.d.ts",
|
|
28
28
|
"*.js",
|
|
29
|
-
"*.json"
|
|
29
|
+
"*.json",
|
|
30
|
+
"rebuild_tailwind_plugin"
|
|
30
31
|
],
|
|
31
32
|
"types": "./index.d.ts",
|
|
32
33
|
"exports": {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Cancel, nullish__none_, run, tup } from 'ctx-core/function'
|
|
2
|
+
import { be, memo_ } from 'ctx-core/rmemo'
|
|
3
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
4
|
+
import postcss from 'postcss'
|
|
5
|
+
import {
|
|
6
|
+
app_ctx,
|
|
7
|
+
browser__output_,
|
|
8
|
+
build_id_,
|
|
9
|
+
server__output_,
|
|
10
|
+
server__output__relative_path_M_middleware_ctx_
|
|
11
|
+
} from 'rebuildjs'
|
|
12
|
+
import { relysjs__build_id_, relysjs__ready_ } from 'relysjs'
|
|
13
|
+
import tailwind from 'tailwindcss'
|
|
14
|
+
export function rebuild_tailwind_plugin_() {
|
|
15
|
+
return { name: 'tailwind', setup: setup_() }
|
|
16
|
+
function setup_() {
|
|
17
|
+
/**
|
|
18
|
+
* @param {import('esbuild').PluginBuild}build
|
|
19
|
+
*/
|
|
20
|
+
const setup = (build)=>{
|
|
21
|
+
build.onEnd(result=>{
|
|
22
|
+
if (result.errors.length) {
|
|
23
|
+
throw new Error(`Build errors: ${result.errors.length} errors`)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
setup.tailwind__build$ = tailwind__build$_()
|
|
28
|
+
return setup
|
|
29
|
+
function tailwind__build$_() {
|
|
30
|
+
return be(app_ctx, ctx=>
|
|
31
|
+
run(memo_(tailwind__build$=>{
|
|
32
|
+
r()
|
|
33
|
+
return tailwind__build$
|
|
34
|
+
function r() {
|
|
35
|
+
if (!relysjs__ready_(ctx)) return
|
|
36
|
+
nullish__none_(tup(
|
|
37
|
+
build_id_(ctx),
|
|
38
|
+
relysjs__build_id_(ctx),
|
|
39
|
+
server__output__relative_path_M_middleware_ctx_(app_ctx),
|
|
40
|
+
), async (
|
|
41
|
+
build_id,
|
|
42
|
+
relysjs__build_id,
|
|
43
|
+
server__output__relative_path_M_middleware_ctx,
|
|
44
|
+
)=>{
|
|
45
|
+
try {
|
|
46
|
+
for (const middleware_ctx of server__output__relative_path_M_middleware_ctx.values()) {
|
|
47
|
+
await output__process(server__output_(middleware_ctx))
|
|
48
|
+
await output__process(browser__output_(middleware_ctx))
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
if (err instanceof Cancel) return
|
|
52
|
+
throw err
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @param {rebuildjs_metafile_T['outputs'][string]}output
|
|
56
|
+
* @returns {Promise<void>}
|
|
57
|
+
*/
|
|
58
|
+
async function output__process(
|
|
59
|
+
output
|
|
60
|
+
) {
|
|
61
|
+
const cssBundle = output?.cssBundle
|
|
62
|
+
if (!cssBundle) return
|
|
63
|
+
const result = await cmd(postcss[
|
|
64
|
+
tailwind({
|
|
65
|
+
content: output.cssBundle_content
|
|
66
|
+
})
|
|
67
|
+
]).process(
|
|
68
|
+
await cmd(readFile(cssBundle)),
|
|
69
|
+
{
|
|
70
|
+
from: cssBundle,
|
|
71
|
+
to: cssBundle,
|
|
72
|
+
})
|
|
73
|
+
await cmd(writeFile(cssBundle, result.css))
|
|
74
|
+
await cmd(writeFile(cssBundle + '.map', JSON.stringify(result.map)))
|
|
75
|
+
}
|
|
76
|
+
async function cmd(promise) {
|
|
77
|
+
if (cancel_()) throw new Cancel()
|
|
78
|
+
const rv = await promise
|
|
79
|
+
if (cancel_()) {
|
|
80
|
+
promise.cancel?.()
|
|
81
|
+
throw new Cancel()
|
|
82
|
+
}
|
|
83
|
+
return rv
|
|
84
|
+
}
|
|
85
|
+
function cancel_() {
|
|
86
|
+
return (
|
|
87
|
+
build_id_(ctx) !== build_id
|
|
88
|
+
|| relysjs__build_id_(ctx) !== relysjs__build_id
|
|
89
|
+
|| server__output__relative_path_M_middleware_ctx_(
|
|
90
|
+
ctx) !== server__output__relative_path_M_middleware_ctx
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
})), { id: 'tailwind__build$', ns: 'app' })
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|