转自:https://www.yuque.com/dukang-hfttn/mo27v1/flcggg

    1. const path = require('path')
    2. const resolve = dir => path.join(__dirname, dir)
    3. console.log('=======开始编译=======')
    4. // 在发送请求之前重写路径
    5. // '/api': {
    6. // target: 'http://api.xxxxx.com',
    7. // ws: true,
    8. // changOrigin: true,
    9. // pathRewrite: {
    10. // '^/api': ''
    11. // }
    12. // }
    13. module.exports = {
    14. // 基本路径
    15. baseUrl: process.env.NODE_ENV === 'production' ? '/production-sub-path/' : '/',
    16. // 它支持webPack-dev-server的所有选项
    17. devServer: {
    18. open: true, // 自动打开浏览器
    19. host: 'vue.xxxxx.com', // 配置启动域名或IP
    20. port: 80, // 端口号
    21. https: false, // 是否开启HTTPS
    22. hotOnly: false,
    23. // 设置代理
    24. proxy: {
    25. '/api': {
    26. target: 'http://api.xxxxx.com',
    27. ws: true,
    28. changOrigin: true
    29. }
    30. },
    31. before: app => {}
    32. },
    33. // 构建输出目录
    34. outputDir: 'dist',
    35. // 静态资源目录 (js, css, img, fonts)
    36. assetsDir: 'assets',
    37. // 是否开启eslint保存检测,有效值:ture | false | 'error'
    38. lintOnSave: true,
    39. // 运行时版本是否需要编译
    40. runtimeCompiler: true,
    41. // 默认babel-loader忽略mode_modules,这里可增加例外的依赖包名
    42. transpileDependencies: [],
    43. /**
    44. * 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
    45. * 打包之后发现map文件过大,项目文件体积很大,设置为false就可以不输出map文件
    46. * map文件的作用在于:项目打包后,代码都是经过压缩加密的,如果运行时报错,输出的错误信息无法准确得知是哪里的代码报错。
    47. * 有了map就可以像未加密的代码一样,准确的输出是哪一行哪一列有错。
    48. * */
    49. productionSourceMap: true,
    50. // webpack配置,值位对象时会合并配置,为方法时会改写配置
    51. configureWebpack: config => {},
    52. /**
    53. * webpack链接API,用于生成和修改webapck配置
    54. * 配置路径别名
    55. * @Author 杜康
    56. * @DateTime 2018-09-20T15:28:18+0800
    57. * @copyright Copyright©杜康
    58. * @version [version]
    59. * @param {[type]} config [description]
    60. * @return {[type]} [description]
    61. */
    62. chainWebpack: config => {
    63. config.resolve.alias
    64. .set('@', resolve('src'))
    65. .set('assets', resolve('src/assets'))
    66. .set('router', resolve('src/router'))
    67. .set('store', resolve('src/store'))
    68. .set('components', resolve('src/components'))
    69. .set('views', resolve('src/views'))
    70. .set('utils', resolve('src/utils'))
    71. .set('api', resolve('src/api'))
    72. .set('styles', resolve('src/styles'))
    73. .set('menus', resolve('src/menus'))
    74. },
    75. // 配置高于chainWebpack中关于css loader的配置
    76. css: {
    77. /**
    78. * 是否开启支持‘foo.module.css’样式
    79. * 建议关闭,开启后会报ElementUI组件找不到的问题
    80. * @type {Boolean}
    81. */
    82. modules: false,
    83. /**
    84. * 是否使用css分离插件
    85. * ExtractTextPlugin,采用独立样式文件载入,
    86. * 不采用<style>方式内联至html文件中
    87. * @type {Boolean}
    88. */
    89. extract: true,
    90. // 是否在构建样式地图,false将提高构建速度
    91. sourceMap: false,
    92. // css预设器配置项
    93. loaderOptions: {
    94. css: {
    95. localIdentName: '[name]',
    96. camelCase: 'only'
    97. },
    98. stylus: {}
    99. }
    100. },
    101. // 构建时开启多进程处理babel编译
    102. parallel: require('os').cpus().length > 1,
    103. // 第三方插件配置
    104. pluginOptions: {},
    105. // 单页插件相关配置 https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
    106. pwa: {}
    107. }