vue.config.js 3.33 KB
Newer Older
xulili's avatar
xulili committed
1 2 3 4 5 6 7

// 拼接路径
const resolve = dir => require('path').join(__dirname, dir)

// 基础路径 注意发布之前要先修改这里
const publicPath = '/'

Z's avatar
Z committed
8
module.exports = {
xulili's avatar
xulili committed
9 10 11 12 13 14 15 16 17 18
  publicPath, // 根据你的实际情况更改这里
  lintOnSave: true,
  devServer: {
    publicPath, // 和 publicPath 保持一致
    disableHostCheck: false,
    https: false,
    hotOnly: false, // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#configuring-proxy
    proxy: {
      '/api': {
        ws: false,
19
        target: 'http://111.26.165.55:8010/crminterface.ashx',
xulili's avatar
xulili committed
20 21 22
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
Z's avatar
Z committed
23
        }
xulili's avatar
xulili committed
24
      },
xulili's avatar
xulili committed
25 26 27 28 29 30 31 32
      '/wxx': {
        ws: false,
        target: 'https://api.weixin.qq.com',
        changeOrigin: true,
        pathRewrite: {
          '^/wxx': ''
        }
      },
Z's avatar
Z committed
33
    }
xulili's avatar
xulili committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: `@import "~@/assets/style/public.scss";`,
      },
    }
  },

  // 默认设置: https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-service/lib/config/base.js
  chainWebpack: config => {
    /**
     * 删除懒加载模块的 prefetch preload,降低带宽压力
     * https://cli.vuejs.org/zh/guide/html-and-static-assets.html#prefetch
     * https://cli.vuejs.org/zh/guide/html-and-static-assets.html#preload
     * 而且预渲染时生成的 prefetch 标签是 modern 版本的,低版本浏览器是不需要的
     */
    config.plugins.delete('prefetch').delete('preload')
    // 解决 cli3 热更新失效 https://github.com/vuejs/vue-cli/issues/1559
    config.resolve.symlinks(true)
    config
    // 开发环境
      .when(
        process.env.NODE_ENV === 'development',
        // sourcemap不包含列信息
        config => config.devtool('cheap-source-map')
      )
    // .when(process.env.NODE_ENV !== 'development', config => {
    //   config.optimization
    //     .minimizer([
    //       new UglifyJsPlugin({
    //         uglifyOptions: {
    //           // 移除 console
    //           // 其它优化选项 https://segmentfault.com/a/1190000010874406
    //           compress: {
    //             warnings: false,
    //             drop_console: true,
    //             drop_debugger: true,
    //             pure_funcs: ['console.log']
    //           }
    //         }
    //       })
    //     ])
    // })
    // // markdown
    // config.module
    //   .rule('md')
    //   .test(/\.md$/)
    //   .use('text-loader')
    //   .loader('text-loader')
    //   .end()
    // // i18n
    // config.module
    //   .rule('i18n')
    //   .resourceQuery(/blockType=i18n/)
    //   .use('i18n')
    //   .loader('@kazupon/vue-i18n-loader')
    //   .end()
    // svg
    const svgRule = config.module.rule('svg')
    svgRule.uses.clear()
    svgRule.include
      .add(resolve('src/assets/svg-icons/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'd2-[name]'
      })
      .end()
    // image exclude
    const imagesRule = config.module.rule('images')
    imagesRule
      .test(/\.(png|jpe?g|gif|webp|svg)(\?.*)?$/)
      .exclude.add(resolve('src/assets/svg-icons/icons'))
      .end()
    // 重新设置 alias
    config.resolve.alias.set('@api', resolve('src/api'))
    // node
    config.node.set('__dirname', true).set('__filename', true)
  }
}