第一次提交
This commit is contained in:
83
vue.config.js
Normal file
83
vue.config.js
Normal file
@@ -0,0 +1,83 @@
|
||||
const settings = require('./src/settings')
|
||||
const path = require('path')
|
||||
const fs = require('fs') // 新增:用于HTTPS证书
|
||||
|
||||
function resolve(dir) {
|
||||
return path.join(__dirname, dir)
|
||||
}
|
||||
|
||||
// 自动生成自签名证书(开发环境使用)
|
||||
function getHttpsConfig() {
|
||||
try {
|
||||
return {
|
||||
https: {
|
||||
key: fs.readFileSync('./cert/key.pem'),
|
||||
cert: fs.readFileSync('./cert/cert.pem')
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('未找到HTTPS证书,将使用HTTP协议')
|
||||
return { https: false }
|
||||
}
|
||||
}
|
||||
|
||||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
||||
const Timestamp = new Date().getTime()
|
||||
const CompressionWebpackPlugin = require('compression-webpack-plugin')
|
||||
const productionGzipExtensions = ['js', 'css']
|
||||
const Components = require('unplugin-vue-components/webpack')
|
||||
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
|
||||
|
||||
module.exports = {
|
||||
assetsDir: 'static',
|
||||
runtimeCompiler: true,
|
||||
css: {
|
||||
requireModuleExtension: true,
|
||||
sourceMap: process.env.NODE_ENV == 'development'
|
||||
},
|
||||
|
||||
configureWebpack: {
|
||||
name: settings.title,
|
||||
resolve: {
|
||||
extensions: ['.js', '.vue', '.json'],
|
||||
alias: {
|
||||
'@': resolve('src')
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new UglifyJsPlugin({
|
||||
uglifyOptions: {
|
||||
compress: {
|
||||
drop_console: process.env.NODE_ENV === 'production' // 只在生产环境移除console
|
||||
}
|
||||
}
|
||||
}),
|
||||
new CompressionWebpackPlugin({
|
||||
filename: '[path].gz[query]',
|
||||
algorithm: 'gzip',
|
||||
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
|
||||
threshold: 10240,
|
||||
minRatio: 0.8,
|
||||
deleteOriginalAssets: false
|
||||
}),
|
||||
Components({
|
||||
resolvers: [ElementPlusResolver()]
|
||||
})
|
||||
],
|
||||
output: {
|
||||
filename: `js/[name].${Timestamp}.js`,
|
||||
chunkFilename: `js/[name].${Timestamp}.js`
|
||||
}
|
||||
},
|
||||
|
||||
devServer: {
|
||||
host: 'swt.costapi.f2b211.com',
|
||||
port: 8080,
|
||||
...getHttpsConfig(), // 动态获取HTTPS配置
|
||||
hot: true,
|
||||
open: true,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*' // 解决跨域问题
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user