feat: electron-builder
This commit is contained in:
		
							parent
							
								
									4dc1dd895f
								
							
						
					
					
						commit
						25ac4ae3af
					
				| 
						 | 
					@ -1,6 +1,8 @@
 | 
				
			||||||
import { join, relative } from 'path'
 | 
					import { join, relative } from 'path'
 | 
				
			||||||
import { rollup, RollupOptions, OutputOptions, RollupOutput } from 'rollup'
 | 
					import { rollup, RollupOptions, OutputOptions, RollupOutput } from 'rollup'
 | 
				
			||||||
import { build as viteBuild2 } from 'vite'
 | 
					import { build as viteBuild2 } from 'vite'
 | 
				
			||||||
 | 
					import { build as electronBuild2 } from 'electron-builder'
 | 
				
			||||||
 | 
					import { config as builderConfig } from './electron-builder.config'
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  mainOptions,
 | 
					  mainOptions,
 | 
				
			||||||
  preloadOptions,
 | 
					  preloadOptions,
 | 
				
			||||||
| 
						 | 
					@ -42,15 +44,28 @@ async function buildReactTs(): Promise<BuildResult> {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; (async () => {
 | 
					// build electron
 | 
				
			||||||
 | 
					async function electronBuild() {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    const result = await electronBuild2({ config: builderConfig })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    console.log(TAG, `electron-builder.build result - ${result}`)
 | 
				
			||||||
 | 
					    return [null, result]
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    return [error, null]
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; (async () => {
 | 
				
			||||||
  console.log(TAG, 'Build with rollup.')
 | 
					  console.log(TAG, 'Build with rollup.')
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    await Promise.all([
 | 
					    await Promise.all([
 | 
				
			||||||
 | 
					      // Avoid logs cleaned by vite
 | 
				
			||||||
      rollupBuild(mainOptions()),
 | 
					      rollupBuild(mainOptions()),
 | 
				
			||||||
      rollupBuild(preloadOptions()),
 | 
					      rollupBuild(preloadOptions()),
 | 
				
			||||||
    ])
 | 
					    ])
 | 
				
			||||||
    await buildReactTs()
 | 
					    await buildReactTs()
 | 
				
			||||||
 | 
					    await electronBuild()
 | 
				
			||||||
  } catch (error) {
 | 
					  } catch (error) {
 | 
				
			||||||
    console.error(TAG, error)
 | 
					    console.error(TAG, error)
 | 
				
			||||||
    process.exit(1)
 | 
					    process.exit(1)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,38 @@
 | 
				
			||||||
 | 
					import { Configuration } from 'electron-builder'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const config: Configuration = {
 | 
				
			||||||
 | 
					  appId: "308487730@qq.com",
 | 
				
			||||||
 | 
					  asar: true,
 | 
				
			||||||
 | 
					  directories: {
 | 
				
			||||||
 | 
					    output: "release/${version}"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  files: [
 | 
				
			||||||
 | 
					    "!node_modules",
 | 
				
			||||||
 | 
					    "dist/**"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  mac: {
 | 
				
			||||||
 | 
					    artifactName: "${productName}_${version}.${ext}",
 | 
				
			||||||
 | 
					    target: [
 | 
				
			||||||
 | 
					      "dmg"
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  win: {
 | 
				
			||||||
 | 
					    target: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        target: "nsis",
 | 
				
			||||||
 | 
					        arch: [
 | 
				
			||||||
 | 
					          "x64"
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    artifactName: "${productName}_${version}.${ext}"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  nsis: {
 | 
				
			||||||
 | 
					    oneClick: false,
 | 
				
			||||||
 | 
					    perMachine: false,
 | 
				
			||||||
 | 
					    allowToChangeInstallationDirectory: true,
 | 
				
			||||||
 | 
					    deleteAppDataOnUninstall: false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export { config }
 | 
				
			||||||
		Loading…
	
		Reference in New Issue