nomadro/apps/miniprogram/weapp/scripts/ensure-page-wxss-plugin.cjs
Eric dc7a46ee0b Make WeChat launch path pages/home/index and document the index redirect.
Keep 20261011 hub visuals on home; index only reLaunches to avoid missing page wxss.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-11 16:03:31 +08:00

50 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fs = require('fs')
const path = require('path')
const STUB = '/* page styles live in common.wxss */\n'
function ensure(pagesRoot) {
if (!pagesRoot || !fs.existsSync(pagesRoot)) return 0
let n = 0
for (const name of fs.readdirSync(pagesRoot)) {
const dir = path.join(pagesRoot, name)
let st
try {
st = fs.statSync(dir)
} catch {
continue
}
if (!st.isDirectory()) continue
const js = path.join(dir, 'index.js')
const wxss = path.join(dir, 'index.wxss')
if (!fs.existsSync(js) || fs.existsSync(wxss)) continue
fs.writeFileSync(wxss, STUB)
n += 1
}
return n
}
/** 样式进 common 后缺页面 wxss → 微信 ENOENT;编译完成后补空文件 */
class EnsurePageWxssPlugin {
constructor(opts = {}) {
this.pagesRoot = opts.pagesRoot
}
apply(compiler) {
const run = () => {
const n = ensure(this.pagesRoot)
if (n > 0) {
console.log(`[ensure-page-wxss] stubbed ${n} page wxss under ${this.pagesRoot}`)
}
}
compiler.hooks.done.tap('EnsurePageWxssPlugin', () => {
run()
// Taro 部分资源可能略晚于 done 落盘
setTimeout(run, 300)
setTimeout(run, 1200)
})
}
}
module.exports = { EnsurePageWxssPlugin, ensure }