vue.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. const path = require('path');
  11. // 引入js打包工具
  12. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  13. const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
  14. const resolve = (dir) => {
  15. return path.join(__dirname, dir);
  16. };
  17. // 项目部署基础
  18. module.exports = {
  19. // 打包路径
  20. outputDir: 'dist',
  21. // 打包路径--线上部署文件地址
  22. // outputDir: '../../crmeb/public/admin',
  23. runtimeCompiler: true,
  24. productionSourceMap: false, //关闭生产环境下的SourceMap映射文件
  25. // 如果你不需要使用eslint,把lintOnSave设为false即可
  26. lintOnSave: false,
  27. // 打包优化
  28. configureWebpack: (config) => {
  29. const pluginsPro = [];
  30. pluginsPro.push(
  31. // js文件压缩
  32. new UglifyJsPlugin({
  33. uglifyOptions: {
  34. compress: {
  35. drop_debugger: true,
  36. drop_console: true, //生产环境自动删除console
  37. pure_funcs: ['console.log'], //移除console
  38. },
  39. },
  40. sourceMap: false,
  41. parallel: true, //使用多进程并行运行来提高构建速度。默认并发运行数:os.cpus().length - 1。
  42. }),
  43. );
  44. if (process.env.NODE_ENV === 'production') {
  45. config.plugins = [...config.plugins, ...pluginsPro];
  46. }
  47. },
  48. css: {
  49. loaderOptions: {
  50. scss: {
  51. sassOptions: {
  52. silenceDeprecations: ['legacy-js-api'],
  53. },
  54. },
  55. },
  56. },
  57. chainWebpack: (config) => {
  58. config.plugins.delete('prefetch');
  59. config.resolve.alias
  60. .set('@', resolve('src')) // key,value自行定义,比如.set('@@', resolve('src/components'))
  61. .set('_c', resolve('src/components'));
  62. config.module
  63. .rule('vue')
  64. .test(/\.vue$/)
  65. .end();
  66. // 重新设置 alias
  67. config.resolve.alias.set('@api', resolve('src/api'));
  68. // node
  69. config.node.set('__dirname', true).set('__filename', true);
  70. config.plugin('monaco').use(new MonacoWebpackPlugin());
  71. },
  72. // 设为false打包时不生成.map文件
  73. productionSourceMap: false,
  74. // 这里写你调用接口的基础路径,来解决跨域,如果设置了代理,那你本地开发环境的axios的baseUrl要写为 '' ,即空字符串
  75. devServer: {
  76. port: 1617, // 端口
  77. },
  78. publicPath: '/admin',
  79. assetsDir: 'system_static',
  80. indexPath: 'index.html',
  81. };