vue.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. const path = require('path');
  2. const resolve = (dir) => path.join(__dirname, dir);
  3. const CopyWebpackPlugin = require('copy-webpack-plugin');
  4. const webpack = require('webpack');
  5. function extendDefaultPlugins(arr) {
  6. let plug = [
  7. 'removeDoctype',
  8. 'removeXMLProcInst',
  9. 'removeComments',
  10. 'removeMetadata',
  11. 'removeEditorsNSData',
  12. 'cleanupAttrs',
  13. 'mergeStyles',
  14. 'inlineStyles',
  15. 'minifyStyles',
  16. 'cleanupIDs',
  17. 'removeUselessDefs',
  18. 'cleanupNumericValues',
  19. 'convertColors',
  20. 'removeUnknownsAndDefaults',
  21. 'removeNonInheritableGroupAttrs',
  22. 'removeUselessStrokeAndFill',
  23. 'removeViewBox',
  24. 'cleanupEnableBackground',
  25. 'removeHiddenElems',
  26. 'removeEmptyText',
  27. 'convertShapeToPath',
  28. 'convertEllipseToCircle',
  29. 'moveElemsAttrsToGroup',
  30. 'moveGroupAttrsToElems',
  31. 'collapseGroups',
  32. 'convertPathData',
  33. 'convertTransform',
  34. 'removeEmptyAttrs',
  35. 'removeEmptyContainers',
  36. 'mergePaths',
  37. 'removeUnusedNS',
  38. 'sortDefsChildren',
  39. 'removeTitle',
  40. 'removeDesc'
  41. ];
  42. return plug.concat(arr);
  43. }
  44. // 添加less继承
  45. function addStyleResource(rule) {
  46. rule.use('style-resource')
  47. .loader('style-resources-loader')
  48. .options({
  49. patterns: [
  50. resolve('src/assets/styles/common/common.less')
  51. ]
  52. })
  53. }
  54. module.exports = {
  55. publicPath: "./", // 默认'/',部署应用包时的基本 URL
  56. indexPath: 'index.html', // 相对于打包路径index.html的路径
  57. outputDir: 'dist', // 'dist', 生产环境构建文件的目录
  58. assetsDir: 'static', // 相对于outputDir的静态资源(js、css、img、fonts)目录
  59. lintOnSave: false, // 是否在开发环境下通过 eslint-loader 在每次保存时 li
  60. runtimeCompiler: true, // 是否使用包含运行时编译器的 Vue 构建版本
  61. pluginOptions: {
  62. windicss: {
  63. // see https://github.com/windicss/vite-plugin-windicss/blob/main/packages/plugin-utils/src/options.ts
  64. },
  65. },
  66. configureWebpack: {
  67. plugins: [
  68. ],
  69. module:{
  70. rules: [
  71. {
  72. test: /\.js$/,
  73. use: {
  74. loader: '@open-wc/webpack-import-meta-loader',
  75. },
  76. },
  77. ]
  78. }
  79. },
  80. chainWebpack: (config) => {
  81. config.resolve.symlinks(true); // 修复热更新失效
  82. config.plugin('html')
  83. .tap(args => {
  84. args[0].title = "新能源区域集控运行管理系统";
  85. return args;
  86. })
  87. // 路径别名
  88. config.resolve.alias
  89. .set("@", resolve("src"))
  90. .set("@node", resolve("node_modules"))
  91. .set("@com", resolve("src/components"))
  92. .set("@assets", resolve("src/assets"))
  93. .set("@api", resolve("src/api"))
  94. .set("@store", resolve("src/store"))
  95. .set("@modeConfig", resolve("public/static/config"))
  96. .set("@tools", resolve("src/tools"))
  97. .set("cesium", resolve("node_modules/cesium/Source"));
  98. // less 继承
  99. const types = ['vue-modules', 'vue', 'normal-modules', 'normal'];
  100. types.forEach(type => addStyleResource(config.module.rule('less').oneOf(type)));
  101. const metaLoaderRule = config.module.rule('meta-loader');
  102. metaLoaderRule.test(/\.js$/)
  103. .use('@open-wc/webpack-import-meta-loader')
  104. .loader('@open-wc/webpack-import-meta-loader');
  105. // svg 雪碧图
  106. config.module // 排除其他svg-loader
  107. .rule('svg')
  108. .exclude.add(resolve('src/assets/icon/svg'))
  109. .end()
  110. .exclude.add(resolve('src/assets/icon/svg_fill'))
  111. .end();
  112. // svg雪碧图
  113. const svgRule = config.module.rule('icons');
  114. svgRule.test(/\.svg$/)
  115. .include.add(resolve('src/assets/icon/svg'))
  116. .end()
  117. .use('svg-sprite-loader')
  118. .loader('svg-sprite-loader')
  119. .options({
  120. symbolId: 'svg-[name]'
  121. });
  122. // svgo 去除svg中无用元素
  123. svgRule.use('svgo-loader').loader('svgo-loader').options({
  124. plugins: extendDefaultPlugins([{
  125. name: "removeAttrs",
  126. params: {
  127. attrs: 'fill',
  128. }
  129. }])
  130. });
  131. },
  132. devServer: {
  133. //代理配置
  134. proxy: {
  135. '/cbk': {
  136. target: 'http://192.168.11.109:18701', // 请求地址
  137. changeOrigin: true, // 在vue-cli3中,默认changeOrigin的值是true,意味着服务器host设置成target,这与vue-cli2不一致,vue-cli2这个默认值是false
  138. // changeOrigin的值是true,target是host, request URL是http://baidu.com
  139. // 如果设置changeOrigin: false,host就是浏览器发送过来的host,也就是localhost:8082。
  140. pathRewrite: { // 路径重写,eg:把api接口替换为''
  141. '^/cbk': ''
  142. }
  143. }
  144. },
  145. open: false, // 是否打开浏览器
  146. }
  147. }