vue.config.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const path = require("path");
  2. function resolve(dir) {
  3. return path.join(__dirname, dir);
  4. }
  5. module.exports = {
  6. publicPath: './',
  7. outputDir: process.env.VUE_APP_outputDir || 'dist',
  8. assetsDir: 'static',
  9. filenameHashing: true,
  10. lintOnSave: false,
  11. runtimeCompiler: false,
  12. transpileDependencies: [],
  13. productionSourceMap: false,
  14. css: {
  15. // 是否使用css分离插件 ExtractTextPlugin
  16. extract: process.env.NODE_ENV === "production" ? true : false,
  17. sourceMap: false,
  18. // requireModuleExtension: true,
  19. loaderOptions: {
  20. sass: {
  21. prependData: `@import "@/assets/css/variable.scss";`
  22. }
  23. }
  24. },
  25. chainWebpack: (config) => {
  26. config
  27. .plugin('html')
  28. .tap(args => {
  29. args[0].title = '哈尔滨市托育综合服务中心建设项目'
  30. return args
  31. })
  32. // 配置别名
  33. config.resolve.alias
  34. .set('@', resolve('src'))
  35. .set('assets', resolve('src/assets'))
  36. .set('components', resolve('src/components'))
  37. .set('views', resolve('src/views'))
  38. .set('api', resolve('src/api'))
  39. if (process.env.NODE_ENV === "production") {
  40. // 删除系统默认的splitChunk
  41. config.optimization.delete("splitChunks");
  42. }
  43. },
  44. configureWebpack: config => {
  45. // 给输出的js名称添加hash
  46. config.output.filename = "static/js/[name].[hash].js";
  47. config.output.chunkFilename = "static/js/[name].[hash].js";
  48. config.optimization = {
  49. splitChunks: {
  50. cacheGroups: {
  51. // 抽离所有入口的公用资源为一个chunk
  52. common: {
  53. name: "chunk-common",
  54. chunks: "initial",
  55. minChunks: 2,
  56. maxInitialRequests: 5,
  57. minSize: 0,
  58. priority: 1,
  59. reuseExistingChunk: true,
  60. enforce: true
  61. },
  62. datav: {
  63. name: "chunk-datav",
  64. test: /[\\/]node_modules[\\/]@jiaminghi[\\/]data-view[\\/]/,
  65. chunks: "all",
  66. priority: 4,
  67. reuseExistingChunk: true,
  68. enforce: true
  69. },
  70. }
  71. }
  72. };
  73. },
  74. // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。
  75. parallel: require('os').cpus().length > 1,
  76. devServer: {
  77. proxy: {
  78. '/x_program_center': {
  79. target: 'http://www.harbinxiaoshi.cn:8000',
  80. pathRewrite: {
  81. '^/x_program_center': ''
  82. }
  83. }
  84. }
  85. }
  86. };