vue.config.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const path = require('path');
  2. const Setting = require('./src/setting.env');
  3. // 引入打包分析文件
  4. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  5. // 引入js打包工具
  6. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  7. const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
  8. const resolve = (dir) => {
  9. return path.join(__dirname, dir);
  10. };
  11. // 项目部署基础
  12. // 默认情况下,我们假设你的应用将被部署在域的根目录下,
  13. // 例如:https://www.my-app.com/
  14. // 默认:'/'
  15. // 如果您的应用程序部署在子路径中,则需要在这指定子路径
  16. // 例如:https://www.foobar.com/my-app/
  17. // 需要将它改为'/my-app/'
  18. // iview-admin线上演示打包路径: https://file.iviewui.com/admin-dist/
  19. const BASE_URL = process.env.NODE_ENV === 'production' ? '/' : '/';
  20. const env = process.env.NODE_ENV;
  21. module.exports = {
  22. // Project deployment base
  23. // By default we assume your app will be deployed at the root of a domain,
  24. // e.g. https://www.my-app.com/
  25. // If your app is deployed at a sub-path, you will need to specify that
  26. // sub-path here. For example, if your app is deployed at
  27. // https://www.foobar.com/my-app/
  28. // then change this to '/my-app/'
  29. outputDir: Setting.outputDir,
  30. runtimeCompiler: true,
  31. productionSourceMap: false, //关闭生产环境下的SourceMap映射文件
  32. baseUrl: BASE_URL,
  33. // tweak internal webpack configuration.
  34. // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  35. // 如果你不需要使用eslint,把lintOnSave设为false即可
  36. lintOnSave: false,
  37. // 打包优化
  38. configureWebpack: (config) => {
  39. const pluginsPro = [];
  40. pluginsPro.push(
  41. // js文件压缩
  42. new UglifyJsPlugin({
  43. uglifyOptions: {
  44. compress: {
  45. drop_debugger: true,
  46. drop_console: true, //生产环境自动删除console
  47. pure_funcs: ['console.log'], //移除console
  48. },
  49. },
  50. sourceMap: false,
  51. parallel: true, //使用多进程并行运行来提高构建速度。默认并发运行数:os.cpus().length - 1。
  52. }),
  53. );
  54. if (process.env.NODE_ENV === 'production') {
  55. config.plugins = [...config.plugins, ...pluginsPro];
  56. }
  57. if (process.env.NODE_ENV === 'production') {
  58. // 开启分离js
  59. // config.optimization = {
  60. // runtimeChunk: 'single',
  61. // splitChunks: {
  62. // chunks: 'all',
  63. // maxInitialRequests: Infinity,
  64. // minSize: 20000,
  65. // cacheGroups: {
  66. // vendor: {
  67. // test: /[\\/]node_modules[\\/]/,
  68. // name(module) {
  69. // // get the name. E.g. node_modules/packageName/not/this/part.js
  70. // // or node_modules/packageName
  71. // const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
  72. // // npm package names are URL-safe, but some servers don't like @ symbols
  73. // return `npm.${packageName.replace('@', '')}`;
  74. // },
  75. // },
  76. // },
  77. // },
  78. // };
  79. }
  80. },
  81. chainWebpack: (config) => {
  82. config.resolve.alias
  83. .set('@', resolve('src')) // key,value自行定义,比如.set('@@', resolve('src/components'))
  84. .set('_c', resolve('src/components'));
  85. // 使用 iView Loader
  86. config.module
  87. .rule('vue')
  88. .test(/\.vue$/)
  89. .use('iview-loader')
  90. .loader('iview-loader')
  91. .tap(() => {
  92. return Setting.iviewLoaderOptions;
  93. })
  94. .end();
  95. // 重新设置 alias
  96. config.resolve.alias.set('@api', resolve('src/api'));
  97. // node
  98. config.node.set('__dirname', true).set('__filename', true);
  99. config.plugin('monaco').use(new MonacoWebpackPlugin());
  100. },
  101. // 设为false打包时不生成.map文件
  102. productionSourceMap: false,
  103. // 这里写你调用接口的基础路径,来解决跨域,如果设置了代理,那你本地开发环境的axios的baseUrl要写为 '' ,即空字符串
  104. devServer: {
  105. port: 1617, //端口号
  106. proxy: {
  107. // "/adminapi": {
  108. '/adminapi': {
  109. // "target" : "https://www.psgjsc.com" ,//目标接口域名
  110. target: 'https://liaoningaoxun.com', //目标接口域名
  111. ws: true,
  112. changeOrigin: true,
  113. // "secure" : true ,// 设置支持https协议的代理
  114. // "pathRewrite" : {
  115. // "/adminapi" : "" // rewrite path
  116. // }
  117. },
  118. }
  119. },
  120. publicPath: '/admin',
  121. assetsDir: 'system_static',
  122. indexPath: 'index.html',
  123. };