vue.config.js 2.7 KB

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