zhangzengfei
2023-11-29 0d3db253cad1fb49c4fae9b9a537c8c318c7172f
vue.config.js
@@ -1,111 +1,186 @@
'use strict'
const glob = require('glob')
const pages = {}
const IS_VENDOR = /[\\/]node_modules[\\/]/
const pageVendor = {}
glob.sync('./src/pages/**/main.ts').forEach(path => {
  const chunk = path.split('./src/pages/')[1].split('/main.ts')[0]
  const chunk_vendor = `${chunk}-vendors`
  const chunk_common = `${chunk}-common`
  pages[chunk] = {
    entry: path,
    template: 'public/index.html',
    title: chunk == 'desktop/index' ? 'SmartAI' : chunk,
    chunks: [chunk_vendor, 'chunk-common', chunk]
  }
  if (chunk != 'index') {
    pages[chunk].filename = 'view/' + chunk + '.html'
  }
  pageVendor[chunk_vendor] = {
    name: chunk_vendor,
    priority: -11,
    chunks: c => c.name === chunk,
    test: /\.js$/,
    enforce: true
  }
  // pageVendor[chunk_common] = {
  //   name: chunk_common,
  //   priority: -20,
  //   chunks: 'initial',
  //   minChunks: 2,
  //   reuseExistingChunk: true,
  //   enforce: true
  // }
})
module.exports = {
  pages,
  chainWebpack: config => {
    config.plugins.delete('named-chunks')
    if (process.env.NODE_ENV === 'production') {
      config.output.filename('js/[name].js').end()
      config.output.chunkFilename('js/[name].js').end()
      // 修改生产配置
      config.plugin('extract-css').tap(() => [
        {
          filename: `css/[name].css`,
          chunkFilename: `css/[name].css`
        }
      ])
    }
    config.optimization.splitChunks({
      cacheGroups: pageVendor
    })
    // config.module.rule('fonts').use('url-loader').loader('file-loader').options({ name: 'fonts/[name].[ext]', publicPath: '../' })
    //config.module.rule('fonts').use('url-loader').loader('file-loader').options({ name: 'fonts/[name].[ext]', outputPath: '../' })
  },
  productionSourceMap: false,
  filenameHashing: false,
  devServer: {
    proxy: {
      '/track': {
        target: 'http://192.168.20.10:8000',
        // ws: true,
        changeOrigin: true,
      },
      '/ws': {
        target: 'http://192.168.20.10:7003',
        // ws: true,
        changeOrigin: true,
      },
      "/data/api-v/app/findAllApp": {
        target: '/',
        target: 'http://localhost:8080/',
        changeOrigin: true,
        pathRewrite: {
          '^/data/api-v/app/findAllApp': 'apps.json'
        }
      },
      "/api-v": {
        target: 'http://192.168.20.10:8000',
        changeOrigin: true
      },
      "/api-f": {
        target: 'http://192.168.20.10:8011',
        // secure: false,
        changeOrigin: true
      },
      "/api-p": {
        target: 'http://192.168.5.23:8010',
        // secure: false,
        changeOrigin: true
      },
      "/api-u": {
        target: 'http://192.168.20.10:8000',
        changeOrigin: true
      },
      "/httpImage": {
        target: 'http://192.168.20.10:7003',
        changeOrigin: true, //开启代理
      },
      "/files": {
        target: 'http://192.168.20.10:7003',
        changeOrigin: true, //开启代理
      }
    }
  }
}
"use strict"
const glob = require("glob")
const { ExitStatus } = require("typescript")
const pages = {}
const IS_VENDOR = /[\\/]node_modules[\\/]/
const pageVendor = {}
const pkg = require("./package.json")
const timestamp = new Date().getTime()
const queryStr = `?v=${pkg.version}&t=${timestamp}`
const basicApps = [
  "index",
  "ai",
  "analysisPower",
  "cameraAccess",
  "cameraVideo",
  "datapush",
  "desktop",
  "gb28181",
  "library",
  "search",
  "settings",
  "syslog"
]
const argv = process.env.npm_lifecycle_event
glob.sync("./src/pages/**/main.ts").forEach((path) => {
  const chunk = path.split("./src/pages/")[1].split("/main.ts")[0]
  // 仅编译基础应用
  if (argv == "release") {
    let app = chunk.split("/")
    if (app.length < 0 || basicApps.indexOf(app[0]) < 0) {
      return
    }
  }
  const chunk_vendor = `${chunk}-vendors`
  const chunk_common = `${chunk}-common`
  pages[chunk] = {
    entry: path,
    template: "public/index.html",
    title: chunk == "desktop/index" ? "SmartAI" : chunk,
    chunks: [chunk_vendor, "chunk-common", chunk]
  }
  if (chunk != "index") {
    pages[chunk].filename = "view/" + chunk + ".html"
  }
  pageVendor[chunk_vendor] = {
    name: chunk_vendor,
    priority: -11,
    chunks: (c) => c.name === chunk,
    test: /\.js$/,
    enforce: true
  }
  // pageVendor[chunk_common] = {
  //   name: chunk_common,
  //   priority: -20,
  //   chunks: 'initial',
  //   minChunks: 2,
  //   reuseExistingChunk: true,
  //   enforce: true
  // }
})
// const serverUrl = "http://192.168.20.189:7009";
const serverUrl = "http://192.168.20.2:7009"
//const serverUrl = "http://192.168.20.116:7009";
const iotdataServerUrl = "http://192.168.8.10:9000"
// const cir = require("circular-dependency-plugin");
module.exports = {
  pages,
  chainWebpack: (config) => {
    config.plugins.delete("named-chunks")
    if (process.env.NODE_ENV === "production") {
      config.output.filename("js/[name].js" + queryStr).end()
      config.output.chunkFilename("js/[name].js" + queryStr).end()
      // 修改生产配置
      config.plugin("extract-css").tap(() => [
        {
          filename: `css/[name].css${queryStr}`,
          chunkFilename: `css/[name].css${queryStr}`
        }
      ])
    }
    config.optimization.splitChunks({
      cacheGroups: pageVendor
    })
    // config.module.rule('fonts').use('url-loader').loader('file-loader').options({ name: 'fonts/[name].[ext]', publicPath: '../' })
    //config.module.rule('fonts').use('url-loader').loader('file-loader').options({ name: 'fonts/[name].[ext]', outputPath: '../' })
  },
  productionSourceMap: false,
  filenameHashing: false,
  pwa: {
    iconPaths: {
      favicon32: "favicon.ico",
      favicon16: "favicon.ico"
    }
  },
  devServer: {
    proxy: {
      "/track": {
        target: serverUrl,
        // ws: true,
        changeOrigin: true
      },
      "/ws": {
        target: serverUrl,
        // ws: true,
        changeOrigin: true
      },
      // "/data/api-v/app/findAllApp": {
      //   // target: '/',
      //   target: "http://localhost:8080/",
      //   changeOrigin: true,
      //   pathRewrite: {
      //     "^/data/api-v/app/findAllApp": "apps.json",
      //   },
      // },
      "/api-c": {
        target: serverUrl,
        changeOrigin: true
      },
      "/api-v": {
        target: serverUrl,
        changeOrigin: true
      },
      "/api-f": {
        target: serverUrl,
        // secure: false,
        changeOrigin: true
      },
      "/api-p": {
        target: serverUrl,
        // secure: false,
        changeOrigin: true
      },
      "/api-u": {
        target: serverUrl,
        changeOrigin: true
      },
      "/httpImage": {
        target: serverUrl,
        changeOrigin: true // 图片代理
      },
      "/files": {
        target: serverUrl,
        changeOrigin: true // 文件代理
      },
      "/iotdata": {
        target: iotdataServerUrl,
        changeOrigin: true // iot服务,
      },
      "/version": {
        target: serverUrl,
        changeOrigin: true // 版本检查,
      }
    }
  }
  // configureWebpack: {
  //   plugins: [
  //     new cir({
  //       exclude: /a\.js|node_modules/,
  //       include: /dir/,
  //       failOnError: true,
  //       allowAsyncCycles: false,
  //       cwd: process.cwd(),
  //     }),
  //   ],
  // },
  /* css:{
    loaderOptions:{
      scss:{
        prependData:`@import"@/assets/css/globalVariable.scss"`
      }
    }
  } */
}