Replace Webpack with Rsbuild
This commit is contained in:
+57
-14
@@ -9,10 +9,38 @@ const templateFile = path.join(
|
||||
'scripts.html',
|
||||
)
|
||||
|
||||
const {entrypoints} = require(
|
||||
path.join(projectRoot, 'web-build/asset-manifest.json'),
|
||||
)
|
||||
// Support both webpack (asset-manifest.json) and rsbuild (manifest.json) formats
|
||||
function getEntrypoints() {
|
||||
const webpackManifestPath = path.join(
|
||||
projectRoot,
|
||||
'web-build/asset-manifest.json',
|
||||
)
|
||||
const rsbuildManifestPath = path.join(projectRoot, 'web-build/manifest.json')
|
||||
|
||||
// Try webpack format first
|
||||
if (fs.existsSync(webpackManifestPath)) {
|
||||
const manifest = require(webpackManifestPath)
|
||||
if (manifest.entrypoints) {
|
||||
console.log('Using webpack manifest format')
|
||||
return manifest.entrypoints
|
||||
}
|
||||
}
|
||||
|
||||
// Try rsbuild format
|
||||
if (fs.existsSync(rsbuildManifestPath)) {
|
||||
const manifest = require(rsbuildManifestPath)
|
||||
if (manifest.entries?.index?.initial) {
|
||||
console.log('Using rsbuild manifest format')
|
||||
const initial = manifest.entries.index.initial
|
||||
// Combine JS and CSS entrypoints, CSS first for proper loading order
|
||||
return [...(initial.css || []), ...(initial.js || [])]
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('No valid manifest found in web-build/')
|
||||
}
|
||||
|
||||
const entrypoints = getEntrypoints()
|
||||
console.log(`Found ${entrypoints.length} entrypoints`)
|
||||
console.log(`Writing ${templateFile}`)
|
||||
|
||||
@@ -33,16 +61,31 @@ const outputFile = entrypoints
|
||||
.join('\n')
|
||||
fs.writeFileSync(templateFile, outputFile)
|
||||
|
||||
function copyFiles(sourceDir, targetDir) {
|
||||
const files = fs.readdirSync(path.join(projectRoot, sourceDir))
|
||||
files.forEach(file => {
|
||||
const sourcePath = path.join(projectRoot, sourceDir, file)
|
||||
const targetPath = path.join(projectRoot, targetDir, file)
|
||||
fs.copyFileSync(sourcePath, targetPath)
|
||||
console.log(`Copied ${sourcePath} to ${targetPath}`)
|
||||
})
|
||||
function copyFilesRecursive(sourceDir, targetDir) {
|
||||
const sourcePath = path.join(projectRoot, sourceDir)
|
||||
const targetPath = path.join(projectRoot, targetDir)
|
||||
|
||||
// Ensure target directory exists
|
||||
fs.mkdirSync(targetPath, {recursive: true})
|
||||
|
||||
const entries = fs.readdirSync(sourcePath, {withFileTypes: true})
|
||||
for (const entry of entries) {
|
||||
const srcPath = path.join(sourcePath, entry.name)
|
||||
const destPath = path.join(targetPath, entry.name)
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
// Recursively copy subdirectory
|
||||
copyFilesRecursive(
|
||||
path.join(sourceDir, entry.name),
|
||||
path.join(targetDir, entry.name),
|
||||
)
|
||||
} else {
|
||||
fs.copyFileSync(srcPath, destPath)
|
||||
console.log(`Copied ${srcPath} to ${destPath}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
copyFiles('web-build/static/js', 'bskyweb/static/js')
|
||||
copyFiles('web-build/static/css', 'bskyweb/static/css')
|
||||
copyFiles('web-build/static/media', 'bskyweb/static/media')
|
||||
copyFilesRecursive('web-build/static/js', 'bskyweb/static/js')
|
||||
copyFilesRecursive('web-build/static/css', 'bskyweb/static/css')
|
||||
copyFilesRecursive('web-build/static/media', 'bskyweb/static/media')
|
||||
|
||||
Reference in New Issue
Block a user