feature: main,preload build
This commit is contained in:
1 parent
93fa203620
commit
7b92b312d6
8 files changed
+108
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { join } from 'path'
|
||||
import { readdirSync } from 'fs'
|
||||
import { OutputOptions, rollup, RollupOptions, RollupOutput } from 'rollup'
|
||||
import { optionsFactory } from './rollup.config'
|
||||
|
||||
const TAG = '[build.ts]'
|
||||
|
||||
function mainOptions() {
|
||||
return optionsFactory({
|
||||
input: join(__dirname, '../main/index.ts'),
|
||||
output: {
|
||||
dir: 'dist/main',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function preloadOptions() {
|
||||
const dirs = readdirSync(join(__dirname, '../preload'))
|
||||
const inputs = dirs.filter(name => /^index\..+\.ts$/.test(name))
|
||||
|
||||
return optionsFactory({
|
||||
input: inputs.map(input => join(__dirname, '../preload', input)),
|
||||
output: {
|
||||
dir: 'dist/preload',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async function doBuild(options: RollupOptions): Promise<[Error | null, RollupOutput | null]> {
|
||||
try {
|
||||
const build = await rollup(options)
|
||||
const output = await build.write(options.output as OutputOptions)
|
||||
|
||||
return [null, output]
|
||||
} catch (error: any) {
|
||||
return [error, null]
|
||||
}
|
||||
}
|
||||
|
||||
// build
|
||||
[mainOptions(), preloadOptions()].forEach(options => {
|
||||
doBuild(options)
|
||||
.then(([err, output]) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
}
|
||||
output?.output.forEach(out => {
|
||||
console.log(TAG, `Build successed -- ${(out as any).facadeModuleId}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user