vue.config.js 2.9 KB

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