1
0
mirror of https://github.com/fumiama/paper-manager.git synced 2026-06-04 23:40:24 +08:00

implement production build

This commit is contained in:
源文雨
2023-04-27 01:35:30 +08:00
parent 940b2618b3
commit ff17c90139
7 changed files with 52 additions and 10 deletions

10
frontend/main.go Normal file
View File

@@ -0,0 +1,10 @@
package frontend
import (
"net/http"
"github.com/fumiama/paper-manager/frontend/vben"
)
// StaticHandler serves contents in frontend
var StaticHandler = http.FileServer(vben.Distribution)

View File

@@ -32,4 +32,4 @@ VITE_USE_IMAGEMIN= true
VITE_USE_PWA = false
# Is it compatible with older browsers
VITE_LEGACY = false
VITE_LEGACY = true

View File

@@ -32,3 +32,4 @@ package-lock.json
pnpm-lock.yaml
.vscode
dist.zip

29
frontend/vben/main.go Normal file
View File

@@ -0,0 +1,29 @@
package vben
import (
"archive/zip"
"bytes"
_ "embed" // embed dist.zip
"io/fs"
"net/http"
)
//go:generate npm run build
//go:generate zip -9 -r -D dist.zip dist/* -x "dist/.DS_Store" "dist/*/.DS_Store"
//go:embed dist.zip
var distzipbytes []byte
// Distribution ...
var Distribution = func() http.FileSystem {
distzip, err := zip.NewReader(bytes.NewReader(distzipbytes), int64(len(distzipbytes)))
if err != nil {
panic(err)
}
distfs, err := fs.Sub(fs.FS(distzip), "dist")
if err != nil {
panic(err)
}
return http.FS(distfs)
}()

View File

@@ -36,7 +36,7 @@
import { Card, List } from 'ant-design-vue'
import { getMessageList, acceptMessage, deleteMessage } from '/@/api/dashboard/index'
import { useMessage } from '/@/hooks/web/useMessage'
import { MessageTypeEnum, MessageItem } from '../../../../api/dashboard/model/model.js'
import { MessageTypeEnum, MessageItem } from '/@/api/dashboard/model/model'
import { Avatar } from 'ant-design-vue'
import headerImg from '/@/assets/images/header.jpg'

View File

@@ -64,20 +64,20 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
pure: VITE_DROP_CONSOLE ? ['console.log', 'debugger'] : [],
},
build: {
target: 'es2015',
target: 'es2022',
cssTarget: 'chrome80',
outDir: OUTPUT_DIR,
// minify: 'terser',
minify: 'terser',
/**
* 当 minify=“minify:'terser'” 解开注释
* Uncomment when minify="minify:'terser'"
*/
// terserOptions: {
// compress: {
// keep_infinity: true,
// drop_console: VITE_DROP_CONSOLE,
// },
// },
terserOptions: {
compress: {
keep_infinity: true,
drop_console: VITE_DROP_CONSOLE,
},
},
// Turning off brotliSize display can slightly reduce packaging time
brotliSize: false,
chunkSizeWarningLimit: 2000,

View File

@@ -10,6 +10,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/fumiama/paper-manager/backend"
"github.com/fumiama/paper-manager/frontend"
)
func line() int {
@@ -33,6 +34,7 @@ func main() {
http.HandleFunc("/file/", backend.FileHandler)
http.HandleFunc("/paper/", backend.PaperHandler)
http.HandleFunc("/upload", backend.UploadHandler)
http.Handle("/", frontend.StaticHandler)
logrus.Infoln("[http.Serve] start at", l.Addr())
logrus.Errorln("[http.Serve]", http.Serve(l, nil))