vue.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. const path = require('path')
  2. const version = require('./package.json').version
  3. const fs = require('fs')
  4. const NODE_ENV = process.env.NODE_ENV
  5. let publicPath = '/flowablePc/'
  6. let outputDir = 'dist'
  7. let appFileName = 'Demo'
  8. if (NODE_ENV === 'lib') {
  9. const libVersionList = fs.readdirSync('./docs/lib')
  10. if (libVersionList.includes(version)) {
  11. console.log(libVersionList);
  12. console.log(version);
  13. throw new Error(`lib 版本 ${version} 已存在`)
  14. }
  15. publicPath = './'
  16. outputDir = `docs/lib/${version}`
  17. appFileName = 'Lib'
  18. }
  19. /* const mainFileStr = `
  20. import Vue from 'vue'
  21. import App from './${appFileName}.vue'
  22. import ElementUI from 'element-ui'
  23. import 'element-ui/lib/theme-chalk/index.css'
  24. Vue.config.productionTip = false
  25. Vue.use(ElementUI)
  26. new Vue({
  27. render: h => h(App)
  28. }).$mount('#app')
  29. `
  30. fs.writeFileSync('./src/main.js', mainFileStr) */
  31. const resolve = dir => {
  32. return path.join(__dirname, dir)
  33. }
  34. module.exports = {
  35. css: {
  36. loaderOptions: {
  37. sass: {
  38. // 配置全局样式变量
  39. }
  40. }
  41. },
  42. publicPath: publicPath,
  43. outputDir: outputDir,
  44. // tweak internal webpack configuration.
  45. // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  46. // 如果你不需要使用eslint,把lintOnSave设为false即可
  47. lintOnSave: true,
  48. chainWebpack: config => {
  49. config.module
  50. .rule('svg')
  51. .exclude.add(resolve('src/icons'))
  52. .end()
  53. config.module
  54. .rule('icons')
  55. .test(/\.svg$/)
  56. .include.add(resolve('src/icons'))
  57. .end()
  58. .use('svg-sprite-loader')
  59. .loader('svg-sprite-loader')
  60. .options({
  61. symbolId: 'icon-[name]'
  62. })
  63. .end()
  64. config.resolve.alias
  65. .set('views', resolve('src/views'))
  66. config
  67. .when(NODE_ENV !== 'development' && NODE_ENV !== 'build',
  68. config => {
  69. config
  70. .optimization.splitChunks({
  71. chunks: 'all',
  72. cacheGroups: {
  73. libs: {
  74. name: 'chunk-libs',
  75. test: /[\\/]node_modules[\\/]/,
  76. priority: 10,
  77. chunks: 'initial' // only package third parties that are initially dependent
  78. },
  79. elementUI: {
  80. name: 'chunk-elementUI', // split elementUI into a single package
  81. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  82. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  83. },
  84. vue: {
  85. name: 'chunk-vue', // split elementUI into a single package
  86. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  87. test: /[\\/]node_modules[\\/]_?vue(.*)/ // in order to adapt to cnpm
  88. }
  89. }
  90. })
  91. config.optimization.runtimeChunk('single')
  92. }
  93. )
  94. },
  95. // 设为false打包时不生成.map文件
  96. productionSourceMap: true,
  97. // 这里写你调用接口的基础路径,来解决跨域,如果设置了代理,那你本地开发环境的axios的baseUrl要写为 '' ,即空字符串
  98. devServer: {
  99. disableHostCheck: true,
  100. proxy: {
  101. '/api': {
  102. // 此处的写法,目的是为了 将 /api 替换成 https://www.baidu.com/
  103. target: 'http://127.0.0.1:7001/',
  104. // 允许跨域
  105. changeOrigin: true,
  106. ws: true,
  107. // pathRewrite: {
  108. // '^/api': '/flowable'
  109. // }
  110. }
  111. }
  112. }
  113. }