vue.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. var projectname = process.argv[3];
  2. var glob = require("glob");
  3. var publicPath = ''
  4. function getEntry() {
  5. var entries = {};
  6. if (process.env.NODE_ENV == "production") {
  7. entries = {
  8. index: {
  9. // page的入口
  10. entry: "src/views/" + projectname + "/main.js",
  11. // 模板来源
  12. template: "public/index.html",
  13. // 在 dist/index.html 的输出
  14. filename: "index.html",
  15. title: projectname,
  16. chunks: ["chunk-vendors", "chunk-common", "index"]
  17. }
  18. };
  19. publicPath = '/' + projectname + '/'
  20. } else {
  21. var items = glob.sync("./src/views/*/*.js");
  22. for (var i in items) {
  23. var filepath = items[i];
  24. var fileList = filepath.split("/");
  25. var fileName = fileList[fileList.length - 2];
  26. publicPath = '/' + fileName + '/'
  27. entries[fileName] = {
  28. entry: `src/views/${fileName}/main.js`,
  29. // 模板来源
  30. template: `public/index.html`,
  31. // 在 dist/index.html 的输出
  32. filename: `${fileName}.html`,
  33. };
  34. }
  35. }
  36. return entries;
  37. }
  38. const path = require('path')
  39. function resolve(dir) {
  40. return path.join(__dirname, dir)
  41. }
  42. const port = process.env.port || process.env.npm_config_port || 12004 // dev port
  43. const name = 'vue Admin Template' // page title
  44. console.log('projectname===')
  45. // console.log(process.argv)
  46. // console.log(projectname)
  47. console.log(publicPath)
  48. var pages = getEntry();
  49. module.exports = {
  50. // publicPath:'/weibao/',
  51. publicPath: publicPath,
  52. productionSourceMap: false, // 生产禁止显示源代码
  53. outputDir: "dist/" + projectname,
  54. pages: pages,
  55. lintOnSave: process.env.NODE_ENV === 'development',
  56. productionSourceMap: false,
  57. devServer: {
  58. port: port,
  59. open: true,
  60. overlay: {
  61. warnings: false,
  62. errors: true
  63. },
  64. proxy: {
  65. [process.env.VUE_APP_BASE_API]: {
  66. target: 'https://test.poteviohealth.com/pmgw/',
  67. // target: 'http://localhost:12017/',
  68. changeOrigin: true,
  69. secure: false,
  70. pathRewrite: {
  71. ['^' + process.env.VUE_APP_BASE_API]: ''
  72. }
  73. }
  74. }
  75. // after: require('./mock/mock-server.js')
  76. },
  77. configureWebpack: {
  78. // provide the app's title in webpack's name field, so that
  79. // it can be accessed in index.html to inject the correct title.
  80. name: name,
  81. resolve: {
  82. alias: {
  83. '@': resolve('src')
  84. }
  85. }
  86. },
  87. };