Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Vite Build #3569

Merged
merged 6 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ module.exports = {
appAvailability: true,
// end cordova bindings
},
// ignore src/dist folders
ignorePatterns: ["src/dist/*"],
};
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ Betaflight Configurator has been translated into several languages. The applicat

If you prefer to have the application in English or any other language, you can select your desired language in the first screen of the application.

## App build via Vite (web)

### Development

1. Install node.js (refer to [.nvmrc](./.nvmrc) for required version)
2. Install yarn: `npm install yarn -g`
3. Change to project folder and run `yarn install`.
4. Run `yarn dev`.

The web app will be available at http://localhost:8000 with full HMR.

### Build Preview

1. Run `yarn build`.
2. Run `yarn preview` after build has finished.
3. Alternatively run `yarn review` to build and preview in one step.

The web app should behave directly as in production, available at http://localhost:8080.

## App build via NW.js (windows/linux/macos) or Cordova (android)

### Development
Expand Down Expand Up @@ -106,7 +125,7 @@ List of possible values of `<task-name>`:
* **dist** copies all the JS and CSS files in the `./dist` folder [2].
* **apps** builds the apps in the `./apps` folder [1].
* **debug** builds debug version of the apps in the `./debug` folder [1][3].
* **release** zips up the apps into individual archives in the `./release` folder [1].
* **release** zips up the apps into individual archives in the `./release` folder [1].

[1] Running this task on macOS or Linux requires Wine, since it's needed to set the icon for the Windows app (build for specific platform to avoid errors).
[2] For Android platform, **dist** task will generate folders and files in the `./dist_cordova` folder.
Expand All @@ -117,7 +136,7 @@ To build or release only for one specific platform you can append the plaform af
If no platform is provided, the build for the host platform is run.

* **MacOS X** use `yarn gulp <task-name> --osx64`
* **Linux** use `yarn gulp <task-name> --linux64`
* **Linux** use `yarn gulp <task-name> --linux64`
* **Windows** use `yarn gulp <task-name> --win64`
* **Android** use `yarn gulp <task-name> --android`

Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"chromium-args": "--disable-features=nw2",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"review": "vite build && vite preview",
"start": "run-script-os",
"start:default": "NODE_ENV=development NW_PRE_ARGS=--load-extension='./node_modules/nw-vue-devtools-prebuilt/extension' gulp debug",
"start:windows": "set NODE_ENV=development && set NW_PRE_ARGS=--load-extension='./node_modules/nw-vue-devtools-prebuilt/extension' && gulp debug",
Expand Down Expand Up @@ -120,6 +123,7 @@
"os": "^0.1.2",
"postcss": "^8.4.17",
"rollup": "^3.9.0",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-vue": "^5.*.*",
"rpm-builder": "^1.2.1",
"run-script-os": "^1.1.6",
Expand Down
6 changes: 3 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="author" content="cTn"/>

<script type="module" src="./src/js/utils/common.js"></script>
<script type="module" src="./src/js/browserMain.js"></script>
<script type="module" src="/src/js/utils/common.js"></script>
<script type="module" src="/src/js/browserMain.js"></script>

<title></title>
</head>
Expand Down Expand Up @@ -81,7 +81,7 @@
:batteryState="FC.BATTERY_STATE?.batteryState"
>
</battery-icon>
<battery-legend
<battery-legend
:voltage="FC.ANALOG.voltage"
:vbatmaxcellvoltage="FC.BATTERY_CONFIG.vbatmaxcellvoltage"
></battery-legend>
Expand Down
28 changes: 22 additions & 6 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue2";
import path from "node:path";
import { readFileSync } from "node:fs";
import copy from "rollup-plugin-copy";

function serveFileFromDirectory(directory) {
return (req, res, next) => {
Expand All @@ -23,7 +24,7 @@ function serveFileFromDirectory(directory) {
* This is plugin to work around the file structure required nwjs.
* In future this can be dropped if we restructure folder structure
* to be more web friendly.
* @returns {import('vite').Plugin}
* @returns {import("vite").Plugin}
*/
function serveLocalesPlugin() {
return {
Expand All @@ -32,9 +33,9 @@ function serveLocalesPlugin() {
return () => {
server.middlewares.use((req, res, next) => {
if (req.url.startsWith("/locales/")) {
serveFileFromDirectory('locales')(req, res, next);
serveFileFromDirectory("locales")(req, res, next);
} else if (req.url.startsWith("/resources/")) {
serveFileFromDirectory('resources')(req, res, next);
serveFileFromDirectory("resources")(req, res, next);
} else {
next();
}
Expand All @@ -52,14 +53,29 @@ export default defineConfig({
include: ["test/**/*.test.{js,mjs,cjs}"],
environment: "jsdom",
setupFiles: ["test/setup.js"],
root: '.',
root: ".",
},
plugins: [vue(), serveLocalesPlugin()],
plugins: [
vue(),
serveLocalesPlugin(),
copy({
targets: [
{ src: ["locales", "resources", "src/tabs", "src/images"], dest: "src/dist" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, guessing we can't have /dist in the root because of root setting in vite config 🤔 Having it in src feels like will backfire

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting and good catch. but it is ignored by default (.gitignore )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already set up that way in #3292. But yeah in src it will probably come back to bite us. What do you suggest?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we look into

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we look into

i don't really understand the errors. they do go away upon re-execution. they tend to only present themselves with new code/execution

],
hook: "writeBundle",
}),
],
root: "./src",
resolve: {
alias: {
"/src": path.resolve(process.cwd(), "src"),
'vue': path.resolve(__dirname, 'node_modules/vue/dist/vue.esm.js'),
"vue": path.resolve(__dirname, "node_modules/vue/dist/vue.esm.js"),
},
},
server: {
port: 8000,
},
preview: {
port: 8080,
},
});
Loading