Skip to content

Commit

Permalink
Merge pull request #55 from electron-vite/v0.9.0
Browse files Browse the repository at this point in the history
V0.9.0
  • Loading branch information
caoxiemeihao authored Aug 12, 2022
2 parents 98dea6b + d68f4f0 commit 4f9e897
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ package-lock.json
# pnpm-lock.yaml
yarn.lock

release
packages/electron-renderer/plugins
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 0.9.0 (2022-08-12)

🎉 `v0.9.0` is a stable version based on `[email protected]`

#### vite-plugin-electron

#### vite-plugin-electron-renderer

- ebc6a3d chore(electron-renderer): remove `renderBuiltUrl()` based on [email protected] ([[email protected]](https://github.com/vitejs/vite/pull/9381/commits/8f2065efcb6ba664f7dce6f3c7666b29e2c56027#diff-aa53520bfd53e6c24220c44494457cc66370fd2bee513c15f9be7eb537a363e7L874))
4 changes: 2 additions & 2 deletions packages/electron-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-electron-renderer",
"version": "0.8.8",
"version": "0.9.0",
"description": "Support use Node.js API in Electron-Renderer",
"main": "plugins/index.js",
"repository": {
Expand All @@ -17,7 +17,7 @@
},
"dependencies": {},
"devDependencies": {
"vite": "^3.0.2"
"vite": "^3.0.6"
},
"files": [
"plugins"
Expand Down
52 changes: 0 additions & 52 deletions packages/electron-renderer/src/build-config.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,5 @@
import path from 'path'
import type { Plugin } from 'vite'

// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/constants.ts#L84-L124
const KNOWN_ASSET_TYPES = [
// images
'png',
'jpe?g',
'jfif',
'pjpeg',
'pjp',
'gif',
'svg',
'ico',
'webp',
'avif',

// media
'mp4',
'webm',
'ogg',
'mp3',
'wav',
'flac',
'aac',

// fonts
'woff2?',
'eot',
'ttf',
'otf',

// other
'webmanifest',
'pdf',
'txt'
]

export default function buildConfig(): Plugin {
return {
name: 'vite-plugin-electron-renderer:build-config',
Expand All @@ -58,22 +22,6 @@ export default function buildConfig(): Plugin {

// prevent accidental clearing of `dist/electron/main`, `dist/electron/preload`
if (config.build.emptyOutDir === undefined) config.build.emptyOutDir = false

// `Uncaught TypeError: Failed to construct 'URL': Invalid URL` #44
if (!config.experimental) config.experimental = {
renderBuiltUrl(filename, type) {
if (
KNOWN_ASSET_TYPES.includes(path.extname(filename).slice(1)) &&
type.hostType === 'js'
) {
// Avoid Vite relative-path assets handling
// https://github.com/vitejs/vite/blob/89dd31cfe228caee358f4032b31fdf943599c842/packages/vite/src/node/build.ts#L850-L862
return { runtime: JSON.stringify(filename) }
}
// TODO: replace `config.build.assetsDir` for chunk js
// TODO: replace `config.build.assetsDir` for split css
},
}
},
}
}
81 changes: 81 additions & 0 deletions packages/electron-renderer/src/build-config.vite-3.0.5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import path from 'path'
import type { Plugin } from 'vite'

// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/constants.ts#L84-L124
const KNOWN_ASSET_TYPES = [
// images
'png',
'jpe?g',
'jfif',
'pjpeg',
'pjp',
'gif',
'svg',
'ico',
'webp',
'avif',

// media
'mp4',
'webm',
'ogg',
'mp3',
'wav',
'flac',
'aac',

// fonts
'woff2?',
'eot',
'ttf',
'otf',

// other
'webmanifest',
'pdf',
'txt'
]

export default function buildConfig(): Plugin {
return {
name: 'vite-plugin-electron-renderer:build-config',
apply: 'build',
config(config) {
// make sure that Electron can be loaded into the local file using `loadFile` after packaging
if (config.base === undefined) config.base = './'

if (config.build === undefined) config.build = {}

// TODO: init `config.build.target`
// https://github.com/vitejs/vite/pull/8843

// ensure that static resources are loaded normally
// TODO: Automatic splicing `build.assetsDir`
if (config.build.assetsDir === undefined) config.build.assetsDir = ''

// https://github.com/electron-vite/electron-vite-vue/issues/107
if (config.build.cssCodeSplit === undefined) config.build.cssCodeSplit = false

// prevent accidental clearing of `dist/electron/main`, `dist/electron/preload`
if (config.build.emptyOutDir === undefined) config.build.emptyOutDir = false

// `Uncaught TypeError: Failed to construct 'URL': Invalid URL` #44
// `[email protected]` fixed this BUG 🐞
// https://github.com/vitejs/vite/pull/9381/commits/8f2065efcb6ba664f7dce6f3c7666b29e2c56027#diff-aa53520bfd53e6c24220c44494457cc66370fd2bee513c15f9be7eb537a363e7L874
if (!config.experimental) config.experimental = {
renderBuiltUrl(filename, type) {
if (
KNOWN_ASSET_TYPES.includes(path.extname(filename).slice(1)) &&
type.hostType === 'js'
) {
// Avoid Vite relative-path assets handling
// https://github.com/vitejs/vite/blob/89dd31cfe228caee358f4032b31fdf943599c842/packages/vite/src/node/build.ts#L850-L862
return { runtime: JSON.stringify(filename) }
}
// TODO: replace `config.build.assetsDir` for chunk js
// TODO: replace `config.build.assetsDir` for split css
},
}
},
}
}
4 changes: 2 additions & 2 deletions packages/electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-electron",
"version": "0.8.8",
"version": "0.9.0",
"description": "Integrate Vite and Electron",
"main": "dist/index.js",
"repository": {
Expand All @@ -19,7 +19,7 @@
"vite-plugin-electron-renderer": "workspace:*"
},
"devDependencies": {
"vite": "^3.0.2",
"vite": "^3.0.6",
"rollup": "^2.77.0"
},
"files": [
Expand Down
37 changes: 37 additions & 0 deletions playground/usecase-in-main/electron-builder.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @see https://www.electron.build/configuration/configuration
*/
{
appId: "YourAppID",
productName: "YourAppName",
copyright: "Copyright © 2022 ${author}",
asar: false,
directories: {
output: "release/${version}",
buildResources: "electron/resources",
},
files: ["dist"],
win: {
target: [
{
target: "nsis",
arch: ["x64"],
},
],
artifactName: "${productName}-Windows-${version}-Setup.${ext}",
},
nsis: {
oneClick: false,
perMachine: false,
allowToChangeInstallationDirectory: true,
deleteAppDataOnUninstall: false,
},
mac: {
target: ["dmg"],
artifactName: "${productName}-Mac-${version}-Installer.${ext}",
},
linux: {
target: ["AppImage"],
artifactName: "${productName}-Linux-${version}.${ext}",
},
}
6 changes: 3 additions & 3 deletions playground/usecase-in-main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"main": "dist/electron/main/index.js",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build && electron-builder"
"build": "vite build && electron-builder"
},
"keywords": [],
"author": "",
"author": "草鞋没号 <[email protected]>",
"license": "ISC",
"dependencies": {
"serialport": "^10.4.0",
Expand All @@ -24,6 +24,6 @@
"node-fetch": "^3.2.8",
"vite-plugin-electron": "workspace:*",
"vite-plugin-esmodule": "^1.4.1",
"vite": "^3.0.2"
"vite": "^3.0.6"
}
}
8 changes: 8 additions & 0 deletions playground/usecase-in-main/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'
import electron from 'vite-plugin-electron'

fs.rmSync('dist', { recursive: true, force: true })

export default defineConfig({
plugins: [
electron({
Expand All @@ -10,6 +13,7 @@ export default defineConfig({
vite: {
build: {
outDir: 'dist/electron/main',
minify: false,
},
},
},
Expand All @@ -23,9 +27,13 @@ export default defineConfig({
// For debug
sourcemap: 'inline',
outDir: 'dist/electron/preload',
minify: false,
},
},
},
}),
],
build: {
minify: false,
},
})
37 changes: 37 additions & 0 deletions playground/usecase-in-renderer/electron-builder.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @see https://www.electron.build/configuration/configuration
*/
{
appId: "YourAppID",
productName: "YourAppName",
copyright: "Copyright © 2022 ${author}",
asar: false,
directories: {
output: "release/${version}",
buildResources: "electron/resources",
},
files: ["dist"],
win: {
target: [
{
target: "nsis",
arch: ["x64"],
},
],
artifactName: "${productName}-Windows-${version}-Setup.${ext}",
},
nsis: {
oneClick: false,
perMachine: false,
allowToChangeInstallationDirectory: true,
deleteAppDataOnUninstall: false,
},
mac: {
target: ["dmg"],
artifactName: "${productName}-Mac-${version}-Installer.${ext}",
},
linux: {
target: ["AppImage"],
artifactName: "${productName}-Linux-${version}.${ext}",
},
}
2 changes: 1 addition & 1 deletion playground/usecase-in-renderer/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'

export const ROOT_PATH = {
// /dist
dist: path.join(__dirname, '../..'),
dist: path.join(__dirname, '..'),
// /dist or /public
public: path.join(__dirname, app.isPackaged ? '../..' : '../../../public'),
}
Expand Down
6 changes: 3 additions & 3 deletions playground/usecase-in-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"main": "dist/electron/main.js",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build && electron-builder"
"build": "vite build && electron-builder"
},
"keywords": [],
"author": "",
"author": "草鞋没号 <[email protected]>",
"license": "ISC",
"dependencies": {
"serialport": "^10.4.0",
Expand All @@ -24,6 +24,6 @@
"node-fetch": "^3.2.8",
"vite-plugin-electron": "workspace:*",
"vite-plugin-esmodule": "^1.4.1",
"vite": "^3.0.2"
"vite": "^3.0.6"
}
}
18 changes: 17 additions & 1 deletion playground/usecase-in-renderer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'
import electron from 'vite-plugin-electron'
import esmodule from 'vite-plugin-esmodule'

fs.rmSync('dist', { recursive: true, force: true })

export default defineConfig({
plugins: [
electron({
main: {
entry: 'electron/main.ts',
vite: {
build: {
minify: false,
},
},
},
preload: {
input: path.join(__dirname, 'electron/preload.ts'),
vite: {
build: {
minify: false,
},
},
},
// Enables use of Node.js API in the Renderer-process
renderer: {
Expand All @@ -22,5 +35,8 @@ export default defineConfig({
},
}),
esmodule(['execa', 'got', 'node-fetch']),
]
],
build: {
minify: false,
},
})
Loading

0 comments on commit 4f9e897

Please sign in to comment.