2021-09-09 09:35:21 +08:00
|
|
|
import { watch, rollup, OutputOptions } from 'rollup'
|
2021-08-05 09:25:34 +08:00
|
|
|
import minimist from 'minimist'
|
|
|
|
import chalk from 'chalk'
|
2021-09-09 09:35:21 +08:00
|
|
|
import ora from 'ora'
|
|
|
|
import options from './rollup.config'
|
2021-08-05 09:25:34 +08:00
|
|
|
|
|
|
|
const argv = minimist(process.argv.slice(2))
|
2021-09-09 09:35:21 +08:00
|
|
|
const opt = options({ proc: 'preload', env: argv.env })
|
2021-08-05 09:25:34 +08:00
|
|
|
const TAG = '[build-preload.ts]'
|
2021-09-09 09:35:21 +08:00
|
|
|
const spinner = ora(`${TAG} Electron preload build...`)
|
2021-08-05 09:25:34 +08:00
|
|
|
|
2021-09-09 09:35:21 +08:00
|
|
|
; (async () => {
|
|
|
|
if (argv.watch) {
|
|
|
|
const watcher = watch(opt)
|
|
|
|
watcher.on('change', filename => {
|
|
|
|
const log = chalk.yellow(`change -- ${filename}`)
|
|
|
|
console.log(TAG, log)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo Hot reload render process !!!
|
|
|
|
*/
|
2021-08-05 09:25:34 +08:00
|
|
|
})
|
2021-09-09 09:35:21 +08:00
|
|
|
} else {
|
|
|
|
spinner.start()
|
|
|
|
try {
|
|
|
|
const build = await rollup(opt)
|
|
|
|
await build.write(opt.output as OutputOptions)
|
|
|
|
spinner.succeed()
|
|
|
|
process.exit()
|
|
|
|
} catch (error) {
|
2021-08-05 09:25:34 +08:00
|
|
|
console.log(`\n${TAG} ${chalk.red('构建报错')}\n`, error, '\n')
|
2021-09-09 09:35:21 +08:00
|
|
|
spinner.fail()
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2021-08-05 09:25:34 +08:00
|
|
|
}
|
2021-09-09 09:35:21 +08:00
|
|
|
})();
|