-
-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vite template can not generate asar #3423
Comments
I noticed that |
Have same problem and solved with |
Yeah
|
After a few hours, I think I fully understand how to deal with it.
Code spoilerconst fsp = require('node:fs/promises')
const path = require('node:path')
/**
* @param {string} folder
* @param {string} [exclude]
*/
async function cleanupEmptyFolders (folder, exclude) {
// eslint-disable-next-line security/detect-non-literal-fs-filename
if (!(await fsp.stat(folder)).isDirectory()) return
const folderName = path.basename(folder)
if (exclude && exclude.includes(folderName)) {
return
}
// eslint-disable-next-line security/detect-non-literal-fs-filename
let files = await fsp.readdir(folder)
if (files.length > 0) {
await Promise.all(files.map(file => cleanupEmptyFolders(path.join(folder, file), exclude)))
// Re-evaluate files; after deleting subfolders we may have an empty parent
// folder now.
// eslint-disable-next-line security/detect-non-literal-fs-filename
files = await fsp.readdir(folder)
}
if (files.length === 0) {
// eslint-disable-next-line security/detect-non-literal-fs-filename
await fsp.rmdir(folder)
}
} and add to packager config: afterPrune: [(buildPath, electronVersion, platform, arch, callback) => {
cleanupEmptyFolders(path.join(buildPath, 'node_modules'))
.then(() => callback())
.catch(error => callback(error))
}],
Code spoiler ignore: [
'.commitlintrc.js',
'.editorconfig',
'.env.development',
'.env.example',
'.env.production',
'.eslintrc.js',
'.git',
'.gitignore',
'.husky',
'.idea',
'.yarn',
'.yarnrc.yml',
'assets',
'forge.config.js',
'jsconfig.json',
'package-lock.json',
'pnpm-lock.yaml',
'src',
'vite.preload-notify.config.mjs',
'vite.preload.config.mjs',
'vite.renderer-notify.config.mjs',
'vite.renderer.config.mjs',
'node_modules/fastify/test'
].map(x => new RegExp('^/' + x)) After all of that, my asar deceased from ~700mb - 1GB to 13 MB, and can be less Result config: Code spoilerconst fsp = require('node:fs/promises')
const path = require('node:path')
const meta = require('./package.json')
/**
* @param {string} folder
* @param {string} [exclude]
*/
async function cleanupEmptyFolders (folder, exclude) {
// eslint-disable-next-line security/detect-non-literal-fs-filename
if (!(await fsp.stat(folder)).isDirectory()) return
const folderName = path.basename(folder)
if (exclude && exclude.includes(folderName)) {
return
}
// eslint-disable-next-line security/detect-non-literal-fs-filename
let files = await fsp.readdir(folder)
if (files.length > 0) {
await Promise.all(files.map(file => cleanupEmptyFolders(path.join(folder, file), exclude)))
// Re-evaluate files; after deleting subfolders we may have an empty parent
// folder now.
// eslint-disable-next-line security/detect-non-literal-fs-filename
files = await fsp.readdir(folder)
}
if (files.length === 0) {
// eslint-disable-next-line security/detect-non-literal-fs-filename
await fsp.rmdir(folder)
}
}
module.exports = {
packagerConfig: {
asar: true,
executableName: meta.productName,
icon: path.resolve(__dirname, 'assets', 'logo', 'logo'),
prune: true,
afterPrune: [(buildPath, electronVersion, platform, arch, callback) => {
cleanupEmptyFolders(path.join(buildPath, 'node_modules'))
.then(() => callback())
.catch(error => callback(error))
}],
ignore: [
'.commitlintrc.js',
'.editorconfig',
'.env.development',
'.env.example',
'.env.production',
'.eslintrc.js',
'.git',
'.gitignore',
'.husky',
'.idea',
'.yarn',
'.yarnrc.yml',
'assets',
'forge.config.js',
'jsconfig.json',
'package-lock.json',
'pnpm-lock.yaml',
'src',
'vite.preload-notify.config.mjs',
'vite.preload.config.mjs',
'vite.renderer-notify.config.mjs',
'vite.renderer.config.mjs',
'node_modules/fastify/test'
].map(x => new RegExp('^/' + x))
},
// ...
} also you can add // Cleanup package.json
const packageDotJson = path.join(buildPath, 'package.json')
const json = await fsp.readFile(packageDotJson, 'utf8')
const content = JSON.parse(json)
const allowedKeys = [
'name', 'productName', 'version', 'description', 'main',
'keywords', 'homepage', 'bugs', 'author', 'license'
]
const result = Object.fromEntries(
Object.entries(content)
.filter(([key]) => allowedKeys.includes(key))
)
await fsp.writeFile(packageDotJson, JSON.stringify(result, null, 2)) |
If extract the
I think the vite should be same with webpack, the asar should only include the |
Next version of Vite plugin will enabled |
Will it be 0.29?
|
Is |
Implemented by #3480 |
Pre-flight checklist
Electron Forge version
7.1.0
Electron version
v27.1.0
Operating system
macOS 14.1.1 (23B81)
Last known working Electron Forge version
No response
Expected behavior
After yarn package, I can find the app.asar file in XXX.app/Contents/Resources
Actual behavior
app.asar is gone and the app folder exists but the folder include everything, for example the whole node_modules
Steps to reproduce
npm init electron-app@latest demo -- --template=vite-typescript
cd demo
yarn package
ls out/demo-darwin-arm64/demo.app/Contents/Resources/
Additional information
If I create code base by the webpack-typescript template, it is ok.
The text was updated successfully, but these errors were encountered: