vue.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const path = require("path");
  2. const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");
  3. const AutoDllPlugin = require("autodll-webpack-plugin");
  4. function resolve(dir) {
  5. return path.join(__dirname, dir);
  6. }
  7. module.exports = {
  8. assetsDir: "./h5",
  9. publicPath: "./",
  10. outputDir: "cordova/www",
  11. configureWebpack: config => {
  12. Object.assign(config.resolve.alias, {
  13. "@utils": resolve("src/utils"),
  14. "@libs": resolve("src/libs"),
  15. "@api": resolve("src/api"),
  16. "@components": resolve("src/components"),
  17. "@assets": resolve("src/assets"),
  18. "@css": resolve("src/assets/css"),
  19. "@images": resolve("src/assets/images"),
  20. "@views": resolve("src/views"),
  21. "@mixins": resolve("src/mixins")
  22. });
  23. if (process.env.NODE_ENV !== "production") {
  24. config.plugins.push(
  25. new HardSourceWebpackPlugin(),
  26. new AutoDllPlugin({
  27. inject: true,
  28. debug: true,
  29. filename: "[name]_[hash].js",
  30. path: "./dll" + Date.parse(new Date()),
  31. entry: {
  32. vendor_vue: ["vue", "vuex", "vue-router"],
  33. vendor_ui: ["vue-awesome-swiper", "vue-ydui"],
  34. vendor_tools: ["axios", "core-js"]
  35. }
  36. })
  37. );
  38. }
  39. },
  40. chainWebpack: config => {
  41. config.plugin("html").tap(args => {
  42. args[0].VUE_APP_NAME = "美天旺";
  43. return args;
  44. });
  45. },
  46. devServer: {
  47. host: "localhost", //target host
  48. port: 8080,
  49. //proxy:{'/api':{}},代理器中设置/api,项目中请求路径为/api的替换为target
  50. proxy: {
  51. "/api": {
  52. target: "http://twong.h", //代理地址,这里设置的地址会代替axios中设置的baseURL
  53. changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
  54. //ws: true, // proxy websockets
  55. //pathRewrite方法重写url
  56. pathRewrite: {
  57. "^/api": "/api"
  58. //pathRewrite: {'^/api': '/'} 重写之后url为 http://192.168.1.16:8085/xxxx
  59. //pathRewrite: {'^/api': '/api'} 重写之后url为 http://192.168.1.16:8085/api/xxxx
  60. }
  61. }
  62. }
  63. }
  64. };