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

Add Vitejs support #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/main/g8/fe-gui/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VUE_APP_BO_API_BASE_URL="http://localhost:3000"
VUE_APP_BO_API_BASE_URL="http://localhost:3000"
BASE_URL="/app/"
2 changes: 2 additions & 0 deletions src/main/g8/fe-gui/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VUE_APP_BO_API_BASE_URL="http://localhost:3000"
BASE_URL="/app/"
2 changes: 2 additions & 0 deletions src/main/g8/fe-gui/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VUE_APP_BO_API_BASE_URL="http://localhost:3000"
BASE_URL="/app/"
48 changes: 44 additions & 4 deletions src/main/g8/fe-gui/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
<!DOCTYPE html>
<!--#GoVueAdmin-Customized-->
<!--
Template by:
* CoreUI Vue.js Admin Template
* @version v4.1.0
* @link https://coreui.io/vue/
* Copyright (c) 2021 creativeLabs Łukasz Holeczek
* License (https://coreui.io/pro/license)
-->
<!-- #{appName} v#{appVersion} -->
<!-- #{appDescription} -->
<html>

<head>
<title>GoVueAdmin</title>
<meta http-equiv="refresh" content="0; url = /app/"/>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>#{pageTitle}</title>
<meta name="description" content="#{appDescription}">
<meta name="author" content="#{appName} v#{appVersion}">
<!-- favicons for all devices -->
<link rel="apple-touch-icon" sizes="57x57" href="/app/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/app/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/app/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/app/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/app/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/app/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/app/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/app/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/app/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/app/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/app/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/app/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/app/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/app/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<script type="module" src="/src/main.js"></script>
</head>

<body>
<h1>GoVueAdmin</h1>
<p>Please wait...</p>
<noscript>
<strong>We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>

</html>
9 changes: 7 additions & 2 deletions src/main/g8/fe-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"lint": "vue-cli-service lint",
"serve": "vue-cli-service serve",
"test:e2e": "vue-cli-service test:e2e",
"test:unit": "vue-cli-service test:unit"
"test:unit": "vue-cli-service test:unit",
"vite-dev": "vite",
"vite-build": "vite build",
"vite-preview": "vite preview"
},
"config": {
"coreui_library_short_version": "4.1"
Expand All @@ -43,6 +46,7 @@
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vitejs/plugin-vue": "^3.2.0",
"@vue/cli-plugin-babel": "~5.0.0-rc.1",
"@vue/cli-plugin-eslint": "~5.0.0-rc.1",
"@vue/cli-plugin-router": "~5.0.0-rc.1",
Expand All @@ -60,6 +64,7 @@
"jest": "^27.0.5",
"prettier": "^2.4.1",
"sass": "^1.32.7",
"sass-loader": "^12.0.0"
"sass-loader": "^12.0.0",
"vite": "^3.2.4"
}
}
4 changes: 3 additions & 1 deletion src/main/g8/fe-gui/src/utils/app_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
@author Thanh Nguyen <[email protected]>
@GoVueAdmin
*/
const APP_CONFIG = require('@/config.json')
// cannot use require in vite https://github.com/vitejs/vite/issues/1241#issuecomment-762367047
// const APP_CONFIG = require('@/config.json')
import APP_CONFIG from '@/config.json'
if (!APP_CONFIG.api_client.bo_api_base_url) {
APP_CONFIG.api_client.bo_api_base_url = process.env.VUE_APP_BO_API_BASE_URL
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/g8/fe-gui/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/** @type {import('vite').UserConfig} */
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path";

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
const path = require('path')
const env = loadEnv(mode, process.cwd(), '')
process.env = {...process.env, ...env};
return {
server: {
port: 8080,
host: "0.0.0.0",
proxy: {
// https://vitejs.dev/config/server-options.html
// '/api': {
// target: 'http://localhost:8000/',
// changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, '')
// },
},
},
plugins: [vue()],
base: env.BASE_URL ?? '/app/',
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue', 'scss'],
alias: [
{
// this is required for the SCSS modules
find: /^~(.*)$/,
replacement: '$1',
},
{
find: '@/',
replacement: `${path.resolve(__dirname, 'src')}/`,
},
{
find: '@',
replacement: path.resolve(__dirname, '/src'),
},
],
},
define: {
'process.env': process.env,
},
}
})