refactor: move cache and src css
This commit is contained in:
parent
d912ea247d
commit
9286ec758d
20
build.ts
20
build.ts
|
@ -3,7 +3,7 @@ import { ensureDir } from '$std/fs/mod.ts'
|
||||||
import { parse, resolve } from '$std/path/mod.ts'
|
import { parse, resolve } from '$std/path/mod.ts'
|
||||||
|
|
||||||
console.log('building styles starts')
|
console.log('building styles starts')
|
||||||
await ensureDir('_fresh')
|
await ensureDir('_fresh/static')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//prevent Deno from exiting before bundle
|
//prevent Deno from exiting before bundle
|
||||||
|
@ -12,7 +12,7 @@ try {
|
||||||
const cssImports = new Map()
|
const cssImports = new Map()
|
||||||
|
|
||||||
const { code, map } = await bundleAsync({
|
const { code, map } = await bundleAsync({
|
||||||
filename: './static/stylesheets/main.css',
|
filename: './src/stylesheets/main.css',
|
||||||
minify: true,
|
minify: true,
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
resolver: {
|
resolver: {
|
||||||
|
@ -29,22 +29,24 @@ try {
|
||||||
|
|
||||||
//update cache for new remote
|
//update cache for new remote
|
||||||
const response = await fetch(specifier)
|
const response = await fetch(specifier)
|
||||||
const file = await response.text()
|
const file = await response.arrayBuffer()
|
||||||
|
const hash = new Uint8Array(await crypto.subtle.digest('SHA-256', file))
|
||||||
|
const filename = [...hash].map(value => value.toString(16).padStart(2, '0')).join('')
|
||||||
|
|
||||||
const filename = `_fresh/${crypto.randomUUID()}`
|
const filepath = `_fresh/${filename}`
|
||||||
await Deno.writeTextFile(filename, file)
|
await Deno.writeFile(filepath, new Uint8Array(file))
|
||||||
cssImports.set(specifier, filename)
|
cssImports.set(specifier, filepath)
|
||||||
return filename
|
return filepath
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
await Deno.writeTextFile(
|
await Deno.writeTextFile(
|
||||||
'./_fresh/styles.css',
|
'./static/styles.css',
|
||||||
new TextDecoder().decode(code),
|
new TextDecoder().decode(code),
|
||||||
)
|
)
|
||||||
await Deno.writeTextFile(
|
await Deno.writeTextFile(
|
||||||
'./_fresh/styles.map.css',
|
'./static/styles.map.css',
|
||||||
new TextDecoder().decode(map!),
|
new TextDecoder().decode(map!),
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
"build": "deno run -A dev.ts build",
|
"build": "deno run -A dev.ts build",
|
||||||
"preview": "deno run -A main.ts",
|
"preview": "deno run -A main.ts",
|
||||||
"update": "deno run -A -r https://fresh.deno.dev/update .",
|
"update": "deno run -A -r https://fresh.deno.dev/update .",
|
||||||
"assets:watch": "deno run -A --watch=static/stylesheets/ build.ts",
|
"assets:watch": "deno run -A --watch=src/ build.ts",
|
||||||
"assets": "deno run -A build.ts"
|
"assets": "deno run -A build.ts"
|
||||||
},
|
},
|
||||||
"fmt": {
|
"fmt": {
|
||||||
|
|
Loading…
Reference in a new issue