vue.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const path = require('path');
  2. module.exports = {
  3. // 基本路径
  4. publicPath: process.env.NODE_ENV === 'production' ? '' : '/',
  5. // 输出文件目录
  6. outputDir: process.env.NODE_ENV === 'production' ? 'dist' : 'devdist',
  7. // eslint-loader 是否在保存的时候检查
  8. lintOnSave: false,
  9. /**
  10. * webpack配置,see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  11. **/
  12. chainWebpack: (config) => {
  13. const svgRule = config.module.rule("svg");
  14. svgRule.uses.clear()
  15. svgRule
  16. .use("svg-sprite-loader")
  17. .loader("svg-sprite-loader")
  18. .options({
  19. symbolId: "icon-[name]",
  20. include: ["./src/icons"]
  21. });
  22. },
  23. configureWebpack: (config) => {
  24. config.resolve = { // 配置解析别名
  25. extensions: ['.js', '.json', '.vue'],
  26. alias: {
  27. 'vue': 'vue/dist/vue.js',
  28. '@': path.resolve(__dirname, './src'),
  29. 'public': path.resolve(__dirname, './public'),
  30. // 'components': path.resolve(__dirname, './src/components'),
  31. // 'common': path.resolve(__dirname, './src/common'),
  32. // 'api': path.resolve(__dirname, './src/api'),
  33. // 'views': path.resolve(__dirname, './src/views'),
  34. // 'data': path.resolve(__dirname, './src/data')
  35. }
  36. }
  37. },
  38. // 生产环境是否生成 sourceMap 文件
  39. productionSourceMap: false,
  40. // css相关配置
  41. css: {
  42. // 是否使用css分离插件 ExtractTextPlugin
  43. extract: true,
  44. // 开启 CSS source maps?
  45. sourceMap: false,
  46. // css预设器配置项
  47. loaderOptions: {
  48. // 如发现 css.modules 报错,请查看这里:http://www.web-jshtml.cn/#/detailed?id=12
  49. sass:  {
  50. prependData: `@import "./src/style/base.scss";`
  51. }
  52. },
  53. // 启用 CSS modules for all css / pre-processor files.
  54. modules: false
  55. },
  56. // use thread-loader for babel & TS in production build
  57. // enabled by default if the machine has more than 1 cores
  58. parallel: require('os').cpus().length > 1,
  59. /**
  60. * PWA 插件相关配置,see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
  61. */
  62. pwa: {},
  63. // webpack-dev-server 相关配置
  64. devServer: {
  65. open: false, // 编译完成是否打开网页
  66. host: '0.0.0.0', // 指定使用地址,默认localhost,0.0.0.0代表可以被外界访问
  67. port: 8080, // 访问端口
  68. https: false, // 编译失败时刷新页面
  69. hot: true, // 开启热加载
  70. hotOnly: false,
  71. proxy: {
  72. "/devApi": {
  73. target: "http://127.0.0.1:6001/",
  74. // target: "http://tcl.mxnzp.com/tcl-admin/",
  75. // target: "https://www.cretinzp.com/jokes-web-manager/", //API服务器的地址
  76. changeOrigin: true,
  77. pathRewrite: {
  78. "^/devApi": ''
  79. }
  80. },
  81. "/apingtxt": {
  82. target: "http://127.0.0.1:9003/",
  83. // target: "https://www.cretinzp.com/jokes-web-manager/", //API服务器的地址
  84. changeOrigin: true,
  85. pathRewrite: {
  86. "^/devApi": ''
  87. }
  88. }
  89. }, // 设置代理
  90. overlay: { // 全屏模式下是否显示脚本错误
  91. warnings: true,
  92. errors: true
  93. },
  94. before: app => {}
  95. },
  96. /**
  97. * 第三方插件配置
  98. */
  99. pluginOptions: {}
  100. }