xiaozhi-esp32-server/main/manager-web/vue.config.js
lapy 70771b4209 chore(westernization): translate remaining Han text across code, UI and docs
Final localization pass over everything the audit covers, driven by the
local qwen3.8:instruct endpoint (thinking disabled) with placeholder-
masked, cached, resumable batches:

- Python server: comments, docstrings, log/error messages, prompt text
- manager-api Java: javadoc, exception messages, Swagger summaries,
  westernized test fixtures (locale strings, signed-URL examples)
- manager-web / manager-mobile: component comments and misc leftovers
  (functional split regexes such as /[、;;,,]/ left byte-identical)
- digital-human: HTML/UI text, JS comments, wake-word defaults aligned
  with the server canonical English wake words
- docs: device-call guide, wakeword and search integration guides

Also widens the westernization audit exception to the whole vendored
generator bundle and retires the stale per-file exception list.
2026-10-11 17:58:15 +01:00

181 lines
5.6 KiB
JavaScript

const { defineConfig } = require('@vue/cli-service');
const dotenv = require('dotenv');
// TerserPlugin is used to compress JavaScript
const TerserPlugin = require('terser-webpack-plugin');
// CompressionPlugin enables Gzip compression
const CompressionPlugin = require('compression-webpack-plugin')
// BundleAnalyzerPlugin is used to analyze bundled files
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// WorkboxPlugin generates the Service Worker
const { InjectManifest } = require('workbox-webpack-plugin');
// Import path module
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
// Ensure the .env file is loaded
dotenv.config();
// Define the CDN resource list to ensure Service Worker accessibility
const cdnResources = {
css: [
'https://unpkg.com/element-ui@2.15.14/lib/theme-chalk/index.css',
'https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css'
],
js: [
'https://unpkg.com/vue@2.6.14/dist/vue.min.js',
'https://unpkg.com/vue-router@3.6.5/dist/vue-router.min.js',
'https://unpkg.com/vuex@3.6.2/dist/vuex.min.js',
'https://unpkg.com/element-ui@2.15.14/lib/index.js',
'https://unpkg.com/axios@0.27.2/dist/axios.min.js',
'https://unpkg.com/opus-decoder@0.7.7/dist/opus-decoder.min.js'
]
};
// Check if CDN is used
const useCDN = process.env.VUE_APP_USE_CDN === 'true';
module.exports = defineConfig({
productionSourceMap: process.env.NODE_ENV !== 'production', // Do not generate source maps in production
devServer: {
port: 8001, // Set port to 8001
proxy: {
'/xiaozhi': {
target: 'http://127.0.0.1:8002',
changeOrigin: true
}
},
client: {
overlay: false, // Do not display webpack error overlay
},
},
publicPath: process.env.VUE_APP_PUBLIC_PATH || "/",
chainWebpack: config => {
// Modify HTML plugin config to dynamically insert CDN links
config.plugin('html')
.tap(args => {
// Determine whether to use CDN based on config
if (process.env.NODE_ENV === 'production' && useCDN) {
args[0].cdn = cdnResources;
}
return args;
});
// Code splitting optimization
config.optimization.splitChunks({
chunks: 'all',
minSize: 20000,
maxSize: 250000,
cacheGroups: {
vendors: {
name: 'chunk-vendors',
test: /[\\/]node_modules[\\/]/,
priority: -10,
chunks: 'initial',
},
common: {
name: 'chunk-common',
minChunks: 2,
priority: -20,
chunks: 'initial',
reuseExistingChunk: true,
},
}
});
// Enable optimization settings
config.optimization.usedExports(true);
config.optimization.concatenateModules(true);
config.optimization.minimize(true);
},
configureWebpack: config => {
if (process.env.NODE_ENV === 'production') {
// Enable multi-threaded compilation
config.optimization = {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log']
}
}
})
]
};
config.plugins.push(
new CompressionPlugin({
algorithm: 'gzip',
test: /\.(js|css|html|svg)$/,
threshold: 20480,
minRatio: 0.8
})
);
// Conditionally add Service Worker based on CDN usage
config.plugins.push(
new InjectManifest({
swSrc: path.resolve(__dirname, 'src/service-worker.js'),
swDest: 'service-worker.js',
exclude: [/\.map$/, /asset-manifest\.json$/],
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024, // 5MB
// Custom Service Worker injection point
injectionPoint: 'self.__WB_MANIFEST',
// Pass additional info to Service Worker
additionalManifestEntries: useCDN ?
[{ url: 'cdn-mode', revision: 'enabled' }] :
[{ url: 'cdn-mode', revision: 'disabled' }]
})
);
// If using a CDN, configure externals to exclude dependencies
if (useCDN) {
config.externals = {
'vue': 'Vue',
'vue-router': 'VueRouter',
'vuex': 'Vuex',
'element-ui': 'ELEMENT',
'axios': 'axios',
'opus-decoder': 'OpusDecoder'
};
} else {
// Ensure externals are not set when CDN is disabled, allowing webpack to bundle all dependencies
config.externals = {};
}
if (process.env.ANALYZE === 'true') { // Control via environment variables
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'server', // Enable local server mode
openAnalyzer: true, // Automatically open browser
analyzerPort: 8888 // Specify port number
})
);
}
config.cache = {
type: 'filesystem', // Use filesystem cache
cacheDirectory: path.resolve(__dirname, '.webpack_cache'), // Custom cache directory
allowCollectingMemory: true, // Enable memory collection
compression: 'gzip', // Enable gzip compression cache
maxAge: 5184000000, // Cache validity period is 1 month
buildDependencies: {
config: [__filename] // Invalidate cache on every config file modification
}
};
}
},
// Expose CDN resource info to service-worker.js
pwa: {
workboxOptions: {
skipWaiting: true,
clientsClaim: true
}
}
});