Skip to content

Commit

Permalink
Feature: Vite Build MVP
Browse files Browse the repository at this point in the history
  • Loading branch information
VitroidFPV committed Sep 5, 2023
1 parent 2406205 commit 3cbfe25
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
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/*"],
};
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 @@ -81,6 +84,7 @@
"switchery-latest": "^0.8.2",
"three": "~0.97.0",
"universal-ga": "^1.2.0",
"vite-plugin-static-copy": "^0.17.0",
"vue": "^2.7.10"
},
"devDependencies": {
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
24 changes: 18 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 { viteStaticCopy } from "vite-plugin-static-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,25 @@ export default defineConfig({
include: ["test/**/*.test.{js,mjs,cjs}"],
environment: "jsdom",
setupFiles: ["test/setup.js"],
root: '.',
root: ".",
},
plugins: [vue(), serveLocalesPlugin()],
plugins: [
vue(),
serveLocalesPlugin(),
viteStaticCopy({
targets: [
{ src: "../locales", dest: "" },
{ src: "../resources", dest: "" },
{ src: "tabs", dest: "" },
{ src: "images", dest: "" },
],
}),
],
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"),
},
},
});
32 changes: 31 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4972,7 +4972,7 @@ check-error@^1.0.2:
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=

"chokidar@>=2.0.0 <4.0.0", chokidar@^3.4.1, chokidar@^3.4.2:
"chokidar@>=2.0.0 <4.0.0", chokidar@^3.4.1, chokidar@^3.4.2, chokidar@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd"
integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==
Expand Down Expand Up @@ -7397,6 +7397,17 @@ fast-glob@^3.1.1, fast-glob@^3.2.2:
merge2 "^1.3.0"
micromatch "^4.0.4"

fast-glob@^3.2.11:
version "3.3.1"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.1.tgz#784b4e897340f3dbbef17413b3f11acf03c874c4"
integrity sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==
dependencies:
"@nodelib/fs.stat" "^2.0.2"
"@nodelib/fs.walk" "^1.2.3"
glob-parent "^5.1.2"
merge2 "^1.3.0"
micromatch "^4.0.4"

fast-glob@^3.2.9:
version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
Expand Down Expand Up @@ -7824,6 +7835,15 @@ fs-extra@^10.1.0:
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^11.1.0:
version "11.1.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d"
integrity sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
Expand Down Expand Up @@ -16233,6 +16253,16 @@ vite-node@0.27.1:
source-map-support "^0.5.21"
vite "^3.0.0 || ^4.0.0"

vite-plugin-static-copy@^0.17.0:
version "0.17.0"
resolved "https://registry.yarnpkg.com/vite-plugin-static-copy/-/vite-plugin-static-copy-0.17.0.tgz#e45527da186c4a3818d09635797b6fc7cc9e035f"
integrity sha512-2HpNbHfDt8SDy393AGXh9llHkc8FJMQkI8s3T5WsH3SWLMO+f5cFIyPErl4yGKU9Uh3Vaqsd4lHZYTf042fQ2A==
dependencies:
chokidar "^3.5.3"
fast-glob "^3.2.11"
fs-extra "^11.1.0"
picocolors "^1.0.0"

"vite@^3.0.0 || ^4.0.0", vite@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/vite/-/vite-4.0.5.tgz#634f0bd1edf8bb8468ed42a1c3fd938c67d2f94b"
Expand Down

0 comments on commit 3cbfe25

Please sign in to comment.