优化打包

This commit is contained in:
chenhaodong
2026-06-23 20:08:35 +08:00
parent 4870a31b9e
commit 3116d3bf8b
10 changed files with 35 additions and 184 deletions
+11
View File
@@ -0,0 +1,11 @@
# IDE
.idea/
# 后端构建输出
exam-api/target/
# 前端打包输出(Vite build 输出到后端 static 目录)
exam-api/src/main/resources/static/
# 日志
logs/
@@ -24,24 +24,13 @@ import java.util.List;
@EnableTransactionManagement @EnableTransactionManagement
public class ExamApplication implements WebMvcConfigurer { public class ExamApplication implements WebMvcConfigurer {
public static void main(String[] args) throws UnknownHostException { public static void main(String[] args) {
ConfigurableApplicationContext application = SpringApplication.run(ExamApplication.class, args); SpringApplication.run(ExamApplication.class, args);
Environment env = application.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = env.getProperty("server.servlet.context-path");
// 未配置默认空白
if(path == null){
path = "";
}
log.info("\n----------------------------------------------------------\n\t" + log.info("\n----------------------------------------------------------\n\t" +
"系统启动成功,访问路径如下:\n\t" + "系统启动成功,访问路径如下:\n\t" +
"本地路径: \t\thttp://127.0.0.1:" + port + path + "/\n\t" + "本地路径: \t\thttp://127.0.0.1:8101\n\t" +
"网络地址: \thttp://" + ip + ":" + port + path + "/\n\t" + "慢sql监控:\t\thttp://127.0.0.1:8101/druid/index.html\n\t"+
"API文档: \t\thttp://" + ip + ":" + port + path + "/doc.html\n" + "API文档: \t\thttp://127.0.0.1:8101/doc.html\n" +
"----------------------------------------------------------"); "----------------------------------------------------------");
} }
@@ -20,6 +20,16 @@ spring:
pool-prepared-statements: true pool-prepared-statements: true
max-open-prepared-statements: 1000 max-open-prepared-statements: 1000
async-init: true async-init: true
druid:
stat-view-servlet:
enabled: true
url-pattern: /druid/*
login-username: admin
login-password: admin123
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
# 开启文档 # 开启文档
swagger: swagger:
@@ -1,2 +0,0 @@
为了方便单文件运行,可以把前端打包文件dist目录的内容复制到本目录下面,这样就可以直接运行jar就包含前端了,不需要单独再部署前端了。
访问地址为:http://localhost:8101
+1
View File
@@ -0,0 +1 @@
ignore-scripts=false
-35
View File
@@ -1,35 +0,0 @@
const { run } = require('runjs')
const chalk = require('chalk')
const config = require('../vue.config.js')
const rawArgv = process.argv.slice(2)
const args = rawArgv.join(' ')
if (process.env.npm_config_preview || rawArgv.includes('--preview')) {
const report = rawArgv.includes('--report')
run(`vue-cli-service build ${args}`)
const port = 9526
const publicPath = config.publicPath
var connect = require('connect')
var serveStatic = require('serve-static')
const app = connect()
app.use(
publicPath,
serveStatic('./dist', {
index: ['index.html', '/']
})
)
app.listen(port, function () {
console.log(chalk.green(`> Preview at http://localhost:${port}${publicPath}`))
if (report) {
console.log(chalk.green(`> Report at http://localhost:${port}${publicPath}report.html`))
}
})
} else {
run(`vue-cli-service build ${args}`)
}
+2 -1
View File
@@ -35,5 +35,6 @@
}, },
"engines": { "engines": {
"node": ">=16.0.0" "node": ">=16.0.0"
} },
"packageManager": "pnpm@11.8.0+sha512.c1f5e7c4cb241c8f174b743851d82f42b802324afc8b0f116b96adb15aa06664948dde36960a3ba1079ba5b4b29dd0140135b94b5b5f5263592249d68e555f26"
} }
+4
View File
@@ -0,0 +1,4 @@
allowBuilds:
'@parcel/watcher': true
cos-js-sdk-v5: true
esbuild: true
+1 -1
View File
@@ -32,7 +32,7 @@ export default defineConfig(({ mode }) => {
}, },
build: { build: {
outDir: '../exam-api/src/main/resources/static', outDir: '../exam-api/src/main/resources/static',
emptyOutDir: false, emptyOutDir: true,
assetsDir: 'static', assetsDir: 'static',
sourcemap: false, sourcemap: false,
chunkSizeWarningLimit: 1000, chunkSizeWarningLimit: 1000,
-128
View File
@@ -1,128 +0,0 @@
'use strict'
const path = require('path')
const defaultSettings = require('./src/settings.js')
function resolve(dir) {
return path.join(__dirname, dir)
}
const name = defaultSettings.title || '校园管藏图书数字化运维系统' // page title
// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run
// You can change the port by the following method:
// port = 9527 npm run dev OR npm run dev --port = 9527
const port = process.env.port || process.env.npm_config_port || 9527 // dev port
// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {
/**
* You will need to set publicPath if you plan to deploy your site under a sub path,
* for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
* then publicPath should be set to "/bar/".
* In most cases please use '/' !!!
* Detail: https://cli.vuejs.org/config/#publicpath
*/
publicPath: '/',
outputDir: 'dist',
assetsDir: 'static',
// lintOnSave: process.env.NODE_ENV !== 'production',
lintOnSave: false,
productionSourceMap: false,
devServer: {
port: port,
open: true,
overlay: {
warnings: false,
errors: true
}
},
configureWebpack: {
// provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title.
name: name,
resolve: {
alias: {
'@': resolve('src')
}
}
},
chainWebpack(config) {
config.plugins.delete('preload') // TODO: need test
config.plugins.delete('prefetch') // TODO: need test
// set svg-sprite-loader
config.module
.rule('svg')
.exclude.add(resolve('src/icons'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
// set preserveWhitespace
config.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.compilerOptions.preserveWhitespace = true
return options
})
.end()
config
// https://webpack.js.org/configuration/devtool/#development
.when(process.env.NODE_ENV === 'development',
config => config.devtool('cheap-source-map')
)
config
.when(process.env.NODE_ENV !== 'development',
config => {
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
.use('script-ext-html-webpack-plugin', [{
// `runtime` must same as runtimeChunk name. default is `runtime`
inline: /runtime\..*\.js$/
}])
.end()
config
.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial' // only package third parties that are initially dependent
},
elementUI: {
name: 'chunk-elementUI', // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
},
commons: {
name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules
minChunks: 3, // minimum common number
priority: 5,
reuseExistingChunk: true
}
}
})
config.optimization.runtimeChunk('single')
}
)
}
}