diff --git a/directory/src/App.jsx b/directory/src/App.jsx
index 4f51250..1a8eaf9 100644
--- a/directory/src/App.jsx
+++ b/directory/src/App.jsx
@@ -8,27 +8,12 @@ import {
} from "react-router-dom";
import Root from "@/routes/root";
import ErrorPage from "@/routes/error-page";
-import Index from "@/routes/index";
-import Operator from "@/routes/operator";
+import routes from "@/routes";
import '@/App.css';
import 'reset-css';
document.title = import.meta.env.VITE_APP_TITLE;
-const routes = [
- {
- path: "",
- index: true,
- name: "Home",
- element:
- }, {
- path: "operator/:key",
- index: false,
- name: "Operator",
- element:
- }
-]
-
const router = createBrowserRouter(
createRoutesFromElements(
{
- fetch("/_assets/directory.json").then(res => res.json()).then(data => {
- console.log(data)
- })
- }, [])
-
- return (
-
- )
-}
\ No newline at end of file
+export default [
+ {
+ path: "",
+ index: true,
+ name: "Home",
+ element:
+ }, {
+ path: "operator/:key",
+ index: false,
+ name: "Operator",
+ element:
+ }
+]
\ No newline at end of file
diff --git a/directory/src/routes/index.css b/directory/src/routes/path/home.css
similarity index 100%
rename from directory/src/routes/index.css
rename to directory/src/routes/path/home.css
diff --git a/directory/src/routes/path/home.jsx b/directory/src/routes/path/home.jsx
new file mode 100644
index 0000000..211b8c9
--- /dev/null
+++ b/directory/src/routes/path/home.jsx
@@ -0,0 +1,24 @@
+import {
+ useState,
+ useEffect
+} from 'react'
+import './home.css'
+
+export default function Home(props) {
+ useEffect(() => {
+ fetch("/_assets/directory.json").then(res => res.json()).then(data => {
+ console.log(data)
+ })
+ }, [])
+
+ return (
+
+ )
+}
\ No newline at end of file
diff --git a/directory/src/routes/operator.css b/directory/src/routes/path/operator.css
similarity index 100%
rename from directory/src/routes/operator.css
rename to directory/src/routes/path/operator.css
diff --git a/directory/src/routes/operator.jsx b/directory/src/routes/path/operator.jsx
similarity index 100%
rename from directory/src/routes/operator.jsx
rename to directory/src/routes/path/operator.jsx
diff --git a/vite.config.js b/vite.config.js
index fce58b9..58a3335 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -22,13 +22,13 @@ class ViteRunner {
},
}
- config() {
+ get config() {
let result;
const temp = process.env.npm_lifecycle_event.split(':')
this.#mode = temp[0] === "vite" ? temp[1] : process.argv[2]
switch (this.#mode) {
case 'directory':
- result = this.directory()
+ result = this.#directoryConfig
const op = temp[2] || process.argv[3]
if (op !== 'preview') {
rmdir(path.resolve(__projetRoot, this.#globalConfig.folder.release, "_directory"))
@@ -39,7 +39,7 @@ class ViteRunner {
case 'build':
case 'build-all':
case 'preview':
- result = this.operator()
+ result = this.#operatorConfig
break
default:
return
@@ -47,8 +47,8 @@ class ViteRunner {
return result
}
- async start() {
- const viteConfig = this.config();
+ start() {
+ const viteConfig = this.config;
switch (this.#mode) {
case 'dev':
this.#dev(viteConfig)
@@ -96,7 +96,7 @@ class ViteRunner {
})()
}
- operator() {
+ get #operatorConfig() {
const operatorName = process.env.O || process.argv[3]
assert(operatorName, 'Please set the operator name by using environment variable O.')
return {
@@ -104,6 +104,9 @@ class ViteRunner {
envDir: path.join(__projetRoot, this.#globalConfig.folder.operator, operatorName),
publicDir: path.resolve(__projetRoot, this.#globalConfig.folder.release, operatorName),
root: path.resolve(__projetRoot),
+ server: {
+ ...this.#baseViteConfig.server,
+ },
resolve: {
alias: {
'@': path.resolve(__projetRoot, './src'),
@@ -118,18 +121,17 @@ class ViteRunner {
}
}
- directory() {
+ get #directoryConfig() {
const directoryDir = path.resolve(__projetRoot, 'directory')
this.#mode = process.argv[3]
return {
- configFile: false,
- base: "",
+ ...this.#baseViteConfig,
envDir: directoryDir,
plugins: [react()],
publicDir: path.resolve(__projetRoot, this.#globalConfig.folder.release),
root: directoryDir,
server: {
- host: '0.0.0.0',
+ ...this.#baseViteConfig.server,
},
resolve: {
alias: {
@@ -155,9 +157,9 @@ class ViteRunner {
async function main() {
if (process.env.npm_lifecycle_event.includes('vite')) return
const runner = new ViteRunner()
- await runner.start()
+ runner.start()
}
main()
-export default defineConfig((new ViteRunner()).config())
\ No newline at end of file
+export default defineConfig((new ViteRunner()).config)
\ No newline at end of file