vue.config.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const { resolve } = require('path')
  2. const { defineConfig } = require('@vue/cli-service')
  3. const moment = require('moment')
  4. const CompressionPlugin = require('compression-webpack-plugin')
  5. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
  6. module.exports = defineConfig({
  7. transpileDependencies: [/node_modules/],
  8. productionSourceMap: false, // 打包取消.map
  9. publicPath: './',
  10. pages: {
  11. indexPath: {
  12. entry: process.env.VUE_APP_ROOT + 'main.ts',
  13. template: process.env.VUE_APP_ROOT + 'index.html',
  14. filename: 'index.html',
  15. title: process.env.VUE_APP_TITLE,
  16. meta: {
  17. revised: moment(new Date()).format('YYYYMMDDHHmmss') // 打包生成版本号
  18. }
  19. }
  20. },
  21. css: {
  22. extract: true, // 是否使用css分离插件 ExtractTextPlugin
  23. sourceMap: false,
  24. },
  25. chainWebpack: (config) => {
  26. config.resolve.alias
  27. .set('@' + process.env.VUE_APP_ENV, resolve(__dirname, process.env.VUE_APP_ROOT))
  28. config.plugin('compressionPlugin')
  29. .use(new CompressionPlugin({
  30. test: /\.js$|\.html$|\.css/, // 匹配文件名
  31. threshold: 10240, // 对超过10k的数据压缩
  32. }))
  33. config.plugin('fork-ts-checker')
  34. .use(new ForkTsCheckerWebpackPlugin({
  35. typescript: {
  36. memoryLimit: 4096,
  37. },
  38. }))
  39. }
  40. })