vue.config.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. var pages = getEntry();
  44. module.exports = {
  45. productionSourceMap: false, // 生产禁止显示源代码
  46. outputDir: "dist/" + projectname,
  47. pages: pages,
  48. lintOnSave: process.env.NODE_ENV === 'development',
  49. productionSourceMap: false,
  50. devServer: {
  51. port: port,
  52. open: true,
  53. overlay: {
  54. warnings: false,
  55. errors: true
  56. },
  57. proxy: {
  58. [process.env.VUE_APP_BASE_API]: {
  59. target: 'https://test.poteviohealth.com/pmgw/',
  60. // target: 'http://localhost:12017/',
  61. changeOrigin: true,
  62. secure: false,
  63. pathRewrite: {
  64. ['^' + process.env.VUE_APP_BASE_API]: ''
  65. }
  66. }
  67. }
  68. // after: require('./mock/mock-server.js')
  69. },
  70. configureWebpack: {
  71. // provide the app's title in webpack's name field, so that
  72. // it can be accessed in index.html to inject the correct title.
  73. name: name,
  74. resolve: {
  75. alias: {
  76. '@': resolve('src')
  77. }
  78. }
  79. },
  80. };