Merge pull request #1 from Hacksore/public-folder
Add public folder support
This commit is contained in:
		
						commit
						c72bfe5fea
					
				| 
						 | 
					@ -1,41 +1,33 @@
 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @type {import('electron-builder').Configuration}
 | 
					 * @type {import('electron-builder').Configuration}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
const config = {
 | 
					const config = {
 | 
				
			||||||
  appId: "308487730@qq.com",
 | 
					  appId: '308487730@qq.com',
 | 
				
			||||||
  asar: true,
 | 
					  asar: true,
 | 
				
			||||||
  directories: {
 | 
					  directories: {
 | 
				
			||||||
    output: "release/${version}"
 | 
					    output: 'release/${version}',
 | 
				
			||||||
 | 
					    buildResources: 'public',
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  files: [
 | 
					  files: ['!node_modules', 'dist', 'package.json'],
 | 
				
			||||||
    "!node_modules",
 | 
					 | 
				
			||||||
    "dist",
 | 
					 | 
				
			||||||
    "package.json"
 | 
					 | 
				
			||||||
  ],
 | 
					 | 
				
			||||||
  mac: {
 | 
					  mac: {
 | 
				
			||||||
    artifactName: "${productName}_${version}.${ext}",
 | 
					    artifactName: '${productName}_${version}.${ext}',
 | 
				
			||||||
    target: [
 | 
					    target: ['dmg'],
 | 
				
			||||||
      "dmg"
 | 
					 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  win: {
 | 
					  win: {
 | 
				
			||||||
    target: [
 | 
					    target: [
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        target: "nsis",
 | 
					        target: 'nsis',
 | 
				
			||||||
        arch: [
 | 
					        arch: ['x64'],
 | 
				
			||||||
          "x64"
 | 
					      },
 | 
				
			||||||
        ]
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    artifactName: "${productName}_${version}.${ext}"
 | 
					    artifactName: '${productName}_${version}.${ext}',
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  nsis: {
 | 
					  nsis: {
 | 
				
			||||||
    oneClick: false,
 | 
					    oneClick: false,
 | 
				
			||||||
    perMachine: false,
 | 
					    perMachine: false,
 | 
				
			||||||
    allowToChangeInstallationDirectory: true,
 | 
					    allowToChangeInstallationDirectory: true,
 | 
				
			||||||
    deleteAppDataOnUninstall: false
 | 
					    deleteAppDataOnUninstall: false,
 | 
				
			||||||
  }
 | 
					  },
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export { config }
 | 
					export { config }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 16 KiB  | 
| 
						 | 
					@ -4,6 +4,7 @@ import { build as viteBuild } from 'vite'
 | 
				
			||||||
import { build as electronBuild, Platform } from 'electron-builder'
 | 
					import { build as electronBuild, Platform } from 'electron-builder'
 | 
				
			||||||
import { config as builderConfig } from '../configs/electron-builder.config.mjs'
 | 
					import { config as builderConfig } from '../configs/electron-builder.config.mjs'
 | 
				
			||||||
import chalk from 'chalk'
 | 
					import chalk from 'chalk'
 | 
				
			||||||
 | 
					import path from 'path'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const TAG = chalk.bgBlue('[build.mjs]')
 | 
					const TAG = chalk.bgBlue('[build.mjs]')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,7 +17,17 @@ const viteConfigs = {
 | 
				
			||||||
async function buildElectron() {
 | 
					async function buildElectron() {
 | 
				
			||||||
  for (const [name, configPath] of Object.entries(viteConfigs)) {
 | 
					  for (const [name, configPath] of Object.entries(viteConfigs)) {
 | 
				
			||||||
    console.group(TAG, name)
 | 
					    console.group(TAG, name)
 | 
				
			||||||
    await viteBuild({ configFile: configPath, mode: process.env.NODE_ENV })
 | 
					
 | 
				
			||||||
 | 
					    const config = {
 | 
				
			||||||
 | 
					      configFile: configPath,
 | 
				
			||||||
 | 
					      mode: process.env.NODE_ENV,
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (name === 'reactTs') {
 | 
				
			||||||
 | 
					      config.publicDir = path.resolve('./public')
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    await viteBuild(config)
 | 
				
			||||||
    console.groupEnd()
 | 
					    console.groupEnd()
 | 
				
			||||||
    console.log() // for beautiful log.
 | 
					    console.log() // for beautiful log.
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,14 +1,14 @@
 | 
				
			||||||
process.env.NODE_ENV = 'development'
 | 
					process.env.NODE_ENV = 'development'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { readFileSync } from 'fs'
 | 
					import { readFileSync } from 'fs'
 | 
				
			||||||
import { join } from 'path'
 | 
					import { resolve, join } from 'path'
 | 
				
			||||||
import electron from 'electron'
 | 
					import electron from 'electron'
 | 
				
			||||||
import { spawn } from 'child_process'
 | 
					import { spawn } from 'child_process'
 | 
				
			||||||
import { createServer, build as viteBuild } from 'vite'
 | 
					import { createServer, build as viteBuild } from 'vite'
 | 
				
			||||||
import chalk from 'chalk'
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const TAG = chalk.bgGreen('[dev.mjs]')
 | 
					const pkg = JSON.parse(
 | 
				
			||||||
const pkg = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8'))
 | 
					  readFileSync(join(process.cwd(), 'package.json'), 'utf8')
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @param {{ name: string; configFile: string; writeBundle: import('rollup').OutputPlugin['writeBundle'] }} param0
 | 
					 * @param {{ name: string; configFile: string; writeBundle: import('rollup').OutputPlugin['writeBundle'] }} param0
 | 
				
			||||||
| 
						 | 
					@ -22,9 +22,7 @@ function getWatcher({ name, configFile, writeBundle }) {
 | 
				
			||||||
      watch: {},
 | 
					      watch: {},
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    configFile,
 | 
					    configFile,
 | 
				
			||||||
    plugins: [
 | 
					    plugins: [{ name, writeBundle }],
 | 
				
			||||||
      { name, writeBundle },
 | 
					 | 
				
			||||||
    ],
 | 
					 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -72,7 +70,10 @@ async function watchPreload(viteDevServer) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// bootstrap
 | 
					// bootstrap
 | 
				
			||||||
const viteDevServer = await createServer({ configFile: 'configs/vite.renderer.ts' })
 | 
					const viteDevServer = await createServer({
 | 
				
			||||||
 | 
					  configFile: 'configs/vite.renderer.ts',
 | 
				
			||||||
 | 
					  publicDir: resolve('./public'),
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
await viteDevServer.listen()
 | 
					await viteDevServer.listen()
 | 
				
			||||||
await watchPreload(viteDevServer)
 | 
					await watchPreload(viteDevServer)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,6 +49,10 @@ function App() {
 | 
				
			||||||
          >
 | 
					          >
 | 
				
			||||||
            Vite Docs
 | 
					            Vite Docs
 | 
				
			||||||
          </a>
 | 
					          </a>
 | 
				
			||||||
 | 
					          <div>
 | 
				
			||||||
 | 
					            Place static files into the public folder
 | 
				
			||||||
 | 
					            <img style={{ width: 100 }} src="./img/node.png" />
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
        </p>
 | 
					        </p>
 | 
				
			||||||
      </header>
 | 
					      </header>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue