vue.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. const DonePlugin = require("./src/plugin/webpackDonePlugin.js");
  2. const WebpackBar = require("webpackbar");
  3. const TerserPlugin = require("terser-webpack-plugin");
  4. console.log('当前环境:', process.env.NODE_ENV);
  5. module.exports = {
  6. transpileDependencies: true,
  7. lintOnSave: false,
  8. chainWebpack: (config) => {
  9. config.module
  10. .rule("lottie")
  11. .test(/\.lottie$/)
  12. .use("file-loader")
  13. .loader("file-loader")
  14. .end();
  15. config.plugin('html').tap(args => {
  16. args[0].title = "慧教研-大数据精准教学诊断平台";
  17. return args
  18. })
  19. // 根据环境配置是否移除 console
  20. if (process.env.NODE_ENV === 'production') {
  21. config.optimization.minimizer('terser').tap((args) => {
  22. args[0].terserOptions.compress.drop_console = true;
  23. args[0].terserOptions.compress.drop_debugger = true;
  24. return args;
  25. });
  26. }
  27. },
  28. publicPath: process.env.NODE_ENV === 'production' ? '/stu/' : '/',// /studata/ 生产环境(打包后)使用目标路径;/ 开发环境(npm run serve)使用根路径,不影响本地开发
  29. configureWebpack: {
  30. optimization: {
  31. minimize: true,
  32. minimizer: [
  33. new TerserPlugin({
  34. terserOptions: {
  35. compress: {
  36. drop_console: process.env.NODE_ENV === 'production', // 只在生产环境移除 console
  37. drop_debugger: process.env.NODE_ENV === 'production', // 只在生产环境移除 debugger
  38. pure_funcs: process.env.NODE_ENV === 'production' ? ['console.log', 'console.info', 'console.warn', 'console.error'] : [],
  39. },
  40. },
  41. }),
  42. ],
  43. },
  44. name: "教学管理大数据平台",
  45. // devtool: "source-map",
  46. // entry:'./public/index.html',
  47. // resolve:{},
  48. // output:{
  49. // filename:'[name].js',
  50. // chunkFilename:'[name].js'
  51. // },
  52. plugins: [
  53. new DonePlugin(),
  54. // new WebpackBar({
  55. // basic: false,
  56. // name: 'JTZX-bigDataAdmin',
  57. // color: 'green'
  58. // })
  59. ],
  60. },
  61. // productionSourceMap: process.env.NODE_ENV !== 'production',
  62. productionSourceMap: false, // 生产环境关闭 sourceMap
  63. css: {
  64. extract: false,
  65. loaderOptions: {
  66. postcss: {
  67. // postcssOptions:{
  68. // plugins: [
  69. // require('postcss-pxtorem')({
  70. // rootValue: 14.4, // 根据设计稿宽度计算,例如设计稿宽度为 1920px,则 rootValue = 1920 / 100 = 19.2
  71. // propList: ['*'], // 需要转换的属性,* 表示所有属性
  72. // selectorBlackList: [], // 忽略的选择器
  73. // replace: false, // 替换 px 为 rem
  74. // mediaQuery: false, // 是否转换媒体查询中的 px
  75. // minPixelValue: 12 // 最小 px 值
  76. // })
  77. // ]
  78. // },
  79. }
  80. },
  81. },
  82. devServer: {
  83. open: false,
  84. hot: true,
  85. host: "",
  86. port: 8080,
  87. https: false,
  88. client: {
  89. overlay: {
  90. warnings: false,
  91. errors: true,
  92. runtimeErrors: false,
  93. },
  94. },
  95. proxy: {
  96. "/api": {
  97. // target: "https://dev3.k12100.net/student/api/",
  98. target: "https://www.k12100.com/student/api/",
  99. changeOrigin: true,
  100. pathRewrite: {
  101. "^/api": "/",
  102. },
  103. },
  104. "/teachingApi": {
  105. target: "https://dev3.k12100.net/teaching/api/",
  106. changeOrigin: true,
  107. pathRewrite: {
  108. "^/teachingApi": "/",
  109. },
  110. }
  111. },
  112. },
  113. };