mirror of
https://github.com/alex8088/electron-vite.git
synced 2025-06-29 23:19:15 +08:00
Compare commits
142 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
52abc48abf | ||
|
cbee52c8bb | ||
|
48e6f4f570 | ||
|
4071778f07 | ||
|
3fd16d0c23 | ||
|
d2e8b1271b | ||
|
28d7df6e91 | ||
|
b7763a7f77 | ||
|
1c084cc090 | ||
|
9ec164d33e | ||
|
a9197f5cc9 | ||
|
3d5c9f68a1 | ||
|
1b411d3633 | ||
|
b56d3c2d21 | ||
|
f2eff25268 | ||
|
2d8e513e07 | ||
|
d8063320dc | ||
|
f33c5b2abe | ||
|
e91e70c105 | ||
|
ea144aef19 | ||
|
987c55ee8b | ||
|
8064bd81ff | ||
|
6e8572d9b7 | ||
|
4b47ef0bd4 | ||
|
5a5af050b2 | ||
|
96ae3c5cd9 | ||
|
79ac91dee2 | ||
|
1599d730f6 | ||
|
3c6e08b2f2 | ||
|
dfe6a3e3f8 | ||
|
6c01417909 | ||
|
5ffd49eddc | ||
|
bf1220875f | ||
|
02e0dff9f4 | ||
|
0a02ace008 | ||
|
e638dcae1b | ||
|
3264abc70b | ||
|
19b42225f8 | ||
|
d9aaf24f84 | ||
|
3605aca1e8 | ||
|
73dfee5a4f | ||
|
b3185d7fc5 | ||
|
d79de5abb6 | ||
|
1838bdbf3e | ||
|
ff23f7d44d | ||
|
a48e12a9df | ||
|
1abedce6c2 | ||
|
c2c655367f | ||
|
6170705eae | ||
|
eeaa7de45c | ||
|
f42a9d370f | ||
|
08ff86f2c4 | ||
|
0ce505a12f | ||
|
ad891af811 | ||
|
27ade03acf | ||
|
52fce25787 | ||
|
19489a28c8 | ||
|
7f13ea2a84 | ||
|
932fc556f5 | ||
|
a12646f25e | ||
|
921aa9d4a7 | ||
|
694e134a52 | ||
|
40a1b64639 | ||
|
476ef54498 | ||
|
9b04362e12 | ||
|
a8f5182d25 | ||
|
0c98f33573 | ||
|
db1128089a | ||
|
0b265442a1 | ||
|
7b27e684d6 | ||
|
dbd7b0137b | ||
|
73f2562172 | ||
|
cc0df8a8cc | ||
|
93e84f6bce | ||
|
619a337c6d | ||
|
963f8aba51 | ||
|
082b1331ff | ||
|
b578f61f1c | ||
|
5de87d681b | ||
|
a7b3c65576 | ||
|
4924e36d74 | ||
|
61eb32aa04 | ||
|
c1e1ca0471 | ||
|
cb58ef8649 | ||
|
93763597fe | ||
|
dc87a798ab | ||
|
4f12196e54 | ||
|
b93a1878c1 | ||
|
8bb03f8b24 | ||
|
f951edf492 | ||
|
7c6020e11b | ||
|
4e48537b39 | ||
|
10099eced0 | ||
|
fbc45f696b | ||
|
d30d3765eb | ||
|
5c4c28ca0a | ||
|
5e31794c2d | ||
|
588b39b0b4 | ||
|
ce56ecd4dc | ||
|
5021496f74 | ||
|
8e1f9f6845 | ||
|
7369960b99 | ||
|
ac47dacc1b | ||
|
2360d502a4 | ||
|
01163866fb | ||
|
8b839872f8 | ||
|
670c23b2e1 | ||
|
566f88960e | ||
|
8a774ef76d | ||
|
27acfb7c1d | ||
|
5c440a8a76 | ||
|
ed64873434 | ||
|
254ce0b5b6 | ||
|
0c46c1064b | ||
|
6c590ad65b | ||
|
d8307e8fd4 | ||
|
532ba52714 | ||
|
8914878a53 | ||
|
d7b4ebc54a | ||
|
342a0556cd | ||
|
9d76799072 | ||
|
f0f21db904 | ||
|
11b6f3c39d | ||
|
ed13174829 | ||
|
583c318af1 | ||
|
3507149b6e | ||
|
81117c6809 | ||
|
3567f26f02 | ||
|
9f5ca0d92d | ||
|
8b445b67c5 | ||
|
c43d1832d2 | ||
|
0367f73a95 | ||
|
785b32f2b0 | ||
|
4f796e4c8a | ||
|
3def0ed84b | ||
|
b71bf82f02 | ||
|
587efabac5 | ||
|
bac8c04816 | ||
|
6dff3475b4 | ||
|
c26a9ff71c | ||
|
388b590808 | ||
|
8c924188de |
@ -1,2 +0,0 @@
|
|||||||
node_modules
|
|
||||||
dist
|
|
38
.eslintrc.js
38
.eslintrc.js
@ -1,38 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
root: true,
|
|
||||||
env: {
|
|
||||||
commonjs: true,
|
|
||||||
es6: true,
|
|
||||||
node: true
|
|
||||||
},
|
|
||||||
parser: '@typescript-eslint/parser',
|
|
||||||
parserOptions: {
|
|
||||||
sourceType: 'module',
|
|
||||||
ecmaVersion: 2021
|
|
||||||
},
|
|
||||||
plugins: ['@typescript-eslint'],
|
|
||||||
extends: [
|
|
||||||
'eslint:recommended',
|
|
||||||
'plugin:@typescript-eslint/recommended',
|
|
||||||
'plugin:@typescript-eslint/eslint-recommended',
|
|
||||||
'plugin:prettier/recommended'
|
|
||||||
],
|
|
||||||
rules: {
|
|
||||||
'no-empty': ['warn', { allowEmptyCatch: true }],
|
|
||||||
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow-with-description' }],
|
|
||||||
'@typescript-eslint/explicit-function-return-type': 'error',
|
|
||||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
||||||
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
|
|
||||||
'@typescript-eslint/no-explicit-any': 'error',
|
|
||||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
||||||
'@typescript-eslint/no-var-requires': 'off'
|
|
||||||
},
|
|
||||||
overrides: [
|
|
||||||
{
|
|
||||||
files: ['*.js'],
|
|
||||||
rules: {
|
|
||||||
'@typescript-eslint/explicit-function-return-type': 'off'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
github: alex8088
|
3
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
3
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -1,6 +1,5 @@
|
|||||||
name: "\U0001F41E Bug Report"
|
name: "\U0001F41E Bug Report"
|
||||||
description: Report an issue with electron-vite
|
description: Report an issue with electron-vite
|
||||||
labels: ['bug', 'triage']
|
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
@ -45,7 +44,7 @@ body:
|
|||||||
required: true
|
required: true
|
||||||
- label: Read the [Contributing Guidelines](https://github.com/alex8088/electron-vite/blob/master/CONTRIBUTING.md).
|
- label: Read the [Contributing Guidelines](https://github.com/alex8088/electron-vite/blob/master/CONTRIBUTING.md).
|
||||||
required: true
|
required: true
|
||||||
- label: Read the [docs](https://evite.netlify.app).
|
- label: Read the [docs](https://electron-vite.org).
|
||||||
required: true
|
required: true
|
||||||
- label: Check that there isn't [already an issue](https://github.com/alex8088/electron-vite/issues) that reports the same bug to avoid creating a duplicate.
|
- label: Check that there isn't [already an issue](https://github.com/alex8088/electron-vite/issues) that reports the same bug to avoid creating a duplicate.
|
||||||
required: true
|
required: true
|
||||||
|
4
.github/ISSUE_TEMPLATE/config.yml
vendored
4
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1 +1,5 @@
|
|||||||
blank_issues_enabled: false
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Questions & Discussions
|
||||||
|
url: https://github.com/alex8088/electron-vite/discussions
|
||||||
|
about: Use GitHub discussions for message-board style questions and discussions.
|
||||||
|
4
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
4
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@ -40,7 +40,7 @@ body:
|
|||||||
required: true
|
required: true
|
||||||
- label: Read the [Contributing Guidelines](https://github.com/alex8088/electron-vite/blob/master/CONTRIBUTING.md).
|
- label: Read the [Contributing Guidelines](https://github.com/alex8088/electron-vite/blob/master/CONTRIBUTING.md).
|
||||||
required: true
|
required: true
|
||||||
- label: Read the [docs](https://evite.netlify.app).
|
- label: Read the [docs](https://electron-vite.org).
|
||||||
required: true
|
required: true
|
||||||
- label: Check that there isn't [already an issue](https://github.com/alex8088/electron-vite/issues) that reports the same bug to avoid creating a duplicate.
|
- label: Check that there isn't [already an issue](https://github.com/alex8088/electron-vite/issues) that requests the same feature to avoid creating a duplicate.
|
||||||
required: true
|
required: true
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
|
.DS_Store
|
||||||
|
.eslintcache
|
||||||
*.log*
|
*.log*
|
||||||
|
11
.vscode/settings.json
vendored
Normal file
11
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"[typescript]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
|
},
|
||||||
|
"[javascript]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
|
},
|
||||||
|
"[json]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
|
}
|
||||||
|
}
|
179
CHANGELOG.md
179
CHANGELOG.md
@ -1,3 +1,182 @@
|
|||||||
|
### v4.0.0-beta.0 (_2025-06-28_)
|
||||||
|
|
||||||
|
- refactor!: bump required node version to 20.19+, 22.12+
|
||||||
|
- fix(deps)!: update Vite to v7 and remove cjs build
|
||||||
|
- fix: use `import type` for type-only imports
|
||||||
|
- perf: build compatibility target for Electron 36 ([#766](https://github.com/alex8088/electron-vite/pull/766))
|
||||||
|
- perf: build compatibility target for Electron 37
|
||||||
|
- chore(deps): update pnpm to v10
|
||||||
|
- chore(deps): update all non-major dependencies
|
||||||
|
- chore(deps): update lint-staged to v16
|
||||||
|
|
||||||
|
### v3.1.0 (_2025-03-25_)
|
||||||
|
|
||||||
|
- fix(bytecodePlugin): optimize 'use strict' directive replacement ([#681](https://github.com/alex8088/electron-vite/issues/681))
|
||||||
|
- perf: build compatilibity target for Electron 35 ([#729](https://github.com/alex8088/electron-vite/pull/729))
|
||||||
|
- chore(deps): update all non-major dependencies
|
||||||
|
- chore(deps): update globals to v16
|
||||||
|
- chore(deps): update esbuild to v0.25
|
||||||
|
|
||||||
|
### v3.1.0-beta.0 (_2025-03-12_)
|
||||||
|
|
||||||
|
See [v3.1.0-beta.0 changelog](https://github.com/alex8088/electron-vite/blob/v3.1.0-beta.0/CHANGELOG.md)
|
||||||
|
|
||||||
|
### v3.0.0 (_2025-02-16_)
|
||||||
|
|
||||||
|
- feat: resolve conditions for preload
|
||||||
|
- perf: build compatilibity target for Electron 32
|
||||||
|
- perf: build compatilibity target for Electron 33 ([#651](https://github.com/alex8088/electron-vite/pull/651))
|
||||||
|
- perf: build compatilibity target for Electron 34
|
||||||
|
- chore: move to eslint flat config
|
||||||
|
- chore(deps): update all non-major dependencies
|
||||||
|
- chore(deps): update @rollup/plugin-node-resolve to v16
|
||||||
|
- chore(deps): update @rollup/plugin-typescript to v12
|
||||||
|
- chore(deps): update esbuild to v0.24
|
||||||
|
- chore(deps): update vite to v6
|
||||||
|
- chore(deps): update @type/node to v22
|
||||||
|
|
||||||
|
### v3.0.0-beta.0 (_2025-01-22_)
|
||||||
|
|
||||||
|
See [v3.0.0-beta.0 changelog](https://github.com/alex8088/electron-vite/blob/v3.0.0-beta.0/CHANGELOG.md)
|
||||||
|
|
||||||
|
### v2.3.0 (_2024-06-23_)
|
||||||
|
|
||||||
|
- feat: resolve import.meta.\[dirname|filename\] to support CommonJS format
|
||||||
|
- fix: don't handle module ID that begin with \0 ([#530](https://github.com/alex8088/electron-vite/pull/530))
|
||||||
|
- fix: not using the mode from the config file ([#539](https://github.com/alex8088/electron-vite/pull/539))
|
||||||
|
- fix: default mode should not overrite user config mode
|
||||||
|
- perf: build compatilibity target for Electron 31
|
||||||
|
- perf: improve cjs shim
|
||||||
|
- chore(deps): update all non-major dependencies
|
||||||
|
- chore(deps): update @typescript-eslint/\* to v7
|
||||||
|
- chore(deps): update esbuild to v0.21
|
||||||
|
|
||||||
|
### v2.2.0 (_2024-04-21_)
|
||||||
|
|
||||||
|
- feat: export mergeConfig from vite ([#471](https://github.com/alex8088/electron-vite/issues/471))
|
||||||
|
- fix(types): narrow down the return type of defineConfig
|
||||||
|
- perf: build compatilibity target for Electron 30
|
||||||
|
- refactor(config): defineConfig types
|
||||||
|
- chore: fix camelcase typo
|
||||||
|
- chore: use rollup-plugin-rm to clean dist
|
||||||
|
|
||||||
|
### v2.1.0 (_2024-03-03_)
|
||||||
|
|
||||||
|
- feat: easy way to fork processes and use workers
|
||||||
|
- fix: config via build.lib fails when default entry point not found ([#393](https://github.com/alex8088/electron-vite/issues/393))
|
||||||
|
- perf: build compatilibity target for Electron 29
|
||||||
|
- perf: allow integrating more complex render solutions ([#412](https://github.com/alex8088/electron-vite/pull/412))
|
||||||
|
- perf(bytecodePlugin): warn that strings cannot be protected when minification is enabled ([#417](https://github.com/alex8088/electron-vite/issues/417))
|
||||||
|
|
||||||
|
### v2.0.0 (_2024-01-09_)
|
||||||
|
|
||||||
|
- feat: bump minimum node version to 18
|
||||||
|
- feat: migrate to ESM
|
||||||
|
- feat: support vite 5
|
||||||
|
- feat: add package.json to export map
|
||||||
|
- feat: support ESM in Electron
|
||||||
|
- feat: env variables prefixed with VITE\_ will be shared in main process and renderer
|
||||||
|
- feat: support for passing arguments to electron in dev and preview commands ([#339](https://github.com/alex8088/electron-vite/pull/339))
|
||||||
|
- feat: config file supports "type": "module" in package.json
|
||||||
|
- fix: emit assets when ssr is enabled
|
||||||
|
- fix: externalizeDepPlugin not work
|
||||||
|
- fix: electron's export subpaths also need to be externalized ([#372](https://github.com/alex8088/electron-vite/issues/372))
|
||||||
|
- perf: improve package.json resolve
|
||||||
|
- perf: use magic-string hires boundary for sourcemaps
|
||||||
|
- perf: build compatilibity target for Electron 28
|
||||||
|
- pref: resolve import meta url in CommonJS format
|
||||||
|
- perf(worker): ESM syntax
|
||||||
|
- perf: package version
|
||||||
|
- perf: dev error message
|
||||||
|
- perf(externalizeDepsPlugin): use cached package data to improve performance
|
||||||
|
- perf: loadEnv api also needs to load shared env variables prefixed with VITE\_
|
||||||
|
- refactor: build
|
||||||
|
- refactor: file hashes use url-safe base64 encoded hashes in vite 5 (rollup 4)
|
||||||
|
- refactor: remove Electron 11, 12 build compatilibity target
|
||||||
|
- refactor: use dynamic import directly
|
||||||
|
- build: use rollup-plugin-dts
|
||||||
|
- chore(deps): update all non-major dependencies
|
||||||
|
- chore(deps): update lint-staged to v15
|
||||||
|
- chore(deps): update eslint-config-prettier to v9
|
||||||
|
- chore(deps): update @rollup/plugin-typescript to v11
|
||||||
|
- chore(deps): update rollup to v4
|
||||||
|
- chore(deps): update vite to v5
|
||||||
|
- chore(deps): update esbuild to v0.19
|
||||||
|
- chore(deps): update typescript to 5.3.3
|
||||||
|
- chore: improve prettier config
|
||||||
|
- chore: update homepage
|
||||||
|
|
||||||
|
### v2.0.0-beta.4 (_2024-01-06_)
|
||||||
|
|
||||||
|
See [v2.0.0-beta.4 changelog](https://github.com/alex8088/electron-vite/blob/v2.0.0-beta.4/CHANGELOG.md)
|
||||||
|
|
||||||
|
### v2.0.0-beta.3 (_2024-01-04_)
|
||||||
|
|
||||||
|
See [v2.0.0-beta.3 changelog](https://github.com/alex8088/electron-vite/blob/v2.0.0-beta.3/CHANGELOG.md)
|
||||||
|
|
||||||
|
### v2.0.0-beta.2 (_2023-12-19_)
|
||||||
|
|
||||||
|
See [v2.0.0-beta.2 changelog](https://github.com/alex8088/electron-vite/blob/v2.0.0-beta.2/CHANGELOG.md)
|
||||||
|
|
||||||
|
### v2.0.0-beta.1 (_2023-12-14_)
|
||||||
|
|
||||||
|
See [v2.0.0-beta.1 changelog](https://github.com/alex8088/electron-vite/blob/v2.0.0-beta.1/CHANGELOG.md)
|
||||||
|
|
||||||
|
### v2.0.0-beta.0 (_2023-12-13_)
|
||||||
|
|
||||||
|
See [v2.0.0-beta.0 changelog](https://github.com/alex8088/electron-vite/blob/v2.0.0-beta.0/CHANGELOG.md)
|
||||||
|
|
||||||
|
### v1.0.29 (_2023-11-17_)
|
||||||
|
|
||||||
|
- feat(cli): support --noSandbox option for dev and preview command
|
||||||
|
- perf: build compatilibity target for Electron 27
|
||||||
|
|
||||||
|
### v1.0.28 (_2023-09-18_)
|
||||||
|
|
||||||
|
- feat(cli): supports specifying electron entry file ([#270](https://github.com/alex8088/electron-vite/issues/270))
|
||||||
|
- fix(externalizeDepsPlugin): supports subpath
|
||||||
|
- perf: build compatilibity target for Electron 26
|
||||||
|
- chore(types): add .json?commonjs-external&asset typing
|
||||||
|
|
||||||
|
### v1.0.27 (_2023-08-01_)
|
||||||
|
|
||||||
|
- chore: remove preinstall script
|
||||||
|
|
||||||
|
### v1.0.26 (_2023-07-30_)
|
||||||
|
|
||||||
|
- feat(cli): add CLI `--inspect[-brk]` to support debugging without IDEs ([#231](https://github.com/alex8088/electron-vite/issues/231))
|
||||||
|
- feat(types): add process.env.ELECTRON_RENDERER_URL type
|
||||||
|
- feat(types): add Vite importMeta types
|
||||||
|
- perf: spawn Electron process using parent's stdios ([#236](https://github.com/alex8088/electron-vite/issues/236))
|
||||||
|
- chore: update user config interface jsdoc
|
||||||
|
- chore(deps): update pnpm to v8
|
||||||
|
- chore(deps): update prettier to v3
|
||||||
|
- chore(deps): update @typescript-eslint/\* to v6
|
||||||
|
|
||||||
|
### v1.0.25 (_2023-07-11_)
|
||||||
|
|
||||||
|
- fix: remove node resolve condition for preload [#204](https://github.com/alex8088/electron-vite/issues/204)
|
||||||
|
- fix(asset): asset handling error when hot reloading
|
||||||
|
- chore(deps): update all non-major dependencies
|
||||||
|
- chore(deps): update fs-extra to v11
|
||||||
|
- chore(deps): update @types/node to v18
|
||||||
|
- chore(deps): update typescript to 5.0.4
|
||||||
|
- chore(deps): update vite to 4.4.2
|
||||||
|
- chore(deps): update esbuild to v0.18
|
||||||
|
- chore(deps): update rollup to 3.26.2
|
||||||
|
|
||||||
|
### v1.0.24 (_2023-06-25_)
|
||||||
|
|
||||||
|
- fix(bytecodePlugin): bytecode loader relative path is incorrect
|
||||||
|
- perf: ignore `browser` field and additional `node` condition for main config
|
||||||
|
|
||||||
|
### v1.0.23 (_2023-06-04_)
|
||||||
|
|
||||||
|
- feat: supports ES build target for renderer [#174](https://github.com/alex8088/electron-vite/issues/174)
|
||||||
|
- revert: chore: remove process env define [#159](https://github.com/alex8088/electron-vite/issues/174)
|
||||||
|
- perf: build compatilibity target for Electron 25
|
||||||
|
- chore(deps): update all non-major dependencies
|
||||||
|
|
||||||
### v1.0.22 (_2023-04-23_)
|
### v1.0.22 (_2023-04-23_)
|
||||||
|
|
||||||
- feat(cli): add --rendererOnly flag to dev command
|
- feat(cli): add --rendererOnly flag to dev command
|
||||||
|
115
README.md
115
README.md
@ -9,17 +9,17 @@
|
|||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://img.shields.io/npm/v/electron-vite?color=6988e6&label=version">
|
<img src="https://img.shields.io/npm/v/electron-vite?color=6988e6&label=version">
|
||||||
<img src="https://img.shields.io/github/license/alex8088/wx-vue-next?color=blue" alt="license" />
|
<img src="https://img.shields.io/github/license/alex8088/electron-vite?color=blue" alt="license" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://evite.netlify.app/">Documentation</a> |
|
<a href="https://electron-vite.org">Documentation</a> |
|
||||||
<a href="https://evite.netlify.app/guide/">Getting Started</a> |
|
<a href="https://electron-vite.org/guide">Getting Started</a> |
|
||||||
<a href="https://github.com/alex8088/quick-start/tree/master/packages/create-electron">create-electron</a>
|
<a href="https://github.com/alex8088/quick-start/tree/master/packages/create-electron">create-electron</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://cn-evite.netlify.app/">中文文档</a>
|
<a href="https://cn.electron-vite.org">中文文档</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
@ -28,15 +28,13 @@
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
- ⚡️ [Vite](https://vitejs.dev) powered and use the same way.
|
- ⚡️ [Vite](https://vitejs.dev) powered and use the same way.
|
||||||
- 🛠 Centralized Configuration.
|
- 🛠 Pre-configured for Electron, don't worry about configuration.
|
||||||
- 💡 Pre-configured for Electron, don't worry about configuration.
|
- 💡 Optimize asset handling (Node.js addons, WebAssembly, Worker Thread, etc).
|
||||||
- 🚀 Fast HMR for renderers.
|
- 🚀 Fast HMR for renderer processes.
|
||||||
- 🔥 Hot reloading for main process and preload scripts.
|
- 🔥 Hot reloading for main process and preload scripts.
|
||||||
- 🔌 Easy to debug.
|
- 🔌 Easy to debug in IDEs like VSCode or WebStorm.
|
||||||
- 🔋 Static asset handling (Node.js addons, WebAssembly, etc).
|
|
||||||
- 🔒 Compile to v8 bytecode to protect source code.
|
- 🔒 Compile to v8 bytecode to protect source code.
|
||||||
- 🏷️ Support for TypeScript decorators.
|
- 🏷️ Support for TypeScript decorators.
|
||||||
- 🔩 Easy to use workers and fork process.
|
|
||||||
- 📦 Out-of-the-box support for TypeScript, Vue, React, Svelte, SolidJS and more.
|
- 📦 Out-of-the-box support for TypeScript, Vue, React, Svelte, SolidJS and more.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -61,7 +59,7 @@ In a project where `electron-vite` is installed, you can use `electron-vite` bin
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configuring
|
### Configuration
|
||||||
|
|
||||||
When running `electron-vite` from the command line, electron-vite will automatically try to resolve a config file named `electron.vite.config.js` inside project root. The most basic config file looks like this:
|
When running `electron-vite` from the command line, electron-vite will automatically try to resolve a config file named `electron.vite.config.js` inside project root. The most basic config file looks like this:
|
||||||
|
|
||||||
@ -80,97 +78,24 @@ export default {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Use HMR in Renderer
|
|
||||||
|
|
||||||
In order to use the renderer process HMR, you need to use the `environment variables` to determine whether the window browser loads a local html file or a local URL.
|
|
||||||
|
|
||||||
```js
|
|
||||||
function createWindow() {
|
|
||||||
// Create the browser window
|
|
||||||
const mainWindow = new BrowserWindow({
|
|
||||||
width: 800,
|
|
||||||
height: 600,
|
|
||||||
webPreferences: {
|
|
||||||
preload: path.join(__dirname, '../preload/index.js')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Load the remote URL for development or the local html file for production
|
|
||||||
if (!app.isPackaged && process.env['ELECTRON_RENDERER_URL']) {
|
|
||||||
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
|
||||||
} else {
|
|
||||||
mainWindow.loadFile(path.join(__dirname, '../renderer/index.html'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Hot Reloading
|
|
||||||
|
|
||||||
Hot reloading refers to quickly rebuilding and restarting the Electron app when the main process or preload scripts module changes. In fact, it's not really hot reloading, but similar. It also brings a good development experience to developers.
|
|
||||||
|
|
||||||
There are two ways to enable it:
|
|
||||||
|
|
||||||
1. Use CLI option `-w` or `--watch`, e.g. `electron-vite dev --watch`. This is the preferred way, it's more flexible.
|
|
||||||
|
|
||||||
2. Use configuration option `build.watch` and set to `{}`. In addition, more watcher options can be configured, see [WatcherOptions](https://rollupjs.org/guide/en/#watch-options).
|
|
||||||
|
|
||||||
### Debugging in VSCode
|
|
||||||
|
|
||||||
Add a file `.vscode/launch.json` with the following configuration:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Debug Main Process",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite",
|
|
||||||
"windows": {
|
|
||||||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite.cmd"
|
|
||||||
},
|
|
||||||
"runtimeArgs": ["--sourcemap"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, set some breakpoints in `main.ts` (source code), and start debugging in the `VSCode Debug View`.
|
|
||||||
|
|
||||||
### Source Code Protection
|
|
||||||
|
|
||||||
Use the plugin `bytecodePlugin` to enable it:
|
|
||||||
|
|
||||||
```js
|
|
||||||
import { defineConfig, bytecodePlugin } from 'electron-vite'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
main: {
|
|
||||||
plugins: [bytecodePlugin()]
|
|
||||||
},
|
|
||||||
preload: {
|
|
||||||
plugins: [bytecodePlugin()]
|
|
||||||
},
|
|
||||||
renderer: {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
`bytecodePlugin` only works in production and supports the main process and preload scripts.
|
|
||||||
|
|
||||||
Also, you can learn more by playing with the [example](https://github.com/alex8088/electron-vite-bytecode-example).
|
|
||||||
|
|
||||||
### Getting Started
|
### Getting Started
|
||||||
|
|
||||||
Clone the [electron-vite-boilerplate](https://github.com/alex8088/electron-vite-boilerplate) or use the [create-electron](https://github.com/alex8088/quick-start/tree/master/packages/create-electron) tool to scaffold your project.
|
Clone the [electron-vite-boilerplate](https://github.com/alex8088/electron-vite-boilerplate) or use the [create-electron](https://github.com/alex8088/quick-start/tree/master/packages/create-electron) tool to scaffold your project.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm init @quick-start/electron
|
npm create @quick-start/electron
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Currently supported template presets include:
|
||||||
|
|
||||||
|
| JavaScript | TypeScript |
|
||||||
|
| :--------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------: |
|
||||||
|
| [vanilla](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/vanilla) | [vanilla-ts](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/vanilla-ts) |
|
||||||
|
| [vue](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/vue) | [vue-ts](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/vue-ts) |
|
||||||
|
| [react](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/react) | [react-ts](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/react-ts) |
|
||||||
|
| [svelte](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/svelte) | [svelte-ts](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/svelte-ts) |
|
||||||
|
| [solid](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/solid) | [solid-ts](https://github.com/alex8088/quick-start/tree/master/packages/create-electron/playground/solid-ts) |
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
See [Contributing Guide](CONTRIBUTING.md).
|
See [Contributing Guide](CONTRIBUTING.md).
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
||||||
|
|
||||||
"mainEntryPointFilePath": "./dist/types/index.d.ts",
|
|
||||||
|
|
||||||
"dtsRollup": {
|
|
||||||
"enabled": true,
|
|
||||||
"untrimmedFilePath": "",
|
|
||||||
"publicTrimmedFilePath": "./dist/index.d.ts"
|
|
||||||
},
|
|
||||||
|
|
||||||
"apiReport": {
|
|
||||||
"enabled": false
|
|
||||||
},
|
|
||||||
|
|
||||||
"docModel": {
|
|
||||||
"enabled": false
|
|
||||||
},
|
|
||||||
|
|
||||||
"tsdocMetadata": {
|
|
||||||
"enabled": false
|
|
||||||
},
|
|
||||||
|
|
||||||
"messages": {
|
|
||||||
"compilerMessageReporting": {
|
|
||||||
"default": {
|
|
||||||
"logLevel": "warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
"extractorMessageReporting": {
|
|
||||||
"default": {
|
|
||||||
"logLevel": "warning",
|
|
||||||
"addToApiReportFile": true
|
|
||||||
},
|
|
||||||
|
|
||||||
"ae-missing-release-tag": {
|
|
||||||
"logLevel": "none"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
"tsdocMessageReporting": {
|
|
||||||
"default": {
|
|
||||||
"logLevel": "warning"
|
|
||||||
},
|
|
||||||
|
|
||||||
"tsdoc-undefined-tag": {
|
|
||||||
"logLevel": "none"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,7 +24,7 @@ if (debugIndex > 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
require('../dist/cli')
|
import('../dist/cli.js')
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
64
eslint.config.js
Normal file
64
eslint.config.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// ts-check
|
||||||
|
|
||||||
|
import eslint from '@eslint/js'
|
||||||
|
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
|
||||||
|
import globals from 'globals'
|
||||||
|
import tseslint from 'typescript-eslint'
|
||||||
|
|
||||||
|
export default tseslint.config(
|
||||||
|
{ ignores: ['**/node_modules', '**/dist', '**/bin'] },
|
||||||
|
eslint.configs.recommended,
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
eslintPluginPrettierRecommended,
|
||||||
|
{
|
||||||
|
languageOptions: {
|
||||||
|
parser: tseslint.parser,
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'module',
|
||||||
|
ecmaVersion: 2022
|
||||||
|
},
|
||||||
|
globals: {
|
||||||
|
...globals.es2021,
|
||||||
|
...globals.node
|
||||||
|
}
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
node: {
|
||||||
|
version: '^20.19.0 || >=22.12.0'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'prettier/prettier': 'warn',
|
||||||
|
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow-with-description' }],
|
||||||
|
'@typescript-eslint/explicit-function-return-type': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
allowExpressions: true,
|
||||||
|
allowTypedFunctionExpressions: true,
|
||||||
|
allowHigherOrderFunctions: true,
|
||||||
|
allowIIFEs: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||||
|
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
|
||||||
|
'@typescript-eslint/no-empty-object-type': ['error', { allowInterfaces: 'always' }],
|
||||||
|
'@typescript-eslint/no-explicit-any': 'error',
|
||||||
|
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||||
|
'@typescript-eslint/no-require-imports': 'error',
|
||||||
|
'@typescript-eslint/no-unused-expressions': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
allowShortCircuit: true,
|
||||||
|
allowTaggedTemplates: true,
|
||||||
|
allowTernary: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['*.js', '*.mjs'],
|
||||||
|
rules: {
|
||||||
|
'@typescript-eslint/explicit-function-return-type': 'off'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
83
node.d.ts
vendored
83
node.d.ts
vendored
@ -4,6 +4,12 @@ declare module '*?nodeWorker' {
|
|||||||
export default function (options: WorkerOptions): Worker
|
export default function (options: WorkerOptions): Worker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// module path
|
||||||
|
declare module '*?modulePath' {
|
||||||
|
const src: string
|
||||||
|
export default src
|
||||||
|
}
|
||||||
|
|
||||||
// node asset
|
// node asset
|
||||||
declare module '*?asset' {
|
declare module '*?asset' {
|
||||||
const src: string
|
const src: string
|
||||||
@ -15,6 +21,11 @@ declare module '*?asset&asarUnpack' {
|
|||||||
export default src
|
export default src
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module '*.json?commonjs-external&asset' {
|
||||||
|
const src: string
|
||||||
|
export default src
|
||||||
|
}
|
||||||
|
|
||||||
// native node module
|
// native node module
|
||||||
declare module '*.node' {
|
declare module '*.node' {
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
@ -27,3 +38,75 @@ declare module '*.wasm?loader' {
|
|||||||
const loadWasm: (options?: WebAssembly.Imports) => Promise<WebAssembly.Instance>
|
const loadWasm: (options?: WebAssembly.Imports) => Promise<WebAssembly.Instance>
|
||||||
export default loadWasm
|
export default loadWasm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build-in process env
|
||||||
|
declare namespace NodeJS {
|
||||||
|
interface ProcessEnv {
|
||||||
|
/**
|
||||||
|
* Vite's dev server address for Electron renderers.
|
||||||
|
*/
|
||||||
|
readonly ELECTRON_RENDERER_URL?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refer to Vite's ImportMeta type declarations
|
||||||
|
// <https://github.com/vitejs/vite/blob/main/packages/vite/types/importMeta.d.ts>
|
||||||
|
|
||||||
|
interface ImportMetaEnv {
|
||||||
|
MODE: string
|
||||||
|
DEV: boolean
|
||||||
|
PROD: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportGlobOptions<Eager extends boolean, AsType extends string> {
|
||||||
|
/**
|
||||||
|
* Import type for the import url.
|
||||||
|
*/
|
||||||
|
as?: AsType
|
||||||
|
/**
|
||||||
|
* Import as static or dynamic
|
||||||
|
*
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
eager?: Eager
|
||||||
|
/**
|
||||||
|
* Import only the specific named export. Set to `default` to import the default export.
|
||||||
|
*/
|
||||||
|
import?: string
|
||||||
|
/**
|
||||||
|
* Custom queries
|
||||||
|
*/
|
||||||
|
query?: string | Record<string, string | number | boolean>
|
||||||
|
/**
|
||||||
|
* Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
|
||||||
|
*
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
exhaustive?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KnownAsTypeMap {
|
||||||
|
raw: string
|
||||||
|
url: string
|
||||||
|
worker: Worker
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportGlobFunction {
|
||||||
|
/**
|
||||||
|
* Import a list of files with a glob pattern.
|
||||||
|
*
|
||||||
|
* https://vitejs.dev/guide/features.html#glob-import
|
||||||
|
*/
|
||||||
|
<Eager extends boolean, As extends string, T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown>(
|
||||||
|
glob: string | string[],
|
||||||
|
options?: ImportGlobOptions<Eager, As>
|
||||||
|
): (Eager extends true ? true : false) extends true ? Record<string, T> : Record<string, () => Promise<T>>
|
||||||
|
<M>(glob: string | string[], options?: ImportGlobOptions<false, string>): Record<string, () => Promise<M>>
|
||||||
|
<M>(glob: string | string[], options: ImportGlobOptions<true, string>): Record<string, M>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportMeta {
|
||||||
|
url: string
|
||||||
|
readonly env: ImportMetaEnv
|
||||||
|
glob: ImportGlobFunction
|
||||||
|
}
|
||||||
|
80
package.json
80
package.json
@ -1,9 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "electron-vite",
|
"name": "electron-vite",
|
||||||
"version": "1.0.22",
|
"version": "4.0.0-beta.0",
|
||||||
"description": "Electron build tooling based on Vite",
|
"description": "Electron build tooling based on Vite",
|
||||||
"main": "dist/index.js",
|
"type": "module",
|
||||||
"types": "dist/index.d.ts",
|
"main": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": "./dist/index.js",
|
||||||
|
"./node": {
|
||||||
|
"types": "./node.d.ts"
|
||||||
|
},
|
||||||
|
"./package.json": "./package.json"
|
||||||
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"electron-vite": "bin/electron-vite.js"
|
"electron-vite": "bin/electron-vite.js"
|
||||||
},
|
},
|
||||||
@ -13,8 +21,9 @@
|
|||||||
"node.d.ts"
|
"node.d.ts"
|
||||||
],
|
],
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^14.18.0 || >=16.0.0"
|
"node": "^20.19.0 || >=22.12.0"
|
||||||
},
|
},
|
||||||
|
"packageManager": "pnpm@10.12.4",
|
||||||
"author": "Alex Wei<https://github.com/alex8088>",
|
"author": "Alex Wei<https://github.com/alex8088>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -24,7 +33,7 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/alex8088/electron-vite/issues"
|
"url": "https://github.com/alex8088/electron-vite/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/alex8088/electron-vite#readme",
|
"homepage": "https://electron-vite.org",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"electron",
|
"electron",
|
||||||
"vite",
|
"vite",
|
||||||
@ -33,9 +42,9 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"lint": "eslint --ext .ts src/**",
|
"lint": "eslint --cache .",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"build": "npm run lint && node scripts/build.js"
|
"build": "pnpm run lint && rollup -c rollup.config.ts --configPlugin typescript"
|
||||||
},
|
},
|
||||||
"simple-git-hooks": {
|
"simple-git-hooks": {
|
||||||
"pre-commit": "npx lint-staged",
|
"pre-commit": "npx lint-staged",
|
||||||
@ -52,7 +61,7 @@
|
|||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@swc/core": "^1.0.0",
|
"@swc/core": "^1.0.0",
|
||||||
"vite": "^3.0.0 || ^4.0.0"
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@swc/core": {
|
"@swc/core": {
|
||||||
@ -60,31 +69,40 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@microsoft/api-extractor": "^7.34.4",
|
"@eslint/js": "^9.29.0",
|
||||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
"@rollup/plugin-json": "^6.1.0",
|
||||||
"@rollup/plugin-typescript": "^9.0.2",
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||||
"@swc/core": "^1.3.37",
|
"@rollup/plugin-typescript": "^12.1.3",
|
||||||
"@types/node": "16.18.3",
|
"@swc/core": "^1.12.7",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
"@types/node": "^22.15.33",
|
||||||
"@typescript-eslint/parser": "^5.54.0",
|
"eslint": "^9.29.0",
|
||||||
"eslint": "^8.35.0",
|
"eslint-config-prettier": "^10.1.5",
|
||||||
"eslint-config-prettier": "^8.6.0",
|
"eslint-plugin-prettier": "^5.5.1",
|
||||||
"eslint-plugin-prettier": "^4.2.1",
|
"globals": "^16.2.0",
|
||||||
"fs-extra": "^10.1.0",
|
"lint-staged": "^16.1.2",
|
||||||
"lint-staged": "^13.1.2",
|
"prettier": "^3.6.2",
|
||||||
"prettier": "^2.8.4",
|
"rollup": "^4.44.1",
|
||||||
"rollup": "^3.18.0",
|
"rollup-plugin-dts": "^6.2.1",
|
||||||
"simple-git-hooks": "^2.8.1",
|
"rollup-plugin-rm": "^1.0.2",
|
||||||
"tslib": "^2.5.0",
|
"simple-git-hooks": "^2.13.0",
|
||||||
"typescript": "^4.8.4",
|
"tslib": "^2.8.1",
|
||||||
"vite": "^4.2.1"
|
"typescript": "^5.8.3",
|
||||||
|
"typescript-eslint": "^8.35.0",
|
||||||
|
"vite": "^7.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "^7.21.0",
|
"@babel/core": "^7.27.7",
|
||||||
"@babel/plugin-transform-arrow-functions": "^7.20.7",
|
"@babel/plugin-transform-arrow-functions": "^7.27.1",
|
||||||
"cac": "^6.7.14",
|
"cac": "^6.7.14",
|
||||||
"esbuild": "^0.17.13",
|
"esbuild": "^0.25.5",
|
||||||
"magic-string": "^0.30.0",
|
"magic-string": "^0.30.17",
|
||||||
"picocolors": "^1.0.0"
|
"picocolors": "^1.1.1"
|
||||||
|
},
|
||||||
|
"pnpm": {
|
||||||
|
"onlyBuiltDependencies": [
|
||||||
|
"@swc/core",
|
||||||
|
"esbuild",
|
||||||
|
"simple-git-hooks"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4072
pnpm-lock.yaml
generated
4072
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
41
rollup.config.ts
Normal file
41
rollup.config.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { createRequire } from 'node:module'
|
||||||
|
import { defineConfig } from 'rollup'
|
||||||
|
import ts from '@rollup/plugin-typescript'
|
||||||
|
import resolve from '@rollup/plugin-node-resolve'
|
||||||
|
import json from '@rollup/plugin-json'
|
||||||
|
import dts from 'rollup-plugin-dts'
|
||||||
|
import rm from 'rollup-plugin-rm'
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url)
|
||||||
|
const pkg = require('./package.json')
|
||||||
|
|
||||||
|
const external = ['esbuild', ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
{
|
||||||
|
input: ['src/index.ts', 'src/cli.ts'],
|
||||||
|
output: [
|
||||||
|
{
|
||||||
|
dir: 'dist',
|
||||||
|
entryFileNames: '[name].js',
|
||||||
|
chunkFileNames: 'chunks/lib-[hash].js',
|
||||||
|
format: 'es'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
external,
|
||||||
|
plugins: [
|
||||||
|
rm('dist', 'buildStart'),
|
||||||
|
json(),
|
||||||
|
ts({ compilerOptions: { rootDir: 'src', declaration: true, declarationDir: 'dist/types' } }),
|
||||||
|
resolve()
|
||||||
|
],
|
||||||
|
treeshake: {
|
||||||
|
moduleSideEffects: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'dist/types/index.d.ts',
|
||||||
|
output: [{ file: pkg.types, format: 'es' }],
|
||||||
|
plugins: [dts(), rm('dist/types', 'buildEnd')]
|
||||||
|
}
|
||||||
|
])
|
@ -1,67 +0,0 @@
|
|||||||
const path = require('path')
|
|
||||||
const colors = require('picocolors')
|
|
||||||
const fs = require('fs-extra')
|
|
||||||
const rollup = require('rollup')
|
|
||||||
const typescript = require('@rollup/plugin-typescript')
|
|
||||||
const { nodeResolve } = require('@rollup/plugin-node-resolve')
|
|
||||||
const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor')
|
|
||||||
|
|
||||||
;(async () => {
|
|
||||||
const dist = path.resolve(__dirname, '../dist')
|
|
||||||
|
|
||||||
await fs.remove(dist)
|
|
||||||
|
|
||||||
console.log()
|
|
||||||
console.log(colors.bold(colors.yellow(`Rolling up ts code...`)))
|
|
||||||
|
|
||||||
const pkg = require('../package.json')
|
|
||||||
|
|
||||||
const external = ['esbuild', ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]
|
|
||||||
|
|
||||||
const bundle = await rollup.rollup({
|
|
||||||
input: {
|
|
||||||
index: path.resolve(__dirname, '../src/index.ts'),
|
|
||||||
cli: path.resolve(__dirname, '../src/cli.ts')
|
|
||||||
},
|
|
||||||
external,
|
|
||||||
plugins: [
|
|
||||||
typescript({
|
|
||||||
tsconfig: path.resolve(__dirname, '../tsconfig.json')
|
|
||||||
}),
|
|
||||||
nodeResolve()
|
|
||||||
],
|
|
||||||
treeshake: {
|
|
||||||
moduleSideEffects: false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
await bundle.write({
|
|
||||||
dir: dist,
|
|
||||||
entryFileNames: '[name].js',
|
|
||||||
chunkFileNames: 'chunks/lib-[hash].js',
|
|
||||||
format: 'cjs'
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log(colors.bold(colors.yellow(`Rolling up type definitions...`)))
|
|
||||||
|
|
||||||
if (pkg.types) {
|
|
||||||
const extractorConfig = ExtractorConfig.loadFileAndPrepare(path.resolve(__dirname, '../api-extractor.json'))
|
|
||||||
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
||||||
localBuild: true,
|
|
||||||
showVerboseMessages: true
|
|
||||||
})
|
|
||||||
|
|
||||||
if (extractorResult.succeeded) {
|
|
||||||
console.log(colors.green('API Extractor completed successfully'))
|
|
||||||
} else {
|
|
||||||
console.error(
|
|
||||||
`API Extractor completed with ${extractorResult.errorCount} errors` +
|
|
||||||
` and ${extractorResult.warningCount} warnings`
|
|
||||||
)
|
|
||||||
process.exitCode = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.remove(path.resolve(dist, 'types'))
|
|
||||||
|
|
||||||
console.log(colors.green(`Build ${pkg.name}@${pkg.version} successfully`))
|
|
||||||
})()
|
|
@ -1,13 +1,13 @@
|
|||||||
// Invoked on the commit-msg git hook by simple-git-hooks.
|
// Invoked on the commit-msg git hook by simple-git-hooks.
|
||||||
|
|
||||||
const colors = require('picocolors')
|
import colors from 'picocolors'
|
||||||
const fs = require('fs')
|
import fs from 'node:fs'
|
||||||
|
|
||||||
const msgPath = process.argv[2]
|
const msgPath = process.argv[2]
|
||||||
const msg = fs.readFileSync(msgPath, 'utf-8').trim()
|
const msg = fs.readFileSync(msgPath, 'utf-8').trim()
|
||||||
|
|
||||||
const commitRE =
|
const commitRE =
|
||||||
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
|
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?!?: .{1,50}/
|
||||||
|
|
||||||
if (!commitRE.test(msg)) {
|
if (!commitRE.test(msg)) {
|
||||||
console.log()
|
console.log()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { build as viteBuild } from 'vite'
|
import { build as viteBuild } from 'vite'
|
||||||
import { InlineConfig, resolveConfig } from './config'
|
import { type InlineConfig, resolveConfig } from './config'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bundles the electron app for production.
|
* Bundles the electron app for production.
|
||||||
|
66
src/cli.ts
66
src/cli.ts
@ -1,7 +1,8 @@
|
|||||||
import { cac } from 'cac'
|
import { cac } from 'cac'
|
||||||
import colors from 'picocolors'
|
import colors from 'picocolors'
|
||||||
import { LogLevel, createLogger } from 'vite'
|
import { type LogLevel, createLogger } from 'vite'
|
||||||
import { InlineConfig } from './config'
|
import type { InlineConfig } from './config'
|
||||||
|
import { version } from '../package.json'
|
||||||
|
|
||||||
const cli = cac('electron-vite')
|
const cli = cac('electron-vite')
|
||||||
|
|
||||||
@ -24,6 +25,20 @@ interface GlobalCLIOptions {
|
|||||||
w?: boolean
|
w?: boolean
|
||||||
watch?: boolean
|
watch?: boolean
|
||||||
outDir?: string
|
outDir?: string
|
||||||
|
entry?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DevCLIOptions {
|
||||||
|
inspect?: boolean | string
|
||||||
|
inspectBrk?: boolean | string
|
||||||
|
remoteDebuggingPort?: string
|
||||||
|
noSandbox?: boolean
|
||||||
|
rendererOnly?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PreviewCLIOptions {
|
||||||
|
noSandbox?: boolean
|
||||||
|
skipBuild?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
function createInlineConfig(root: string, options: GlobalCLIOptions): InlineConfig {
|
function createInlineConfig(root: string, options: GlobalCLIOptions): InlineConfig {
|
||||||
@ -52,6 +67,7 @@ cli
|
|||||||
.option('--ignoreConfigWarning', `[boolean] ignore config warning`)
|
.option('--ignoreConfigWarning', `[boolean] ignore config warning`)
|
||||||
.option('--sourcemap', `[boolean] output source maps for debug (default: false)`)
|
.option('--sourcemap', `[boolean] output source maps for debug (default: false)`)
|
||||||
.option('--outDir <dir>', `[string] output directory (default: out)`)
|
.option('--outDir <dir>', `[string] output directory (default: out)`)
|
||||||
|
.option('--entry <file>', `[string] specify electron entry file`)
|
||||||
|
|
||||||
// dev
|
// dev
|
||||||
cli
|
cli
|
||||||
@ -59,13 +75,36 @@ cli
|
|||||||
.alias('serve')
|
.alias('serve')
|
||||||
.alias('dev')
|
.alias('dev')
|
||||||
.option('-w, --watch', `[boolean] rebuilds when main process or preload script modules have changed on disk`)
|
.option('-w, --watch', `[boolean] rebuilds when main process or preload script modules have changed on disk`)
|
||||||
|
.option('--inspect [port]', `[boolean | number] enable V8 inspector on the specified port`)
|
||||||
|
.option('--inspectBrk [port]', `[boolean | number] enable V8 inspector on the specified port`)
|
||||||
.option('--remoteDebuggingPort <port>', `[string] port for remote debugging`)
|
.option('--remoteDebuggingPort <port>', `[string] port for remote debugging`)
|
||||||
|
.option('--noSandbox', `[boolean] forces renderer process to run un-sandboxed`)
|
||||||
.option('--rendererOnly', `[boolean] only dev server for the renderer`)
|
.option('--rendererOnly', `[boolean] only dev server for the renderer`)
|
||||||
.action(async (root: string, options: { remoteDebuggingPort?: string; rendererOnly: boolean } & GlobalCLIOptions) => {
|
.action(async (root: string, options: DevCLIOptions & GlobalCLIOptions) => {
|
||||||
if (options.remoteDebuggingPort) {
|
if (options.remoteDebuggingPort) {
|
||||||
process.env.REMOTE_DEBUGGING_PORT = options.remoteDebuggingPort
|
process.env.REMOTE_DEBUGGING_PORT = options.remoteDebuggingPort
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.inspect) {
|
||||||
|
process.env.V8_INSPECTOR_PORT = typeof options.inspect === 'number' ? `${options.inspect}` : '5858'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.inspectBrk) {
|
||||||
|
process.env.V8_INSPECTOR_BRK_PORT = typeof options.inspectBrk === 'number' ? `${options.inspectBrk}` : '5858'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.noSandbox) {
|
||||||
|
process.env.NO_SANDBOX = '1'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options['--']) {
|
||||||
|
process.env.ELECTRON_CLI_ARGS = JSON.stringify(options['--'])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.entry) {
|
||||||
|
process.env.ELECTRON_ENTRY = options.entry
|
||||||
|
}
|
||||||
|
|
||||||
const { createServer } = await import('./server')
|
const { createServer } = await import('./server')
|
||||||
const inlineConfig = createInlineConfig(root, options)
|
const inlineConfig = createInlineConfig(root, options)
|
||||||
|
|
||||||
@ -86,6 +125,10 @@ cli.command('build [root]', 'build for production').action(async (root: string,
|
|||||||
const { build } = await import('./build')
|
const { build } = await import('./build')
|
||||||
const inlineConfig = createInlineConfig(root, options)
|
const inlineConfig = createInlineConfig(root, options)
|
||||||
|
|
||||||
|
if (options.entry) {
|
||||||
|
process.env.ELECTRON_ENTRY = options.entry
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await build(inlineConfig)
|
await build(inlineConfig)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -98,11 +141,24 @@ cli.command('build [root]', 'build for production').action(async (root: string,
|
|||||||
// preview
|
// preview
|
||||||
cli
|
cli
|
||||||
.command('preview [root]', 'start electron app to preview production build')
|
.command('preview [root]', 'start electron app to preview production build')
|
||||||
|
.option('--noSandbox', `[boolean] forces renderer process to run un-sandboxed`)
|
||||||
.option('--skipBuild', `[boolean] skip build`)
|
.option('--skipBuild', `[boolean] skip build`)
|
||||||
.action(async (root: string, options: { skipBuild?: boolean } & GlobalCLIOptions) => {
|
.action(async (root: string, options: PreviewCLIOptions & GlobalCLIOptions) => {
|
||||||
const { preview } = await import('./preview')
|
const { preview } = await import('./preview')
|
||||||
const inlineConfig = createInlineConfig(root, options)
|
const inlineConfig = createInlineConfig(root, options)
|
||||||
|
|
||||||
|
if (options.noSandbox) {
|
||||||
|
process.env.NO_SANDBOX = '1'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.entry) {
|
||||||
|
process.env.ELECTRON_ENTRY = options.entry
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options['--']) {
|
||||||
|
process.env.ELECTRON_CLI_ARGS = JSON.stringify(options['--'])
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await preview(inlineConfig, { skipBuild: options.skipBuild })
|
await preview(inlineConfig, { skipBuild: options.skipBuild })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -113,6 +169,6 @@ cli
|
|||||||
})
|
})
|
||||||
|
|
||||||
cli.help()
|
cli.help()
|
||||||
cli.version(require('../package.json').version)
|
cli.version(version)
|
||||||
|
|
||||||
cli.parse()
|
cli.parse()
|
||||||
|
@ -5,7 +5,7 @@ import { createRequire } from 'node:module'
|
|||||||
import colors from 'picocolors'
|
import colors from 'picocolors'
|
||||||
import {
|
import {
|
||||||
type UserConfig as ViteConfig,
|
type UserConfig as ViteConfig,
|
||||||
type UserConfigExport as UserViteConfigExport,
|
type UserConfigExport as ViteConfigExport,
|
||||||
type ConfigEnv,
|
type ConfigEnv,
|
||||||
type Plugin,
|
type Plugin,
|
||||||
type LogLevel,
|
type LogLevel,
|
||||||
@ -18,7 +18,10 @@ import { build } from 'esbuild'
|
|||||||
import { electronMainVitePlugin, electronPreloadVitePlugin, electronRendererVitePlugin } from './plugins/electron'
|
import { electronMainVitePlugin, electronPreloadVitePlugin, electronRendererVitePlugin } from './plugins/electron'
|
||||||
import assetPlugin from './plugins/asset'
|
import assetPlugin from './plugins/asset'
|
||||||
import workerPlugin from './plugins/worker'
|
import workerPlugin from './plugins/worker'
|
||||||
import { isObject, dynamicImport } from './utils'
|
import importMetaPlugin from './plugins/importMeta'
|
||||||
|
import esmShimPlugin from './plugins/esm'
|
||||||
|
import modulePathPlugin from './plugins/modulePath'
|
||||||
|
import { isObject, isFilePathESM } from './utils'
|
||||||
|
|
||||||
export { defineConfig as defineViteConfig } from 'vite'
|
export { defineConfig as defineViteConfig } from 'vite'
|
||||||
|
|
||||||
@ -26,42 +29,42 @@ export interface UserConfig {
|
|||||||
/**
|
/**
|
||||||
* Vite config options for electron main process
|
* Vite config options for electron main process
|
||||||
*
|
*
|
||||||
* https://cn.vitejs.dev/config/
|
* https://vitejs.dev/config/
|
||||||
*/
|
*/
|
||||||
main?: ViteConfig & { configFile?: string | false }
|
main?: ViteConfig & { configFile?: string | false }
|
||||||
/**
|
/**
|
||||||
* Vite config options for electron renderer process
|
* Vite config options for electron renderer process
|
||||||
*
|
*
|
||||||
* https://cn.vitejs.dev/config/
|
* https://vitejs.dev/config/
|
||||||
*/
|
*/
|
||||||
renderer?: ViteConfig & { configFile?: string | false }
|
renderer?: ViteConfig & { configFile?: string | false }
|
||||||
/**
|
/**
|
||||||
* Vite config options for electron preload files
|
* Vite config options for electron preload files
|
||||||
*
|
*
|
||||||
* https://cn.vitejs.dev/config/
|
* https://vitejs.dev/config/
|
||||||
*/
|
*/
|
||||||
preload?: ViteConfig & { configFile?: string | false }
|
preload?: ViteConfig & { configFile?: string | false }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserConfigSchema {
|
export interface ElectronViteConfig {
|
||||||
/**
|
/**
|
||||||
* Vite config options for electron main process
|
* Vite config options for electron main process
|
||||||
*
|
*
|
||||||
* https://cn.vitejs.dev/config/
|
* https://vitejs.dev/config/
|
||||||
*/
|
*/
|
||||||
main?: UserViteConfigExport
|
main?: ViteConfigExport
|
||||||
/**
|
/**
|
||||||
* Vite config options for electron renderer process
|
* Vite config options for electron renderer process
|
||||||
*
|
*
|
||||||
* https://cn.vitejs.dev/config/
|
* https://vitejs.dev/config/
|
||||||
*/
|
*/
|
||||||
renderer?: UserViteConfigExport
|
renderer?: ViteConfigExport
|
||||||
/**
|
/**
|
||||||
* Vite config options for electron preload files
|
* Vite config options for electron preload files
|
||||||
*
|
*
|
||||||
* https://cn.vitejs.dev/config/
|
* https://vitejs.dev/config/
|
||||||
*/
|
*/
|
||||||
preload?: UserViteConfigExport
|
preload?: ViteConfigExport
|
||||||
}
|
}
|
||||||
|
|
||||||
export type InlineConfig = Omit<ViteConfig, 'base'> & {
|
export type InlineConfig = Omit<ViteConfig, 'base'> & {
|
||||||
@ -70,16 +73,28 @@ export type InlineConfig = Omit<ViteConfig, 'base'> & {
|
|||||||
ignoreConfigWarning?: boolean
|
ignoreConfigWarning?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UserConfigFn = (env: ConfigEnv) => UserConfigSchema | Promise<UserConfigSchema>
|
export type ElectronViteConfigFnObject = (env: ConfigEnv) => ElectronViteConfig
|
||||||
export type UserConfigExport = UserConfigSchema | Promise<UserConfigSchema> | UserConfigFn
|
export type ElectronViteConfigFnPromise = (env: ConfigEnv) => Promise<ElectronViteConfig>
|
||||||
|
export type ElectronViteConfigFn = (env: ConfigEnv) => ElectronViteConfig | Promise<ElectronViteConfig>
|
||||||
|
|
||||||
|
export type ElectronViteConfigExport =
|
||||||
|
| ElectronViteConfig
|
||||||
|
| Promise<ElectronViteConfig>
|
||||||
|
| ElectronViteConfigFnObject
|
||||||
|
| ElectronViteConfigFnPromise
|
||||||
|
| ElectronViteConfigFn
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type helper to make it easier to use `electron.vite.config.*`
|
* Type helper to make it easier to use `electron.vite.config.*`
|
||||||
* accepts a direct {@link UserConfig} object, or a function that returns it.
|
* accepts a direct {@link ElectronViteConfig} object, or a function that returns it.
|
||||||
* The function receives a object that exposes two properties:
|
* The function receives a object that exposes two properties:
|
||||||
* `command` (either `'build'` or `'serve'`), and `mode`.
|
* `command` (either `'build'` or `'serve'`), and `mode`.
|
||||||
*/
|
*/
|
||||||
export function defineConfig(config: UserConfigExport): UserConfigExport {
|
export function defineConfig(config: ElectronViteConfig): ElectronViteConfig
|
||||||
|
export function defineConfig(config: Promise<ElectronViteConfig>): Promise<ElectronViteConfig>
|
||||||
|
export function defineConfig(config: ElectronViteConfigFnObject): ElectronViteConfigFnObject
|
||||||
|
export function defineConfig(config: ElectronViteConfigExport): ElectronViteConfigExport
|
||||||
|
export function defineConfig(config: ElectronViteConfigExport): ElectronViteConfigExport {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,8 +112,6 @@ export async function resolveConfig(
|
|||||||
const config = inlineConfig
|
const config = inlineConfig
|
||||||
const mode = inlineConfig.mode || defaultMode
|
const mode = inlineConfig.mode || defaultMode
|
||||||
|
|
||||||
config.mode = mode
|
|
||||||
|
|
||||||
process.env.NODE_ENV = defaultMode
|
process.env.NODE_ENV = defaultMode
|
||||||
|
|
||||||
let userConfig: UserConfig | undefined
|
let userConfig: UserConfig | undefined
|
||||||
@ -127,11 +140,20 @@ export async function resolveConfig(
|
|||||||
if (loadResult.config.main) {
|
if (loadResult.config.main) {
|
||||||
const mainViteConfig: ViteConfig = mergeConfig(loadResult.config.main, deepClone(config))
|
const mainViteConfig: ViteConfig = mergeConfig(loadResult.config.main, deepClone(config))
|
||||||
|
|
||||||
|
mainViteConfig.mode = inlineConfig.mode || mainViteConfig.mode || defaultMode
|
||||||
|
|
||||||
if (outDir) {
|
if (outDir) {
|
||||||
resetOutDir(mainViteConfig, outDir, 'main')
|
resetOutDir(mainViteConfig, outDir, 'main')
|
||||||
}
|
}
|
||||||
|
|
||||||
mergePlugins(mainViteConfig, [...electronMainVitePlugin({ root }), assetPlugin(), workerPlugin()])
|
mergePlugins(mainViteConfig, [
|
||||||
|
...electronMainVitePlugin({ root }),
|
||||||
|
assetPlugin(),
|
||||||
|
workerPlugin(),
|
||||||
|
modulePathPlugin(),
|
||||||
|
importMetaPlugin(),
|
||||||
|
esmShimPlugin()
|
||||||
|
])
|
||||||
|
|
||||||
loadResult.config.main = mainViteConfig
|
loadResult.config.main = mainViteConfig
|
||||||
loadResult.config.main.configFile = false
|
loadResult.config.main.configFile = false
|
||||||
@ -140,10 +162,17 @@ export async function resolveConfig(
|
|||||||
if (loadResult.config.preload) {
|
if (loadResult.config.preload) {
|
||||||
const preloadViteConfig: ViteConfig = mergeConfig(loadResult.config.preload, deepClone(config))
|
const preloadViteConfig: ViteConfig = mergeConfig(loadResult.config.preload, deepClone(config))
|
||||||
|
|
||||||
|
preloadViteConfig.mode = inlineConfig.mode || preloadViteConfig.mode || defaultMode
|
||||||
|
|
||||||
if (outDir) {
|
if (outDir) {
|
||||||
resetOutDir(preloadViteConfig, outDir, 'preload')
|
resetOutDir(preloadViteConfig, outDir, 'preload')
|
||||||
}
|
}
|
||||||
mergePlugins(preloadViteConfig, [...electronPreloadVitePlugin({ root }), assetPlugin()])
|
mergePlugins(preloadViteConfig, [
|
||||||
|
...electronPreloadVitePlugin({ root }),
|
||||||
|
assetPlugin(),
|
||||||
|
importMetaPlugin(),
|
||||||
|
esmShimPlugin()
|
||||||
|
])
|
||||||
|
|
||||||
loadResult.config.preload = preloadViteConfig
|
loadResult.config.preload = preloadViteConfig
|
||||||
loadResult.config.preload.configFile = false
|
loadResult.config.preload.configFile = false
|
||||||
@ -152,6 +181,8 @@ export async function resolveConfig(
|
|||||||
if (loadResult.config.renderer) {
|
if (loadResult.config.renderer) {
|
||||||
const rendererViteConfig: ViteConfig = mergeConfig(loadResult.config.renderer, deepClone(config))
|
const rendererViteConfig: ViteConfig = mergeConfig(loadResult.config.renderer, deepClone(config))
|
||||||
|
|
||||||
|
rendererViteConfig.mode = inlineConfig.mode || rendererViteConfig.mode || defaultMode
|
||||||
|
|
||||||
if (outDir) {
|
if (outDir) {
|
||||||
resetOutDir(rendererViteConfig, outDir, 'renderer')
|
resetOutDir(rendererViteConfig, outDir, 'renderer')
|
||||||
}
|
}
|
||||||
@ -227,11 +258,7 @@ export async function loadConfigFromFile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// electron does not support adding type: "module" to package.json
|
const isESM = isFilePathESM(resolvedPath)
|
||||||
let isESM = false
|
|
||||||
if (/\.m[jt]s$/.test(resolvedPath) || resolvedPath.endsWith('.ts')) {
|
|
||||||
isESM = true
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const bundled = await bundleConfigFile(resolvedPath, isESM)
|
const bundled = await bundleConfigFile(resolvedPath, isESM)
|
||||||
@ -316,7 +343,7 @@ async function bundleConfigFile(fileName: string, isESM: boolean): Promise<{ cod
|
|||||||
absWorkingDir: process.cwd(),
|
absWorkingDir: process.cwd(),
|
||||||
entryPoints: [fileName],
|
entryPoints: [fileName],
|
||||||
write: false,
|
write: false,
|
||||||
target: ['node14.18', 'node16'],
|
target: ['node20'],
|
||||||
platform: 'node',
|
platform: 'node',
|
||||||
bundle: true,
|
bundle: true,
|
||||||
format: isESM ? 'esm' : 'cjs',
|
format: isESM ? 'esm' : 'cjs',
|
||||||
@ -379,17 +406,18 @@ async function loadConfigFormBundledFile(
|
|||||||
configFile: string,
|
configFile: string,
|
||||||
bundledCode: string,
|
bundledCode: string,
|
||||||
isESM: boolean
|
isESM: boolean
|
||||||
): Promise<UserConfigExport> {
|
): Promise<ElectronViteConfigExport> {
|
||||||
if (isESM) {
|
if (isESM) {
|
||||||
const fileNameTmp = path.resolve(configRoot, `${CONFIG_FILE_NAME}.${Date.now()}.mjs`)
|
const fileNameTmp = path.resolve(configRoot, `${CONFIG_FILE_NAME}.${Date.now()}.mjs`)
|
||||||
fs.writeFileSync(fileNameTmp, bundledCode)
|
fs.writeFileSync(fileNameTmp, bundledCode)
|
||||||
|
|
||||||
const fileUrl = pathToFileURL(fileNameTmp)
|
const fileUrl = pathToFileURL(fileNameTmp)
|
||||||
try {
|
try {
|
||||||
return (await dynamicImport(fileUrl)).default
|
return (await import(fileUrl.href)).default
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(fileNameTmp)
|
fs.unlinkSync(fileNameTmp)
|
||||||
|
// eslint-disable-next-line no-empty
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import { createRequire } from 'node:module'
|
import { createRequire } from 'node:module'
|
||||||
import { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process'
|
import { type ChildProcess, spawn } from 'node:child_process'
|
||||||
import { type Logger } from 'vite'
|
import { loadPackageData } from './utils'
|
||||||
|
|
||||||
const _require = createRequire(import.meta.url)
|
const _require = createRequire(import.meta.url)
|
||||||
|
|
||||||
const ensureElectronEntryFile = (root = process.cwd()): void => {
|
const ensureElectronEntryFile = (root = process.cwd()): void => {
|
||||||
const pkg = path.join(root, 'package.json')
|
if (process.env.ELECTRON_ENTRY) return
|
||||||
if (fs.existsSync(pkg)) {
|
const pkg = loadPackageData()
|
||||||
const main = require(pkg).main
|
if (pkg) {
|
||||||
if (!main) {
|
if (!pkg.main) {
|
||||||
throw new Error('No entry point found for electron app, please add a "main" field to package.json')
|
throw new Error('No entry point found for electron app, please add a "main" field to package.json')
|
||||||
} else {
|
} else {
|
||||||
const entryPath = path.resolve(root, main)
|
const entryPath = path.resolve(root, pkg.main)
|
||||||
if (!fs.existsSync(entryPath)) {
|
if (!fs.existsSync(entryPath)) {
|
||||||
throw new Error(`No electron app entry file found: ${entryPath}`)
|
throw new Error(`No electron app entry file found: ${entryPath}`)
|
||||||
}
|
}
|
||||||
@ -36,6 +36,16 @@ const getElectronMajorVer = (): string => {
|
|||||||
return majorVer
|
return majorVer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function supportESM(): boolean {
|
||||||
|
const majorVer = getElectronMajorVer()
|
||||||
|
return parseInt(majorVer) >= 28
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getElectronMajorVersion(): number {
|
||||||
|
const majorVer = getElectronMajorVer()
|
||||||
|
return parseInt(majorVer)
|
||||||
|
}
|
||||||
|
|
||||||
export function getElectronPath(): string {
|
export function getElectronPath(): string {
|
||||||
let electronExecPath = process.env.ELECTRON_EXEC_PATH || ''
|
let electronExecPath = process.env.ELECTRON_EXEC_PATH || ''
|
||||||
if (!electronExecPath) {
|
if (!electronExecPath) {
|
||||||
@ -59,20 +69,26 @@ export function getElectronNodeTarget(): string {
|
|||||||
const electronVer = getElectronMajorVer()
|
const electronVer = getElectronMajorVer()
|
||||||
|
|
||||||
const nodeVer = {
|
const nodeVer = {
|
||||||
|
'37': '22.16',
|
||||||
|
'36': '22.14',
|
||||||
|
'35': '22.14',
|
||||||
|
'34': '20.18',
|
||||||
|
'33': '20.18',
|
||||||
|
'32': '20.16',
|
||||||
|
'31': '20.14',
|
||||||
|
'30': '20.11',
|
||||||
|
'29': '20.9',
|
||||||
|
'28': '18.18',
|
||||||
|
'27': '18.17',
|
||||||
|
'26': '18.16',
|
||||||
|
'25': '18.15',
|
||||||
'24': '18.14',
|
'24': '18.14',
|
||||||
'23': '18.12',
|
'23': '18.12',
|
||||||
'22': '16.17',
|
'22': '16.17',
|
||||||
'21': '16.16',
|
'21': '16.16',
|
||||||
'20': '16.15',
|
'20': '16.15',
|
||||||
'19': '16.14',
|
'19': '16.14',
|
||||||
'18': '16.13',
|
'18': '16.13'
|
||||||
'17': '16.13',
|
|
||||||
'16': '16.9',
|
|
||||||
'15': '16.5',
|
|
||||||
'14': '14.17',
|
|
||||||
'13': '14.17',
|
|
||||||
'12': '14.16',
|
|
||||||
'11': '12.18'
|
|
||||||
}
|
}
|
||||||
if (electronVer && parseInt(electronVer) > 10) {
|
if (electronVer && parseInt(electronVer) > 10) {
|
||||||
let target = nodeVer[electronVer]
|
let target = nodeVer[electronVer]
|
||||||
@ -86,20 +102,26 @@ export function getElectronChromeTarget(): string {
|
|||||||
const electronVer = getElectronMajorVer()
|
const electronVer = getElectronMajorVer()
|
||||||
|
|
||||||
const chromeVer = {
|
const chromeVer = {
|
||||||
|
'37': '138',
|
||||||
|
'36': '136',
|
||||||
|
'35': '134',
|
||||||
|
'34': '132',
|
||||||
|
'33': '130',
|
||||||
|
'32': '128',
|
||||||
|
'31': '126',
|
||||||
|
'30': '124',
|
||||||
|
'29': '122',
|
||||||
|
'28': '120',
|
||||||
|
'27': '118',
|
||||||
|
'26': '116',
|
||||||
|
'25': '114',
|
||||||
'24': '112',
|
'24': '112',
|
||||||
'23': '110',
|
'23': '110',
|
||||||
'22': '108',
|
'22': '108',
|
||||||
'21': '106',
|
'21': '106',
|
||||||
'20': '104',
|
'20': '104',
|
||||||
'19': '102',
|
'19': '102',
|
||||||
'18': '100',
|
'18': '100'
|
||||||
'17': '98',
|
|
||||||
'16': '96',
|
|
||||||
'15': '94',
|
|
||||||
'14': '93',
|
|
||||||
'13': '91',
|
|
||||||
'12': '89',
|
|
||||||
'11': '87'
|
|
||||||
}
|
}
|
||||||
if (electronVer && parseInt(electronVer) > 10) {
|
if (electronVer && parseInt(electronVer) > 10) {
|
||||||
let target = chromeVer[electronVer]
|
let target = chromeVer[electronVer]
|
||||||
@ -109,25 +131,34 @@ export function getElectronChromeTarget(): string {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
export function startElectron(root: string | undefined, logger: Logger): ChildProcessWithoutNullStreams {
|
export function startElectron(root: string | undefined): ChildProcess {
|
||||||
ensureElectronEntryFile(root)
|
ensureElectronEntryFile(root)
|
||||||
|
|
||||||
const electronPath = getElectronPath()
|
const electronPath = getElectronPath()
|
||||||
|
|
||||||
const inspect = !!process.env.VSCODE_INSPECTOR_OPTIONS
|
const isDev = process.env.NODE_ENV_ELECTRON_VITE === 'development'
|
||||||
|
|
||||||
const args: string[] = []
|
const args: string[] = process.env.ELECTRON_CLI_ARGS ? JSON.parse(process.env.ELECTRON_CLI_ARGS) : []
|
||||||
if (!!process.env.REMOTE_DEBUGGING_PORT && process.env.NODE_ENV_ELECTRON_VITE === 'development') {
|
|
||||||
|
if (!!process.env.REMOTE_DEBUGGING_PORT && isDev) {
|
||||||
args.push(`--remote-debugging-port=${process.env.REMOTE_DEBUGGING_PORT}`)
|
args.push(`--remote-debugging-port=${process.env.REMOTE_DEBUGGING_PORT}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const ps = spawn(electronPath, ['.'].concat(args))
|
if (!!process.env.V8_INSPECTOR_PORT && isDev) {
|
||||||
ps.stdout.on('data', chunk => {
|
args.push(`--inspect=${process.env.V8_INSPECTOR_PORT}`)
|
||||||
!inspect && chunk.toString().trim() && logger.info(chunk.toString())
|
}
|
||||||
})
|
|
||||||
ps.stderr.on('data', chunk => {
|
if (!!process.env.V8_INSPECTOR_BRK_PORT && isDev) {
|
||||||
!inspect && chunk.toString().trim() && logger.error(chunk.toString())
|
args.push(`--inspect-brk=${process.env.V8_INSPECTOR_BRK_PORT}`)
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if (process.env.NO_SANDBOX === '1') {
|
||||||
|
args.push('--no-sandbox')
|
||||||
|
}
|
||||||
|
|
||||||
|
const entry = process.env.ELECTRON_ENTRY || '.'
|
||||||
|
|
||||||
|
const ps = spawn(electronPath, [entry].concat(args), { stdio: 'inherit' })
|
||||||
ps.on('close', process.exit)
|
ps.on('close', process.exit)
|
||||||
|
|
||||||
return ps
|
return ps
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export { type LogLevel, createLogger, splitVendorChunkPlugin, splitVendorChunk } from 'vite'
|
export { type LogLevel, createLogger, mergeConfig } from 'vite'
|
||||||
export * from './config'
|
export * from './config'
|
||||||
export { createServer } from './server'
|
export { createServer } from './server'
|
||||||
export { build } from './build'
|
export { build } from './build'
|
||||||
|
@ -42,7 +42,7 @@ function resolveAsset(id: string): AssetResolved | null {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeAssetRE = /__VITE_NODE_ASSET__([a-z\d]{8})__/g
|
const nodeAssetRE = /__VITE_NODE_ASSET__([\w$]+)__/g
|
||||||
const nodePublicAssetRE = /__VITE_NODE_PUBLIC_ASSET__([a-z\d]{8})__/g
|
const nodePublicAssetRE = /__VITE_NODE_PUBLIC_ASSET__([a-z\d]{8})__/g
|
||||||
|
|
||||||
const wasmHelperId = '\0__electron-vite-wasm-helper'
|
const wasmHelperId = '\0__electron-vite-wasm-helper'
|
||||||
@ -68,6 +68,10 @@ export default function assetPlugin(): Plugin {
|
|||||||
name: 'vite:node-asset',
|
name: 'vite:node-asset',
|
||||||
apply: 'build',
|
apply: 'build',
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
|
buildStart(): void {
|
||||||
|
publicAssetPathCache.clear()
|
||||||
|
assetCache.clear()
|
||||||
|
},
|
||||||
configResolved(config): void {
|
configResolved(config): void {
|
||||||
sourcemap = config.build.sourcemap
|
sourcemap = config.build.sourcemap
|
||||||
publicDir = normalizePath(config.publicDir)
|
publicDir = normalizePath(config.publicDir)
|
||||||
@ -83,6 +87,12 @@ export default function assetPlugin(): Plugin {
|
|||||||
return wasmHelperCode
|
return wasmHelperCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id.startsWith('\0')) {
|
||||||
|
// Rollup convention, this id should be handled by the
|
||||||
|
// plugin that marked it with \0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const assetResolved = resolveAsset(id)
|
const assetResolved = resolveAsset(id)
|
||||||
if (!assetResolved) {
|
if (!assetResolved) {
|
||||||
return
|
return
|
||||||
@ -105,7 +115,7 @@ export default function assetPlugin(): Plugin {
|
|||||||
const hash = this.emitFile({
|
const hash = this.emitFile({
|
||||||
type: 'asset',
|
type: 'asset',
|
||||||
name: path.basename(file),
|
name: path.basename(file),
|
||||||
source
|
source: source as unknown as Uint8Array
|
||||||
})
|
})
|
||||||
referenceId = `__VITE_NODE_ASSET__${hash}__`
|
referenceId = `__VITE_NODE_ASSET__${hash}__`
|
||||||
assetCache.set(file, referenceId)
|
assetCache.set(file, referenceId)
|
||||||
@ -169,7 +179,7 @@ export default function assetPlugin(): Plugin {
|
|||||||
if (s) {
|
if (s) {
|
||||||
return {
|
return {
|
||||||
code: s.toString(),
|
code: s.toString(),
|
||||||
map: sourcemap ? s.generateMap({ hires: true }) : null
|
map: sourcemap ? s.generateMap({ hires: 'boundary' }) : null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
|
@ -15,7 +15,7 @@ import { toRelativePath } from '../utils'
|
|||||||
const _require = createRequire(import.meta.url)
|
const _require = createRequire(import.meta.url)
|
||||||
|
|
||||||
function getBytecodeCompilerPath(): string {
|
function getBytecodeCompilerPath(): string {
|
||||||
return path.join(path.dirname(_require.resolve('electron-vite/package.json')), 'bin', 'electron-bytecode.js')
|
return path.join(path.dirname(_require.resolve('electron-vite/package.json')), 'bin', 'electron-bytecode.cjs')
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileToBytecode(code: string): Promise<Buffer> {
|
function compileToBytecode(code: string): Promise<Buffer> {
|
||||||
@ -98,7 +98,7 @@ const bytecodeModuleLoaderCode = [
|
|||||||
` ret |= buffer[0];`,
|
` ret |= buffer[0];`,
|
||||||
` return ret;`,
|
` return ret;`,
|
||||||
`};`,
|
`};`,
|
||||||
`Module._extensions[".jsc"] = function (module, filename) {`,
|
`Module._extensions[".jsc"] = Module._extensions[".cjsc"] = function (module, filename) {`,
|
||||||
` const bytecodeBuffer = fs.readFileSync(filename);`,
|
` const bytecodeBuffer = fs.readFileSync(filename);`,
|
||||||
` if (!Buffer.isBuffer(bytecodeBuffer)) {`,
|
` if (!Buffer.isBuffer(bytecodeBuffer)) {`,
|
||||||
` throw new Error("BytecodeBuffer must be a buffer object.");`,
|
` throw new Error("BytecodeBuffer must be a buffer object.");`,
|
||||||
@ -181,7 +181,7 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const useStrict = '"use strict";'
|
const useStrict = '"use strict";'
|
||||||
const bytecodeModuleLoader = 'bytecode-loader.js'
|
const bytecodeModuleLoader = 'bytecode-loader.cjs'
|
||||||
|
|
||||||
let config: ResolvedConfig
|
let config: ResolvedConfig
|
||||||
let useInRenderer = false
|
let useInRenderer = false
|
||||||
@ -196,11 +196,14 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
config = resolvedConfig
|
config = resolvedConfig
|
||||||
useInRenderer = config.plugins.some(p => p.name === 'vite:electron-renderer-preset-config')
|
useInRenderer = config.plugins.some(p => p.name === 'vite:electron-renderer-preset-config')
|
||||||
if (useInRenderer) {
|
if (useInRenderer) {
|
||||||
config.logger.warn(colors.yellow('bytecodePlugin is not support renderers'))
|
config.logger.warn(colors.yellow('bytecodePlugin does not support renderer.'))
|
||||||
|
}
|
||||||
|
if (resolvedConfig.build.minify && protectedStrings.length > 0) {
|
||||||
|
config.logger.warn(colors.yellow('Strings cannot be protected when minification is enabled.'))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
transform(code, id): void | { code: string; map: SourceMapInput } {
|
transform(code, id): void | { code: string; map: SourceMapInput } {
|
||||||
if (protectedStrings.length === 0 || !filter(id)) return
|
if (config.build.minify || protectedStrings.length === 0 || !filter(id)) return
|
||||||
|
|
||||||
let match: RegExpExecArray | null
|
let match: RegExpExecArray | null
|
||||||
let s: MagicString | undefined
|
let s: MagicString | undefined
|
||||||
@ -222,11 +225,20 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
if (s) {
|
if (s) {
|
||||||
return {
|
return {
|
||||||
code: s.toString(),
|
code: s.toString(),
|
||||||
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
map: config.build.sourcemap ? s.generateMap({ hires: 'boundary' }) : null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
renderChunk(code, chunk): { code: string } | null {
|
renderChunk(code, chunk, options): { code: string } | null {
|
||||||
|
if (options.format === 'es') {
|
||||||
|
config.logger.warn(
|
||||||
|
colors.yellow(
|
||||||
|
'bytecodePlugin does not support ES module, please remove "type": "module" ' +
|
||||||
|
'in package.json or set the "build.rollupOptions.output.format" option to "cjs".'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return null
|
||||||
|
}
|
||||||
if (useInRenderer) {
|
if (useInRenderer) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -240,8 +252,8 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
generateBundle(): void {
|
generateBundle(options): void {
|
||||||
if (!useInRenderer && bytecodeRequired) {
|
if (options.format !== 'es' && !useInRenderer && bytecodeRequired) {
|
||||||
this.emitFile({
|
this.emitFile({
|
||||||
type: 'asset',
|
type: 'asset',
|
||||||
source: bytecodeModuleLoaderCode.join('\n') + '\n',
|
source: bytecodeModuleLoaderCode.join('\n') + '\n',
|
||||||
@ -251,7 +263,7 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async writeBundle(options, output): Promise<void> {
|
async writeBundle(options, output): Promise<void> {
|
||||||
if (useInRenderer || !bytecodeRequired) {
|
if (options.format === 'es' || useInRenderer || !bytecodeRequired) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +287,7 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getBytecodeLoaderBlock = (chunkFileName: string): string => {
|
const getBytecodeLoaderBlock = (chunkFileName: string): string => {
|
||||||
return `require("${toRelativePath(bytecodeModuleLoader, chunkFileName)}");`
|
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@ -298,7 +310,7 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
const chunkFileName = path.resolve(outDir, name)
|
const chunkFileName = path.resolve(outDir, name)
|
||||||
if (bytecodeChunks.includes(name)) {
|
if (bytecodeChunks.includes(name)) {
|
||||||
const bytecodeBuffer = await compileToBytecode(_code)
|
const bytecodeBuffer = await compileToBytecode(_code)
|
||||||
fs.writeFileSync(path.resolve(outDir, name + 'c'), bytecodeBuffer)
|
fs.writeFileSync(path.resolve(outDir, name + 'c'), bytecodeBuffer as unknown as Uint8Array)
|
||||||
if (chunk.isEntry) {
|
if (chunk.isEntry) {
|
||||||
if (!removeBundleJS) {
|
if (!removeBundleJS) {
|
||||||
keepBundle(chunkFileName)
|
keepBundle(chunkFileName)
|
||||||
@ -332,7 +344,9 @@ export function bytecodePlugin(options: BytecodeOptions = {}): Plugin | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName)
|
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName)
|
||||||
_code = hasBytecodeMoudle ? _code.replace(useStrict, `${useStrict}\n${bytecodeLoaderBlock}`) : _code
|
_code = hasBytecodeMoudle
|
||||||
|
? _code.replace(/("use strict";)|('use strict';)/, `${useStrict}\n${bytecodeLoaderBlock}`)
|
||||||
|
: _code
|
||||||
}
|
}
|
||||||
fs.writeFileSync(chunkFileName, _code)
|
fs.writeFileSync(chunkFileName, _code)
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,16 @@ import path from 'node:path'
|
|||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import { builtinModules } from 'node:module'
|
import { builtinModules } from 'node:module'
|
||||||
import colors from 'picocolors'
|
import colors from 'picocolors'
|
||||||
import { type Plugin, mergeConfig, normalizePath } from 'vite'
|
import { type Plugin, type LibraryOptions, mergeConfig, normalizePath } from 'vite'
|
||||||
import { getElectronNodeTarget, getElectronChromeTarget } from '../electron'
|
import type { OutputOptions } from 'rollup'
|
||||||
|
import { getElectronNodeTarget, getElectronChromeTarget, supportESM } from '../electron'
|
||||||
|
import { loadPackageData } from '../utils'
|
||||||
|
|
||||||
export interface ElectronPluginOptions {
|
export interface ElectronPluginOptions {
|
||||||
root?: string
|
root?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function findLibEntry(root: string, scope: string): string {
|
function findLibEntry(root: string, scope: string): string | undefined {
|
||||||
for (const name of ['index', scope]) {
|
for (const name of ['index', scope]) {
|
||||||
for (const ext of ['js', 'ts', 'mjs', 'cjs']) {
|
for (const ext of ['js', 'ts', 'mjs', 'cjs']) {
|
||||||
const entryFile = path.resolve(root, 'src', scope, `${name}.${ext}`)
|
const entryFile = path.resolve(root, 'src', scope, `${name}.${ext}`)
|
||||||
@ -18,7 +20,7 @@ function findLibEntry(root: string, scope: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ''
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
function findInput(root: string, scope = 'renderer'): string {
|
function findInput(root: string, scope = 'renderer'): string {
|
||||||
@ -29,6 +31,25 @@ function findInput(root: string, scope = 'renderer'): string {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processEnvDefine(): Record<string, string> {
|
||||||
|
return {
|
||||||
|
'process.env': `process.env`,
|
||||||
|
'global.process.env': `global.process.env`,
|
||||||
|
'globalThis.process.env': `globalThis.process.env`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveBuildOutputs(
|
||||||
|
outputs: OutputOptions | OutputOptions[] | undefined,
|
||||||
|
libOptions: LibraryOptions | false
|
||||||
|
): OutputOptions | OutputOptions[] | undefined {
|
||||||
|
if (libOptions && !Array.isArray(outputs)) {
|
||||||
|
const libFormats = libOptions.formats || []
|
||||||
|
return libFormats.map(format => ({ ...outputs, format }))
|
||||||
|
}
|
||||||
|
return outputs
|
||||||
|
}
|
||||||
|
|
||||||
export function electronMainVitePlugin(options?: ElectronPluginOptions): Plugin[] {
|
export function electronMainVitePlugin(options?: ElectronPluginOptions): Plugin[] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@ -40,16 +61,23 @@ export function electronMainVitePlugin(options?: ElectronPluginOptions): Plugin[
|
|||||||
|
|
||||||
const nodeTarget = getElectronNodeTarget()
|
const nodeTarget = getElectronNodeTarget()
|
||||||
|
|
||||||
|
const pkg = loadPackageData() || { type: 'commonjs' }
|
||||||
|
|
||||||
|
const format = pkg.type && pkg.type === 'module' && supportESM() ? 'es' : 'cjs'
|
||||||
|
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
|
resolve: {
|
||||||
|
browserField: false,
|
||||||
|
mainFields: ['module', 'jsnext:main', 'jsnext'],
|
||||||
|
conditions: ['node']
|
||||||
|
},
|
||||||
build: {
|
build: {
|
||||||
outDir: path.resolve(root, 'out', 'main'),
|
outDir: path.resolve(root, 'out', 'main'),
|
||||||
target: nodeTarget,
|
target: nodeTarget,
|
||||||
assetsDir: 'chunks',
|
assetsDir: 'chunks',
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])],
|
external: ['electron', /^electron\/.+/, ...builtinModules.flatMap(m => [m, `node:${m}`])],
|
||||||
output: {
|
output: {}
|
||||||
entryFileNames: '[name].js'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
reportCompressedSize: false,
|
reportCompressedSize: false,
|
||||||
minify: false
|
minify: false
|
||||||
@ -59,12 +87,21 @@ export function electronMainVitePlugin(options?: ElectronPluginOptions): Plugin[
|
|||||||
const build = config.build || {}
|
const build = config.build || {}
|
||||||
const rollupOptions = build.rollupOptions || {}
|
const rollupOptions = build.rollupOptions || {}
|
||||||
if (!rollupOptions.input) {
|
if (!rollupOptions.input) {
|
||||||
|
const libOptions = build.lib
|
||||||
|
const outputOptions = rollupOptions.output
|
||||||
defaultConfig.build['lib'] = {
|
defaultConfig.build['lib'] = {
|
||||||
entry: findLibEntry(root, 'main'),
|
entry: findLibEntry(root, 'main'),
|
||||||
formats: ['cjs']
|
formats:
|
||||||
|
libOptions && libOptions.formats && libOptions.formats.length > 0
|
||||||
|
? []
|
||||||
|
: [
|
||||||
|
outputOptions && !Array.isArray(outputOptions) && outputOptions.format
|
||||||
|
? outputOptions.format
|
||||||
|
: format
|
||||||
|
]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defaultConfig.build.rollupOptions.output['format'] = 'cjs'
|
defaultConfig.build.rollupOptions.output['format'] = format
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig.build.rollupOptions.output['assetFileNames'] = path.posix.join(
|
defaultConfig.build.rollupOptions.output['assetFileNames'] = path.posix.join(
|
||||||
@ -75,13 +112,22 @@ export function electronMainVitePlugin(options?: ElectronPluginOptions): Plugin[
|
|||||||
const buildConfig = mergeConfig(defaultConfig.build, build)
|
const buildConfig = mergeConfig(defaultConfig.build, build)
|
||||||
config.build = buildConfig
|
config.build = buildConfig
|
||||||
|
|
||||||
config.envPrefix = config.envPrefix || 'MAIN_VITE_'
|
config.resolve = mergeConfig(defaultConfig.resolve, config.resolve || {})
|
||||||
|
|
||||||
|
config.define = config.define || {}
|
||||||
|
config.define = { ...processEnvDefine(), ...config.define }
|
||||||
|
|
||||||
|
config.envPrefix = config.envPrefix || ['MAIN_VITE_', 'VITE_']
|
||||||
|
|
||||||
config.publicDir = config.publicDir || 'resources'
|
config.publicDir = config.publicDir || 'resources'
|
||||||
// do not copy public dir
|
// do not copy public dir
|
||||||
config.build.copyPublicDir = false
|
config.build.copyPublicDir = false
|
||||||
// module preload polyfill does not apply to nodejs (main process)
|
// module preload polyfill does not apply to nodejs (main process)
|
||||||
config.build.modulePreload = false
|
config.build.modulePreload = false
|
||||||
|
// enable ssr build
|
||||||
|
config.build.ssr = true
|
||||||
|
config.build.ssrEmitAssets = true
|
||||||
|
config.ssr = { ...config.ssr, ...{ noExternal: true } }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -91,36 +137,44 @@ export function electronMainVitePlugin(options?: ElectronPluginOptions): Plugin[
|
|||||||
configResolved(config): void {
|
configResolved(config): void {
|
||||||
const build = config.build
|
const build = config.build
|
||||||
if (!build.target) {
|
if (!build.target) {
|
||||||
throw new Error('build target required for the electron vite main config')
|
throw new Error('build.target option is required in the electron vite main config.')
|
||||||
} else {
|
} else {
|
||||||
const targets = Array.isArray(build.target) ? build.target : [build.target]
|
const targets = Array.isArray(build.target) ? build.target : [build.target]
|
||||||
if (targets.some(t => !t.startsWith('node'))) {
|
if (targets.some(t => !t.startsWith('node'))) {
|
||||||
throw new Error('the electron vite main config build target must be node')
|
throw new Error('The electron vite main config build.target option must be "node?".')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const lib = build.lib
|
const libOptions = build.lib
|
||||||
if (!lib) {
|
|
||||||
const rollupOptions = build.rollupOptions
|
const rollupOptions = build.rollupOptions
|
||||||
if (!rollupOptions?.input) {
|
|
||||||
throw new Error('build lib field required for the electron vite main config')
|
if (!(libOptions && libOptions.entry) && !rollupOptions?.input) {
|
||||||
|
throw new Error(
|
||||||
|
'An entry point is required in the electron vite main config, ' +
|
||||||
|
'which can be specified using "build.lib.entry" or "build.rollupOptions.input".'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedOutputs = resolveBuildOutputs(rollupOptions.output, libOptions)
|
||||||
|
|
||||||
|
if (resolvedOutputs) {
|
||||||
|
const outputs = Array.isArray(resolvedOutputs) ? resolvedOutputs : [resolvedOutputs]
|
||||||
|
if (outputs.length > 1) {
|
||||||
|
throw new Error('The electron vite main config does not support multiple outputs.')
|
||||||
} else {
|
} else {
|
||||||
const output = rollupOptions?.output
|
const outpout = outputs[0]
|
||||||
if (output) {
|
if (['es', 'cjs'].includes(outpout.format || '')) {
|
||||||
const formats = Array.isArray(output) ? output : [output]
|
if (outpout.format === 'es' && !supportESM()) {
|
||||||
if (formats.some(f => f.format !== 'cjs')) {
|
throw new Error(
|
||||||
throw new Error('the electron vite main config output format must be cjs')
|
'The electron vite main config output format does not support "es", ' +
|
||||||
}
|
'you can upgrade electron to the latest version or switch to "cjs" format.'
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!lib.entry) {
|
throw new Error(
|
||||||
throw new Error('build entry field required for the electron vite main config')
|
`The electron vite main config output format must be "cjs"${supportESM() ? ' or "es"' : ''}.`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (!lib.formats) {
|
|
||||||
throw new Error('build format field required for the electron vite main config')
|
|
||||||
} else if (!lib.formats.includes('cjs')) {
|
|
||||||
throw new Error('the electron vite main config build lib format must be cjs')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,16 +193,24 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
|
|||||||
|
|
||||||
const nodeTarget = getElectronNodeTarget()
|
const nodeTarget = getElectronNodeTarget()
|
||||||
|
|
||||||
|
const pkg = loadPackageData() || { type: 'commonjs' }
|
||||||
|
|
||||||
|
const format = pkg.type && pkg.type === 'module' && supportESM() ? 'es' : 'cjs'
|
||||||
|
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
|
ssr: {
|
||||||
|
resolve: {
|
||||||
|
conditions: ['module', 'browser', 'development|production'],
|
||||||
|
mainFields: ['browser', 'module', 'jsnext:main', 'jsnext']
|
||||||
|
}
|
||||||
|
},
|
||||||
build: {
|
build: {
|
||||||
outDir: path.resolve(root, 'out', 'preload'),
|
outDir: path.resolve(root, 'out', 'preload'),
|
||||||
target: nodeTarget,
|
target: nodeTarget,
|
||||||
assetsDir: 'chunks',
|
assetsDir: 'chunks',
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])],
|
external: ['electron', /^electron\/.+/, ...builtinModules.flatMap(m => [m, `node:${m}`])],
|
||||||
output: {
|
output: {}
|
||||||
entryFileNames: '[name].js'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
reportCompressedSize: false,
|
reportCompressedSize: false,
|
||||||
minify: false
|
minify: false
|
||||||
@ -158,12 +220,21 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
|
|||||||
const build = config.build || {}
|
const build = config.build || {}
|
||||||
const rollupOptions = build.rollupOptions || {}
|
const rollupOptions = build.rollupOptions || {}
|
||||||
if (!rollupOptions.input) {
|
if (!rollupOptions.input) {
|
||||||
|
const libOptions = build.lib
|
||||||
|
const outputOptions = rollupOptions.output
|
||||||
defaultConfig.build['lib'] = {
|
defaultConfig.build['lib'] = {
|
||||||
entry: findLibEntry(root, 'preload'),
|
entry: findLibEntry(root, 'preload'),
|
||||||
formats: ['cjs']
|
formats:
|
||||||
|
libOptions && libOptions.formats && libOptions.formats.length > 0
|
||||||
|
? []
|
||||||
|
: [
|
||||||
|
outputOptions && !Array.isArray(outputOptions) && outputOptions.format
|
||||||
|
? outputOptions.format
|
||||||
|
: format
|
||||||
|
]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defaultConfig.build.rollupOptions.output['format'] = 'cjs'
|
defaultConfig.build.rollupOptions.output['format'] = format
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig.build.rollupOptions.output['assetFileNames'] = path.posix.join(
|
defaultConfig.build.rollupOptions.output['assetFileNames'] = path.posix.join(
|
||||||
@ -174,13 +245,41 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
|
|||||||
const buildConfig = mergeConfig(defaultConfig.build, build)
|
const buildConfig = mergeConfig(defaultConfig.build, build)
|
||||||
config.build = buildConfig
|
config.build = buildConfig
|
||||||
|
|
||||||
config.envPrefix = config.envPrefix || 'PRELOAD_VITE_'
|
const resolvedOutputs = resolveBuildOutputs(config.build.rollupOptions!.output, config.build.lib || false)
|
||||||
|
|
||||||
|
if (resolvedOutputs) {
|
||||||
|
const outputs = Array.isArray(resolvedOutputs) ? resolvedOutputs : [resolvedOutputs]
|
||||||
|
|
||||||
|
if (outputs.find(({ format }) => format === 'es')) {
|
||||||
|
if (Array.isArray(config.build.rollupOptions!.output)) {
|
||||||
|
config.build.rollupOptions!.output.forEach(output => {
|
||||||
|
if (output.format === 'es') {
|
||||||
|
output['entryFileNames'] = '[name].mjs'
|
||||||
|
output['chunkFileNames'] = '[name]-[hash].mjs'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
config.build.rollupOptions!.output!['entryFileNames'] = '[name].mjs'
|
||||||
|
config.build.rollupOptions!.output!['chunkFileNames'] = '[name]-[hash].mjs'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config.define = config.define || {}
|
||||||
|
config.define = { ...processEnvDefine(), ...config.define }
|
||||||
|
|
||||||
|
config.envPrefix = config.envPrefix || ['PRELOAD_VITE_', 'VITE_']
|
||||||
|
|
||||||
config.publicDir = config.publicDir || 'resources'
|
config.publicDir = config.publicDir || 'resources'
|
||||||
// do not copy public dir
|
// do not copy public dir
|
||||||
config.build.copyPublicDir = false
|
config.build.copyPublicDir = false
|
||||||
// module preload polyfill does not apply to nodejs (preload scripts)
|
// module preload polyfill does not apply to nodejs (preload scripts)
|
||||||
config.build.modulePreload = false
|
config.build.modulePreload = false
|
||||||
|
// enable ssr build
|
||||||
|
config.build.ssr = true
|
||||||
|
config.build.ssrEmitAssets = true
|
||||||
|
config.ssr = mergeConfig(defaultConfig.ssr, config.ssr || {})
|
||||||
|
config.ssr.noExternal = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -190,36 +289,44 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
|
|||||||
configResolved(config): void {
|
configResolved(config): void {
|
||||||
const build = config.build
|
const build = config.build
|
||||||
if (!build.target) {
|
if (!build.target) {
|
||||||
throw new Error('build target required for the electron vite preload config')
|
throw new Error('build.target option is required in the electron vite preload config.')
|
||||||
} else {
|
} else {
|
||||||
const targets = Array.isArray(build.target) ? build.target : [build.target]
|
const targets = Array.isArray(build.target) ? build.target : [build.target]
|
||||||
if (targets.some(t => !t.startsWith('node'))) {
|
if (targets.some(t => !t.startsWith('node'))) {
|
||||||
throw new Error('the electron vite preload config build target must be node')
|
throw new Error('The electron vite preload config build.target must be "node?".')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const lib = build.lib
|
const libOptions = build.lib
|
||||||
if (!lib) {
|
|
||||||
const rollupOptions = build.rollupOptions
|
const rollupOptions = build.rollupOptions
|
||||||
if (!rollupOptions?.input) {
|
|
||||||
throw new Error('build lib field required for the electron vite preload config')
|
if (!(libOptions && libOptions.entry) && !rollupOptions?.input) {
|
||||||
|
throw new Error(
|
||||||
|
'An entry point is required in the electron vite preload config, ' +
|
||||||
|
'which can be specified using "build.lib.entry" or "build.rollupOptions.input".'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedOutputs = resolveBuildOutputs(rollupOptions.output, libOptions)
|
||||||
|
|
||||||
|
if (resolvedOutputs) {
|
||||||
|
const outputs = Array.isArray(resolvedOutputs) ? resolvedOutputs : [resolvedOutputs]
|
||||||
|
if (outputs.length > 1) {
|
||||||
|
throw new Error('The electron vite preload config does not support multiple outputs.')
|
||||||
} else {
|
} else {
|
||||||
const output = rollupOptions?.output
|
const outpout = outputs[0]
|
||||||
if (output) {
|
if (['es', 'cjs'].includes(outpout.format || '')) {
|
||||||
const formats = Array.isArray(output) ? output : [output]
|
if (outpout.format === 'es' && !supportESM()) {
|
||||||
if (formats.some(f => f.format !== 'cjs')) {
|
throw new Error(
|
||||||
throw new Error('the electron vite preload config output format must be cjs')
|
'The electron vite preload config output format does not support "es", ' +
|
||||||
}
|
'you can upgrade electron to the latest version or switch to "cjs" format.'
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!lib.entry) {
|
throw new Error(
|
||||||
throw new Error('build entry field required for the electron vite preload config')
|
`The electron vite preload config output format must be "cjs"${supportESM() ? ' or "es"' : ''}.`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (!lib.formats) {
|
|
||||||
throw new Error('build format field required for the electron vite preload config')
|
|
||||||
} else if (!lib.formats.includes('cjs')) {
|
|
||||||
throw new Error('the electron vite preload config lib format must be cjs')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,7 +383,7 @@ export function electronRendererVitePlugin(options?: ElectronPluginOptions): Plu
|
|||||||
|
|
||||||
config.envDir = config.envDir || path.resolve(root)
|
config.envDir = config.envDir || path.resolve(root)
|
||||||
|
|
||||||
config.envPrefix = config.envPrefix || 'RENDERER_VITE_'
|
config.envPrefix = config.envPrefix || ['RENDERER_VITE_', 'VITE_']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -284,23 +391,25 @@ export function electronRendererVitePlugin(options?: ElectronPluginOptions): Plu
|
|||||||
enforce: 'post',
|
enforce: 'post',
|
||||||
configResolved(config): void {
|
configResolved(config): void {
|
||||||
if (config.base !== './' && config.base !== '/') {
|
if (config.base !== './' && config.base !== '/') {
|
||||||
config.logger.warn(colors.yellow('should not set base field for the electron vite renderer config'))
|
config.logger.warn(colors.yellow('(!) Should not set "base" option for the electron vite renderer config.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
const build = config.build
|
const build = config.build
|
||||||
if (!build.target) {
|
if (!build.target) {
|
||||||
throw new Error('build target required for the electron vite renderer config')
|
throw new Error('build.target option is required in the electron vite renderer config.')
|
||||||
} else {
|
} else {
|
||||||
const targets = Array.isArray(build.target) ? build.target : [build.target]
|
const targets = Array.isArray(build.target) ? build.target : [build.target]
|
||||||
if (targets.some(t => !t.startsWith('chrome'))) {
|
if (targets.some(t => !t.startsWith('chrome') && !/^es((202\d{1})|next)$/.test(t))) {
|
||||||
throw new Error('the electron vite renderer config build target must be chrome')
|
config.logger.warn(
|
||||||
|
'The electron vite renderer config build.target is not "chrome?" or "es?". This could be a mistake.'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const rollupOptions = build.rollupOptions
|
const rollupOptions = build.rollupOptions
|
||||||
if (!rollupOptions.input) {
|
if (!rollupOptions.input) {
|
||||||
config.logger.warn(colors.yellow(`index.html file is not found in ${colors.dim('/src/renderer')} directory`))
|
config.logger.warn(colors.yellow(`index.html file is not found in ${colors.dim('/src/renderer')} directory.`))
|
||||||
throw new Error('build rollupOptions input field required for the electron vite renderer config')
|
throw new Error('build.rollupOptions.input option is required in the electron vite renderer config.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
79
src/plugins/esm.ts
Normal file
79
src/plugins/esm.ts
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* The core of this plugin was conceived by pi0 and is taken from the following repository:
|
||||||
|
* https://github.com/unjs/unbuild/blob/main/src/builder/plugins/cjs.ts
|
||||||
|
* license: https://github.com/unjs/unbuild/blob/main/LICENSE
|
||||||
|
*/
|
||||||
|
|
||||||
|
import MagicString from 'magic-string'
|
||||||
|
import type { SourceMapInput } from 'rollup'
|
||||||
|
import type { Plugin } from 'vite'
|
||||||
|
|
||||||
|
import { getElectronMajorVersion } from '../electron'
|
||||||
|
|
||||||
|
const CJSyntaxRe = /__filename|__dirname|require\(|require\.resolve\(/
|
||||||
|
|
||||||
|
const CJSShim_normal = `
|
||||||
|
// -- CommonJS Shims --
|
||||||
|
import __cjs_url__ from 'node:url';
|
||||||
|
import __cjs_path__ from 'node:path';
|
||||||
|
import __cjs_mod__ from 'node:module';
|
||||||
|
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = __cjs_path__.dirname(__filename);
|
||||||
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
||||||
|
`
|
||||||
|
|
||||||
|
const CJSShim_node_20_11 = `
|
||||||
|
// -- CommonJS Shims --
|
||||||
|
import __cjs_mod__ from 'node:module';
|
||||||
|
const __filename = import.meta.filename;
|
||||||
|
const __dirname = import.meta.dirname;
|
||||||
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
||||||
|
`
|
||||||
|
|
||||||
|
const ESMStaticImportRe =
|
||||||
|
/(?<=\s|^|;)import\s*([\s"']*(?<imports>[\p{L}\p{M}\w\t\n\r $*,/{}@.]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gmu
|
||||||
|
|
||||||
|
interface StaticImport {
|
||||||
|
end: number
|
||||||
|
}
|
||||||
|
|
||||||
|
function findStaticImports(code: string): StaticImport[] {
|
||||||
|
const matches: StaticImport[] = []
|
||||||
|
for (const match of code.matchAll(ESMStaticImportRe)) {
|
||||||
|
matches.push({ end: (match.index || 0) + match[0].length })
|
||||||
|
}
|
||||||
|
return matches
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function esmShimPlugin(): Plugin {
|
||||||
|
let sourcemap: boolean | 'inline' | 'hidden' = false
|
||||||
|
|
||||||
|
const CJSShim = getElectronMajorVersion() >= 30 ? CJSShim_node_20_11 : CJSShim_normal
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: 'vite:esm-shim',
|
||||||
|
apply: 'build',
|
||||||
|
enforce: 'post',
|
||||||
|
configResolved(config): void {
|
||||||
|
sourcemap = config.build.sourcemap
|
||||||
|
},
|
||||||
|
renderChunk(code, _chunk, options): { code: string; map?: SourceMapInput } | null {
|
||||||
|
if (options.format === 'es') {
|
||||||
|
if (code.includes(CJSShim) || !CJSyntaxRe.test(code)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastESMImport = findStaticImports(code).pop()
|
||||||
|
const indexToAppend = lastESMImport ? lastESMImport.end : 0
|
||||||
|
const s = new MagicString(code)
|
||||||
|
s.appendRight(indexToAppend, CJSShim)
|
||||||
|
return {
|
||||||
|
code: s.toString(),
|
||||||
|
map: sourcemap ? s.generateMap({ hires: 'boundary' }) : null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
import path from 'node:path'
|
|
||||||
import { createRequire } from 'node:module'
|
|
||||||
import { type Plugin, mergeConfig } from 'vite'
|
import { type Plugin, mergeConfig } from 'vite'
|
||||||
|
import { loadPackageData } from '../utils'
|
||||||
|
|
||||||
export interface ExternalOptions {
|
export interface ExternalOptions {
|
||||||
exclude?: string[]
|
exclude?: string[]
|
||||||
@ -13,19 +12,19 @@ export interface ExternalOptions {
|
|||||||
export function externalizeDepsPlugin(options: ExternalOptions = {}): Plugin | null {
|
export function externalizeDepsPlugin(options: ExternalOptions = {}): Plugin | null {
|
||||||
const { exclude = [], include = [] } = options
|
const { exclude = [], include = [] } = options
|
||||||
|
|
||||||
const packagePath = path.resolve(process.cwd(), 'package.json')
|
const pkg = loadPackageData() || {}
|
||||||
const require = createRequire(import.meta.url)
|
|
||||||
const pkg = require(packagePath)
|
|
||||||
let deps = Object.keys(pkg.dependencies || {})
|
let deps = Object.keys(pkg.dependencies || {})
|
||||||
|
|
||||||
if (include.length) {
|
if (include.length) {
|
||||||
deps = deps.concat(include)
|
deps = deps.concat(include.filter(dep => dep.trim() !== ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exclude.length) {
|
if (exclude.length) {
|
||||||
deps = deps.filter(dep => !exclude.includes(dep))
|
deps = deps.filter(dep => !exclude.includes(dep))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deps = [...new Set(deps)]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'vite:externalize-deps',
|
name: 'vite:externalize-deps',
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
@ -33,7 +32,7 @@ export function externalizeDepsPlugin(options: ExternalOptions = {}): Plugin | n
|
|||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
build: {
|
build: {
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: [...new Set(deps)]
|
external: deps.length > 0 ? [...deps, new RegExp(`^(${deps.join('|')})/.+`)] : []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
src/plugins/importMeta.ts
Normal file
21
src/plugins/importMeta.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import type { Plugin } from 'vite'
|
||||||
|
|
||||||
|
export default function importMetaPlugin(): Plugin {
|
||||||
|
return {
|
||||||
|
name: 'vite:import-meta',
|
||||||
|
apply: 'build',
|
||||||
|
enforce: 'pre',
|
||||||
|
resolveImportMeta(property, { format }): string | null {
|
||||||
|
if (property === 'url' && format === 'cjs') {
|
||||||
|
return `require("url").pathToFileURL(__filename).href`
|
||||||
|
}
|
||||||
|
if (property === 'filename' && format === 'cjs') {
|
||||||
|
return `__filename`
|
||||||
|
}
|
||||||
|
if (property === 'dirname' && format === 'cjs') {
|
||||||
|
return `__dirname`
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
65
src/plugins/modulePath.ts
Normal file
65
src/plugins/modulePath.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import type { Plugin } from 'vite'
|
||||||
|
import type { SourceMapInput } from 'rollup'
|
||||||
|
import MagicString from 'magic-string'
|
||||||
|
import { cleanUrl, parseRequest, toRelativePath } from '../utils'
|
||||||
|
|
||||||
|
const modulePathRE = /__VITE_MODULE_PATH__([\w$]+)__/g
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve `?modulePath` import and return the module bundle path.
|
||||||
|
*/
|
||||||
|
export default function modulePathPlugin(): Plugin {
|
||||||
|
let sourcemap: boolean | 'inline' | 'hidden' = false
|
||||||
|
return {
|
||||||
|
name: 'vite:module-path',
|
||||||
|
apply: 'build',
|
||||||
|
enforce: 'pre',
|
||||||
|
configResolved(config): void {
|
||||||
|
sourcemap = config.build.sourcemap
|
||||||
|
},
|
||||||
|
resolveId(id, importer): string | void {
|
||||||
|
const query = parseRequest(id)
|
||||||
|
if (query && typeof query.modulePath === 'string') {
|
||||||
|
return id + `&importer=${importer}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
load(id): string | void {
|
||||||
|
const query = parseRequest(id)
|
||||||
|
if (query && typeof query.modulePath === 'string' && typeof query.importer === 'string') {
|
||||||
|
const cleanPath = cleanUrl(id)
|
||||||
|
const hash = this.emitFile({
|
||||||
|
type: 'chunk',
|
||||||
|
id: cleanPath,
|
||||||
|
importer: query.importer
|
||||||
|
})
|
||||||
|
const refId = `__VITE_MODULE_PATH__${hash}__`
|
||||||
|
return `
|
||||||
|
import { join } from 'path'
|
||||||
|
export default join(__dirname, ${refId})`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
renderChunk(code, chunk): { code: string; map: SourceMapInput } | null {
|
||||||
|
if (code.match(modulePathRE)) {
|
||||||
|
let match: RegExpExecArray | null
|
||||||
|
const s = new MagicString(code)
|
||||||
|
|
||||||
|
while ((match = modulePathRE.exec(code))) {
|
||||||
|
const [full, hash] = match
|
||||||
|
const filename = this.getFileName(hash)
|
||||||
|
const outputFilepath = toRelativePath(filename, chunk.fileName)
|
||||||
|
const replacement = JSON.stringify(outputFilepath)
|
||||||
|
s.overwrite(match.index, match.index + full.length, replacement, {
|
||||||
|
contentOnly: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: s.toString(),
|
||||||
|
map: sourcemap ? s.generateMap({ hires: 'boundary' }) : null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ import type { SourceMapInput } from 'rollup'
|
|||||||
import MagicString from 'magic-string'
|
import MagicString from 'magic-string'
|
||||||
import { cleanUrl, parseRequest, toRelativePath } from '../utils'
|
import { cleanUrl, parseRequest, toRelativePath } from '../utils'
|
||||||
|
|
||||||
const nodeWorkerAssetUrlRE = /__VITE_NODE_WORKER_ASSET__([a-z\d]{8})__/g
|
const nodeWorkerAssetUrlRE = /__VITE_NODE_WORKER_ASSET__([\w$]+)__/g
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve `?nodeWorker` import and automatically generate `Worker` wrapper.
|
* Resolve `?nodeWorker` import and automatically generate `Worker` wrapper.
|
||||||
@ -35,7 +35,7 @@ export default function workerPlugin(): Plugin {
|
|||||||
const assetRefId = `__VITE_NODE_WORKER_ASSET__${hash}__`
|
const assetRefId = `__VITE_NODE_WORKER_ASSET__${hash}__`
|
||||||
return `
|
return `
|
||||||
import { Worker } from 'node:worker_threads';
|
import { Worker } from 'node:worker_threads';
|
||||||
export default function (options) { return new Worker(require.resolve(${assetRefId}), options); }`
|
export default function (options) { return new Worker(new URL(${assetRefId}, import.meta.url), options); }`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
renderChunk(code, chunk): { code: string; map: SourceMapInput } | null {
|
renderChunk(code, chunk): { code: string; map: SourceMapInput } | null {
|
||||||
@ -55,7 +55,7 @@ export default function workerPlugin(): Plugin {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
code: s.toString(),
|
code: s.toString(),
|
||||||
map: sourcemap ? s.generateMap({ hires: true }) : null
|
map: sourcemap ? s.generateMap({ hires: 'boundary' }) : null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ export async function preview(inlineConfig: InlineConfig = {}, options: { skipBu
|
|||||||
|
|
||||||
const logger = createLogger(inlineConfig.logLevel)
|
const logger = createLogger(inlineConfig.logLevel)
|
||||||
|
|
||||||
startElectron(inlineConfig.root, logger)
|
startElectron(inlineConfig.root)
|
||||||
|
|
||||||
logger.info(colors.green(`\nstart electron app...\n`))
|
logger.info(colors.green(`\nstart electron app...\n`))
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import type { ChildProcessWithoutNullStreams } from 'node:child_process'
|
import type { ChildProcess } from 'node:child_process'
|
||||||
import {
|
import {
|
||||||
type UserConfig as ViteConfig,
|
type UserConfig as ViteConfig,
|
||||||
type ViteDevServer,
|
type ViteDevServer,
|
||||||
createServer as ViteCreateServer,
|
createServer as viteCreateServer,
|
||||||
build as viteBuild,
|
build as viteBuild,
|
||||||
createLogger,
|
createLogger,
|
||||||
mergeConfig
|
mergeConfig
|
||||||
@ -22,7 +22,11 @@ export async function createServer(
|
|||||||
const logger = createLogger(inlineConfig.logLevel)
|
const logger = createLogger(inlineConfig.logLevel)
|
||||||
|
|
||||||
let server: ViteDevServer | undefined
|
let server: ViteDevServer | undefined
|
||||||
let ps: ChildProcessWithoutNullStreams | undefined
|
let ps: ChildProcess | undefined
|
||||||
|
|
||||||
|
const errorHook = (e): void => {
|
||||||
|
logger.error(`${colors.bgRed(colors.white(' ERROR '))} ${colors.red(e.message)}`)
|
||||||
|
}
|
||||||
|
|
||||||
const mainViteConfig = config.config?.main
|
const mainViteConfig = config.config?.main
|
||||||
if (mainViteConfig && !options.rendererOnly) {
|
if (mainViteConfig && !options.rendererOnly) {
|
||||||
@ -34,13 +38,13 @@ export async function createServer(
|
|||||||
|
|
||||||
ps.removeAllListeners()
|
ps.removeAllListeners()
|
||||||
ps.kill()
|
ps.kill()
|
||||||
ps = startElectron(inlineConfig.root, logger)
|
ps = startElectron(inlineConfig.root)
|
||||||
|
|
||||||
logger.info(colors.green(`\nrestart electron app...`))
|
logger.info(colors.green(`\nrestart electron app...`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await doBuild(mainViteConfig, watchHook)
|
await doBuild(mainViteConfig, watchHook, errorHook)
|
||||||
|
|
||||||
logger.info(colors.green(`\nbuild the electron main process successfully`))
|
logger.info(colors.green(`\nbuild the electron main process successfully`))
|
||||||
}
|
}
|
||||||
@ -59,7 +63,7 @@ export async function createServer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await doBuild(preloadViteConfig, watchHook)
|
await doBuild(preloadViteConfig, watchHook, errorHook)
|
||||||
|
|
||||||
logger.info(colors.green(`\nbuild the electron preload files successfully`))
|
logger.info(colors.green(`\nbuild the electron preload files successfully`))
|
||||||
}
|
}
|
||||||
@ -76,7 +80,7 @@ export async function createServer(
|
|||||||
if (rendererViteConfig) {
|
if (rendererViteConfig) {
|
||||||
logger.info(colors.gray(`\n-----\n`))
|
logger.info(colors.gray(`\n-----\n`))
|
||||||
|
|
||||||
server = await ViteCreateServer(rendererViteConfig)
|
server = await viteCreateServer(rendererViteConfig)
|
||||||
|
|
||||||
if (!server.httpServer) {
|
if (!server.httpServer) {
|
||||||
throw new Error('HTTP server not available')
|
throw new Error('HTTP server not available')
|
||||||
@ -100,7 +104,7 @@ export async function createServer(
|
|||||||
server.printUrls()
|
server.printUrls()
|
||||||
}
|
}
|
||||||
|
|
||||||
ps = startElectron(inlineConfig.root, logger)
|
ps = startElectron(inlineConfig.root)
|
||||||
|
|
||||||
logger.info(colors.green(`\nstart electron app...\n`))
|
logger.info(colors.green(`\nstart electron app...\n`))
|
||||||
}
|
}
|
||||||
@ -108,7 +112,7 @@ export async function createServer(
|
|||||||
|
|
||||||
type UserConfig = ViteConfig & { configFile?: string | false }
|
type UserConfig = ViteConfig & { configFile?: string | false }
|
||||||
|
|
||||||
async function doBuild(config: UserConfig, watchHook: () => void): Promise<void> {
|
async function doBuild(config: UserConfig, watchHook: () => void, errorHook: (e: Error) => void): Promise<void> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
if (config.build?.watch) {
|
if (config.build?.watch) {
|
||||||
let firstBundle = true
|
let firstBundle = true
|
||||||
@ -131,10 +135,12 @@ async function doBuild(config: UserConfig, watchHook: () => void): Promise<void>
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
viteBuild(config).then(() => {
|
viteBuild(config)
|
||||||
|
.then(() => {
|
||||||
if (!config.build?.watch) {
|
if (!config.build?.watch) {
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.catch(e => errorHook(e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
50
src/utils.ts
50
src/utils.ts
@ -1,14 +1,14 @@
|
|||||||
import { URL, URLSearchParams } from 'node:url'
|
import { URL, URLSearchParams } from 'node:url'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
import fs from 'node:fs'
|
||||||
import { createHash } from 'node:crypto'
|
import { createHash } from 'node:crypto'
|
||||||
|
import { createRequire } from 'node:module'
|
||||||
import { loadEnv as viteLoadEnv } from 'vite'
|
import { loadEnv as viteLoadEnv } from 'vite'
|
||||||
|
|
||||||
export function isObject(value: unknown): value is Record<string, unknown> {
|
export function isObject(value: unknown): value is Record<string, unknown> {
|
||||||
return Object.prototype.toString.call(value) === '[object Object]'
|
return Object.prototype.toString.call(value) === '[object Object]'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const dynamicImport = new Function('file', 'return import(file)')
|
|
||||||
|
|
||||||
export const wildcardHosts = new Set(['0.0.0.0', '::', '0000:0000:0000:0000:0000:0000:0000:0000'])
|
export const wildcardHosts = new Set(['0.0.0.0', '::', '0000:0000:0000:0000:0000:0000:0000:0000'])
|
||||||
|
|
||||||
export function resolveHostname(optionsHost: string | boolean | undefined): string {
|
export function resolveHostname(optionsHost: string | boolean | undefined): string {
|
||||||
@ -29,7 +29,10 @@ export function parseRequest(id: string): Record<string, string> | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getHash(text: Buffer | string): string {
|
export function getHash(text: Buffer | string): string {
|
||||||
return createHash('sha256').update(text).digest('hex').substring(0, 8)
|
return createHash('sha256')
|
||||||
|
.update(text as unknown as Uint8Array)
|
||||||
|
.digest('hex')
|
||||||
|
.substring(0, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toRelativePath(filename: string, importer: string): string {
|
export function toRelativePath(filename: string, importer: string): string {
|
||||||
@ -38,14 +41,49 @@ export function toRelativePath(filename: string, importer: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load `.env` files within the `envDir`(default: `process.cwd()`).
|
* Load `.env` files within the `envDir` (default: `process.cwd()`) .
|
||||||
* By default, only env variables prefixed with `MAIN_VITE_`, `PRELOAD_VITE_` and
|
* By default, only env variables prefixed with `VITE_`, `MAIN_VITE_`, `PRELOAD_VITE_` and
|
||||||
* `RENDERER_VITE_` are loaded, unless `prefixes` is changed.
|
* `RENDERER_VITE_` are loaded, unless `prefixes` is changed.
|
||||||
*/
|
*/
|
||||||
export function loadEnv(
|
export function loadEnv(
|
||||||
mode: string,
|
mode: string,
|
||||||
envDir: string = process.cwd(),
|
envDir: string = process.cwd(),
|
||||||
prefixes: string | string[] = ['MAIN_VITE_', 'PRELOAD_VITE_', 'RENDERER_VITE_']
|
prefixes: string | string[] = ['VITE_', 'MAIN_VITE_', 'PRELOAD_VITE_', 'RENDERER_VITE_']
|
||||||
): Record<string, string> {
|
): Record<string, string> {
|
||||||
return viteLoadEnv(mode, envDir, prefixes)
|
return viteLoadEnv(mode, envDir, prefixes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PackageData {
|
||||||
|
main?: string
|
||||||
|
type?: 'module' | 'commonjs'
|
||||||
|
dependencies?: Record<string, string>
|
||||||
|
}
|
||||||
|
|
||||||
|
let packageCached: PackageData | null = null
|
||||||
|
|
||||||
|
export function loadPackageData(root = process.cwd()): PackageData | null {
|
||||||
|
if (packageCached) return packageCached
|
||||||
|
const pkg = path.join(root, 'package.json')
|
||||||
|
if (fs.existsSync(pkg)) {
|
||||||
|
const _require = createRequire(import.meta.url)
|
||||||
|
const data = _require(pkg)
|
||||||
|
packageCached = {
|
||||||
|
main: data.main,
|
||||||
|
type: data.type,
|
||||||
|
dependencies: data.dependencies
|
||||||
|
}
|
||||||
|
return packageCached
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isFilePathESM(filePath: string): boolean {
|
||||||
|
if (/\.m[jt]s$/.test(filePath) || filePath.endsWith('.ts')) {
|
||||||
|
return true
|
||||||
|
} else if (/\.c[jt]s$/.test(filePath)) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
const pkg = loadPackageData()
|
||||||
|
return pkg?.type === 'module'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2019",
|
"target": "ES2023",
|
||||||
"module": "esnext",
|
"module": "ESNext",
|
||||||
"lib": ["esnext"],
|
"lib": ["ESNext"],
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "bundler",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true
|
||||||
"declaration": true,
|
|
||||||
"declarationDir": "dist/types",
|
|
||||||
"outDir": "dist"
|
|
||||||
},
|
},
|
||||||
"include": ["src"]
|
"include": ["src", "rollup.config.ts"]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user