|
|
|
const path = require('path')
|
|
|
|
const { defineConfig } = require('@vue/cli-service')
|
|
|
|
|
|
|
|
// 设置环境变量
|
|
|
|
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = 'false'
|
|
|
|
process.env.VUE_CLI_MODERN_BUILD = 'false'
|
|
|
|
|
|
|
|
// 设置日志级别
|
|
|
|
process.env.VUE_CLI_LOG_LEVEL = 'info'
|
|
|
|
process.env.VUE_CLI_DEBUG = 'true'
|
|
|
|
|
|
|
|
// 设置编码 - 增强版
|
|
|
|
process.env.LANG = 'zh_CN.UTF-8'
|
|
|
|
process.env.LC_ALL = 'zh_CN.UTF-8'
|
|
|
|
process.env.NODE_OPTIONS = '--max-old-space-size=4096'
|
|
|
|
process.env.CHROME_BIN = process.env.CHROME_BIN || 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
|
|
|
|
|
|
|
|
// 强制设置控制台编码
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
process.env.PYTHONIOENCODING = 'utf-8'
|
|
|
|
process.env.PYTHONLEGACYWINDOWSSTDIO = 'utf-8'
|
|
|
|
}
|
|
|
|
|
|
|
|
const appRoot = path.resolve(__dirname)
|
|
|
|
|
|
|
|
module.exports = defineConfig({
|
|
|
|
outputDir: path.join(appRoot, 'dist/renderer'),
|
|
|
|
publicPath: './',
|
|
|
|
|
|
|
|
configureWebpack: {
|
|
|
|
target: 'electron-renderer',
|
|
|
|
// 完全禁用eval,强制使用安全的sourcemap
|
|
|
|
devtool: false,
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@': path.join(appRoot, 'src/renderer'),
|
|
|
|
'views': path.join(appRoot, 'src/renderer/views')
|
|
|
|
},
|
|
|
|
extensions: ['.js', '.vue', '.json']
|
|
|
|
},
|
|
|
|
externals: {
|
|
|
|
electron: 'require("electron")',
|
|
|
|
fs: 'require("fs")',
|
|
|
|
path: 'require("path")'
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
// 定义全局变量
|
|
|
|
new (require('webpack')).DefinePlugin({
|
|
|
|
'global': 'globalThis',
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
|
|
|
|
}),
|
|
|
|
// 提供全局变量
|
|
|
|
new (require('webpack')).ProvidePlugin({
|
|
|
|
global: 'globalThis',
|
|
|
|
process: 'process/browser'
|
|
|
|
})
|
|
|
|
],
|
|
|
|
node: {
|
|
|
|
global: true
|
|
|
|
},
|
|
|
|
// 强制禁用eval相关功能
|
|
|
|
optimization: {
|
|
|
|
minimize: false,
|
|
|
|
minimizer: [],
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'all',
|
|
|
|
cacheGroups: {
|
|
|
|
vendor: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: 'vendors',
|
|
|
|
chunks: 'all',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 禁用所有可能导致eval的webpack功能
|
|
|
|
experiments: {
|
|
|
|
topLevelAwait: false,
|
|
|
|
asyncWebAssembly: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
pages: {
|
|
|
|
index: {
|
|
|
|
entry: path.join(appRoot, 'src/renderer/main.js'),
|
|
|
|
template: path.join(appRoot, 'public/index.html'),
|
|
|
|
filename: 'index.html'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
pluginOptions: {
|
|
|
|
electronBuilder: {
|
|
|
|
preload: path.join(appRoot, 'src/preload.js'),
|
|
|
|
mainProcessFile: path.join(appRoot, 'src/main/index.js'),
|
|
|
|
builderOptions: {
|
|
|
|
extraResources: [{
|
|
|
|
from: path.join(appRoot, 'dist/renderer'),
|
|
|
|
to: 'app',
|
|
|
|
filter: ["**/*"]
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
devServer: {
|
|
|
|
hot: true, // 启用热重载
|
|
|
|
liveReload: true, // 启用实时重载
|
|
|
|
allowedHosts: "all",
|
|
|
|
static: {
|
|
|
|
directory: path.join(__dirname, 'dist/renderer'),
|
|
|
|
watch: true // 启用文件监听
|
|
|
|
},
|
|
|
|
compress: false,
|
|
|
|
proxy: null,
|
|
|
|
// 安全配置
|
|
|
|
headers: {
|
|
|
|
"Content-Security-Policy": "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self' ws: wss:; object-src 'none'; frame-src 'none';"
|
|
|
|
},
|
|
|
|
// 增强日志配置 - 解决中文乱码
|
|
|
|
client: {
|
|
|
|
logging: 'info',
|
|
|
|
overlay: {
|
|
|
|
errors: true,
|
|
|
|
warnings: false
|
|
|
|
},
|
|
|
|
progress: true
|
|
|
|
},
|
|
|
|
// 详细日志 - 增强编码支持
|
|
|
|
logLevel: 'info',
|
|
|
|
stats: {
|
|
|
|
colors: true,
|
|
|
|
modules: false,
|
|
|
|
children: false,
|
|
|
|
chunks: false,
|
|
|
|
chunkModules: false,
|
|
|
|
entrypoints: false,
|
|
|
|
warnings: true,
|
|
|
|
errors: true,
|
|
|
|
errorDetails: true,
|
|
|
|
reasons: true,
|
|
|
|
timings: true,
|
|
|
|
builtAt: true,
|
|
|
|
version: true,
|
|
|
|
hash: true,
|
|
|
|
assets: true,
|
|
|
|
assetsSort: 'field',
|
|
|
|
chunksSort: 'field',
|
|
|
|
modulesSort: 'field'
|
|
|
|
},
|
|
|
|
// 编码设置
|
|
|
|
setupMiddlewares: (middlewares, devServer) => {
|
|
|
|
// 强制设置响应头编码
|
|
|
|
devServer.app.use((req, res, next) => {
|
|
|
|
res.setHeader('Content-Type', 'text/html; charset=utf-8')
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
return middlewares
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
chainWebpack: config => {
|
|
|
|
// 强制禁用所有sourcemap,避免eval
|
|
|
|
config.devtool(false)
|
|
|
|
|
|
|
|
// 禁用所有可能导致eval的webpack功能
|
|
|
|
config.optimization.minimize(false)
|
|
|
|
|
|
|
|
// 静态资源处理
|
|
|
|
config.module
|
|
|
|
.rule('images')
|
|
|
|
.set('generator', {
|
|
|
|
filename: 'img/[name].[hash:8][ext]'
|
|
|
|
})
|
|
|
|
|
|
|
|
// 全局变量定义
|
|
|
|
config.plugin('define').tap(args => {
|
|
|
|
args[0]['global'] = 'globalThis'
|
|
|
|
args[0]['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV || 'development')
|
|
|
|
args[0]['process.browser'] = true
|
|
|
|
args[0]['globalThis'] = 'globalThis'
|
|
|
|
args[0]['window.global'] = 'window'
|
|
|
|
args[0]['global["webpackChunkGoFaster"]'] = 'globalThis["webpackChunkGoFaster"]'
|
|
|
|
// 明确禁用eval
|
|
|
|
args[0]['__webpack_require__.e'] = 'undefined'
|
|
|
|
return args
|
|
|
|
})
|
|
|
|
|
|
|
|
// 添加全局polyfill
|
|
|
|
config.resolve.alias.set('global', 'globalThis')
|
|
|
|
|
|
|
|
// 确保所有模块都能访问全局变量
|
|
|
|
config.resolve.alias.set('process', 'process/browser')
|
|
|
|
|
|
|
|
// 添加webpack chunk名称处理
|
|
|
|
config.output.chunkFilename('[name].js')
|
|
|
|
config.output.globalObject('globalThis')
|
|
|
|
|
|
|
|
// 配置热重载插件
|
|
|
|
config.plugin('hot').use(require('webpack').HotModuleReplacementPlugin, [{
|
|
|
|
multiStep: false,
|
|
|
|
fullBuildTimeout: 200
|
|
|
|
}])
|
|
|
|
|
|
|
|
// 确保热重载正常工作
|
|
|
|
config.plugin('hmr').use(require('webpack').HotModuleReplacementPlugin)
|
|
|
|
|
|
|
|
// 增强日志配置
|
|
|
|
config.stats({
|
|
|
|
colors: true,
|
|
|
|
modules: false,
|
|
|
|
children: false,
|
|
|
|
chunks: false,
|
|
|
|
chunkModules: false,
|
|
|
|
entrypoints: false,
|
|
|
|
warnings: true,
|
|
|
|
warningsFilter: /export.*was not found in/,
|
|
|
|
errors: true,
|
|
|
|
errorDetails: true,
|
|
|
|
reasons: true,
|
|
|
|
usedExports: false,
|
|
|
|
providedExports: false,
|
|
|
|
optimizationBailout: false,
|
|
|
|
source: false,
|
|
|
|
publicPath: false,
|
|
|
|
timings: true,
|
|
|
|
builtAt: true,
|
|
|
|
version: true,
|
|
|
|
hash: true
|
|
|
|
})
|
|
|
|
|
|
|
|
// 添加进度条
|
|
|
|
config.plugin('progress').use(require('webpack/lib/ProgressPlugin'), [{
|
|
|
|
activeModules: false,
|
|
|
|
entries: true,
|
|
|
|
handler(percentage, message, ...args) {
|
|
|
|
if (percentage === 0) {
|
|
|
|
console.log('🚀 开始构建...')
|
|
|
|
} else if (percentage === 1) {
|
|
|
|
console.log('✅ 构建完成!')
|
|
|
|
} else if (percentage % 0.1 === 0) {
|
|
|
|
console.log(`📊 构建进度: ${Math.round(percentage * 100)}%`)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
modules: false,
|
|
|
|
modulesCount: 5000,
|
|
|
|
profile: false,
|
|
|
|
dependencies: false,
|
|
|
|
dependenciesCount: 10000,
|
|
|
|
percentBy: null
|
|
|
|
}])
|
|
|
|
}
|
|
|
|
})
|