Load ruffle
This commit is contained in:
parent
25de264abb
commit
b46de85926
4 changed files with 50 additions and 2 deletions
40
build/copy_plugin.js
Normal file
40
build/copy_plugin.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import serveStatic from 'serve-static'
|
||||
import { resolve } from 'node:path'
|
||||
import { cp } from 'node:fs/promises'
|
||||
|
||||
const getPrefix = s => {
|
||||
const padEnd = s.endsWith('/') ? s : s + '/'
|
||||
return padEnd.startsWith('/') ? padEnd : '/' + padEnd
|
||||
}
|
||||
|
||||
const copyPlugin = ({ inUrl, inFs }) => {
|
||||
const prefix = getPrefix(inUrl)
|
||||
const subdir = prefix.slice(1)
|
||||
let copyTarget
|
||||
const handler = serveStatic(inFs)
|
||||
|
||||
return [{
|
||||
name: 'copy-plugin-serve',
|
||||
apply: 'serve',
|
||||
configureServer (server) {
|
||||
server.middlewares.use(prefix, handler)
|
||||
}
|
||||
}, {
|
||||
name: 'copy-plugin-build',
|
||||
apply: 'build',
|
||||
configResolved (config) {
|
||||
copyTarget = resolve(config.root, config.build.outDir, subdir)
|
||||
},
|
||||
closeBundle: {
|
||||
order: 'post',
|
||||
sequential: true,
|
||||
async handler () {
|
||||
console.log(`Copying '${inFs}' to ${copyTarget}...`)
|
||||
await cp(inFs, copyTarget, { recursive: true })
|
||||
console.log('Done.')
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
export default copyPlugin
|
||||
Loading…
Add table
Add a link
Reference in a new issue