vue.config.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 'use strict'
  2. const path = require('path')
  3. const ip = '192.168.1.43'
  4. const os = require('os')
  5. const fs = require("fs")
  6. //判断环境
  7. let ifaces = os.networkInterfaces()
  8. let localityIp = '', result = []
  9. for (let dev in ifaces) {
  10. ifaces[dev].forEach(function (details) {
  11. if (localityIp === '' && details.family === 'IPv4' && !details.internal) {
  12. localityIp = details.address
  13. return;
  14. }
  15. })
  16. }
  17. let getFile = localityIp == ip ? false : true
  18. /******** 获取git版本信息 ********/
  19. const gitHEAD = getFile ? fs.readFileSync('.git/HEAD', 'utf-8').trim() : false
  20. const ref = getFile ? gitHEAD.split(': ')[1] : false
  21. const develop = getFile ? gitHEAD.split('/')[2] : false
  22. const gitVersion = getFile ? fs.readFileSync('.git/' + ref, 'utf-8').trim() : false
  23. const buildEdition = develop && gitVersion ? develop + ': ' + gitVersion : '未配置'
  24. const myDate = new Date()
  25. const buildTime = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + myDate.getDate() + ' ' + myDate.getHours() + ':' + myDate.getMinutes();
  26. const logsList = getFile ? fs.readFileSync('.git/logs/HEAD', 'utf-8').replace(/\r\n|\r/g, "\n").split("\n") : false
  27. const buildUser = getFile ? logsList[logsList.length - 2].split(" ")[2] : '未配置'
  28. //生成随机版本编码
  29. const revision = generateRandomString()
  30. process.env.VUE_APP_RENEWAL_ENCODING = revision
  31. require('fs').writeFileSync('public/version.txt', revision)
  32. function generateRandomString() {
  33. let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  34. let randomString = "";
  35. for (let i = 0; i < 24; i++) {
  36. let randomIndex = Math.floor(Math.random() * chars.length);
  37. randomString += chars.charAt(randomIndex);
  38. }
  39. return randomString;
  40. }
  41. const name = '实验室安全智慧化管控系统' // 网页标题
  42. const {defineConfig} = require('@vue/cli-service')
  43. const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
  44. const webpack = require('webpack');
  45. module.exports = defineConfig({
  46. transpileDependencies: true,
  47. lintOnSave: false,
  48. publicPath: "./", // 公共路径(必须有的)
  49. outputDir: "bigData", // 输出文件目录
  50. assetsDir: "static", //静态资源文件名称
  51. productionSourceMap: false, //去除打包后js的map文件
  52. devServer: {
  53. host: "localhost", // 默认是localhost
  54. port: 8081, // 前端项目编译后使用的端口号,跟webpack配置的port同理
  55. open: true,
  56. proxy: {
  57. '/api': {
  58. target: `http://localhost:8081`, // 实际跨域请求的API地址
  59. changeOrigin: true, // 跨域
  60. // 请求地址重写 http://front-end/api/login ⇒ http://api-url/login
  61. pathRewrite: {
  62. ['^' + process.env.VUE_APP_BASE_API]: ''
  63. }
  64. }
  65. },
  66. },
  67. configureWebpack: {
  68. resolve: {
  69. fallback: {
  70. },
  71. },
  72. plugins: [
  73. new NodePolyfillPlugin(),
  74. new webpack.ProvidePlugin({
  75. process: 'process/browser',
  76. }),
  77. ]
  78. },
  79. chainWebpack(config) {
  80. //标记打包时间与当前git版本信息
  81. config.plugin('html').tap(args => {
  82. args[0].buildUser = buildUser;
  83. args[0].buildTime = buildTime;
  84. args[0].buildEdition = buildEdition;
  85. return args
  86. })
  87. config
  88. .when(process.env.VUE_APP_ENV !== 'www.dlc.com',
  89. config => {
  90. config
  91. .plugin('ScriptExtHtmlWebpackPlugin')
  92. .after('html')
  93. .use('script-ext-html-webpack-plugin', [{
  94. // `runtime` must same as runtimeChunk name. default is `runtime`
  95. inline: /runtime\..*\.js$/
  96. }])
  97. .end()
  98. config
  99. .optimization.splitChunks({
  100. chunks: 'all',
  101. minSize: 50000, //构建出来的chunk大于30000才会被分割
  102. maxSize: 100000, //会尝试根据这个大小进行代码分割
  103. })
  104. }
  105. )
  106. },
  107. })