| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- 'use strict'
- const fs = require('fs')
- const path = require('path')
- const webpack = require('webpack')
- function resolve(dir) {
- return path.join(__dirname, dir)
- }
- // npm 提升 @aws-sdk 子包后,babel-loader 缓存仍可能指向
- // @aws-sdk/client-s3/node_modules/@aws-sdk/* 等已不存在的嵌套路径,导致 ENOENT。
- const DEPS_CACHE_VERSION = 'aws-sdk-hoist-fix-1'
- function clearWebpackCacheIfStale() {
- const cacheDir = path.join(__dirname, 'node_modules/.cache')
- const markerPath = path.join(cacheDir, '.deps-layout-marker')
- const lockPath = path.join(__dirname, 'package-lock.json')
- let lockId = 'no-lock'
- try {
- const stat = fs.statSync(lockPath)
- lockId = `${stat.mtimeMs}-${stat.size}`
- } catch (e) {
- // ignore
- }
- const marker = `${DEPS_CACHE_VERSION}|${lockId}`
- let prev = ''
- try {
- if (fs.existsSync(markerPath)) {
- prev = fs.readFileSync(markerPath, 'utf8')
- }
- } catch (e) {
- // ignore
- }
- if (prev !== marker && fs.existsSync(cacheDir)) {
- fs.rmSync(cacheDir, { recursive: true, force: true })
- console.log('[vue.config] Cleared webpack cache (dependency layout changed)')
- }
- try {
- fs.mkdirSync(cacheDir, { recursive: true })
- fs.writeFileSync(markerPath, marker)
- } catch (e) {
- // ignore
- }
- }
- clearWebpackCacheIfStale()
- const name = process.env.VUE_APP_TITLE || '云联私域管理系统' // 网页标题
- const port = process.env.port || process.env.npm_config_port || 80 // 端口
- // vue.config.js 配置说明
- //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
- // 这里只列一部分,具体配置参考文档
- module.exports = {
- // 部署生产环境和开发环境下的URL。
- // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
- // 例如 https://www.test.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.test.vip/admin/,则设置 baseUrl 为 /admin/。
- publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
- // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
- outputDir: 'dist',
- // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
- assetsDir: 'static',
- // 是否开启eslint保存检测,有效值:ture | false | 'error'
- lintOnSave: process.env.NODE_ENV === 'development',
- // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
- productionSourceMap: false,
- // CSS 相关配置
- css: {
- loaderOptions: {
- scss: {
- // 全局注入共享 mixin,组件无需手动 @import
- prependData: `
- @import "~@/assets/styles/page-layout.scss";
- @import "~@/assets/styles/dialog-layout.scss";
- @import "~@/assets/styles/page-transitions.scss";
- `
- }
- }
- },
- // transpileDependencies: true, // 默认情况下 babel-loader 忽略 node_modules 中的所有文件,启用此选项需配置transpileDependencies
- transpileDependencies: [
- /@aws-sdk/,
- '@aws/lambda-invoke-store',
- /@aws/,
- /@smithy/,
- /@huaweicloud/,
- /vod-js-sdk-v6/
- ],
- // webpack-dev-server 相关配置
- devServer: {
- host: '0.0.0.0',
- port: port,
- open: true,
- disableHostCheck: true,
- proxy: {
- // watch模块代理(fs-watch微服务,独立部署)
- '/watch-api': {
- target: 'http://localhost:8010',
- changeOrigin: true,
- pathRewrite: {
- '^/watch-api': ''
- }
- },
- // 向量知识库 / AI → fs-ai-api (9009)
- '/prod-api/qdrant': {
- target: 'http://localhost:9009',
- changeOrigin: true,
- pathRewrite: { '^/prod-api': '' }
- },
- '/prod-api/ai/': {
- target: 'http://localhost:9009',
- changeOrigin: true,
- pathRewrite: { '^/prod-api': '' }
- },
- // ===== 默认所有其他请求 → fs-saasadmin(8004) 租户总后台 =====
- // saasadminui 严格对应 fs-saasadmin(8004),不跨服务调用
- // @Profile("admin") 和 @Profile({"admin","company"}) 的 Controllers 在 8004 可用
- // com.fs.company.controller 中的 store/workflow/companyWorkflow/tag 等子包也已放开加载
- // 冲突子包(chat/company/course/crm/fastGpt/live/newAdv/qw/stats/transfer)已排除,由 fs-saasadmin 自有 Controller 覆盖
- [process.env.VUE_APP_BASE_API]: {
- target: 'http://localhost:8004',
- changeOrigin: true,
- pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
- }
- }
- },
- configureWebpack: {
- name: name,
- resolve: {
- alias: {
- '@': resolve('src')
- }
- },
- plugins: [
- // @smithy/@aws-sdk 会 import node:stream 等内置模块,浏览器用空模块替代
- new webpack.NormalModuleReplacementPlugin(/^node:/, resource => {
- resource.request = resolve('src/utils/node-empty-module.js')
- })
- ]
- },
- 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/assets/icons'))
- .end()
- config.module
- .rule('icons')
- .test(/\.svg$/)
- .include.add(resolve('src/assets/icons'))
- .end()
- .use('svg-sprite-loader')
- .loader('svg-sprite-loader')
- .options({
- symbolId: 'icon-[name]'
- })
- .end()
- 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')
- // Windows 下 terser 多进程压缩易触发 write UNKNOWN,改为单进程
- config.optimization.minimizer('terser').tap((args) => {
- const opts = args[0] || {}
- opts.parallel = false
- args[0] = opts
- return args
- })
- }
- )
- }
- }
|