vue.config.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. loaderOptions: {
  25. postcss: {
  26. postcssOptions: {
  27. config: process.env.VUE_APP_ROOT, // 自定义 postcss.config.js 文件路径,https://webpack.docschina.org/loaders/postcss-loader/#postcss-options
  28. }
  29. }
  30. }
  31. },
  32. chainWebpack: (config) => {
  33. config.resolve.alias
  34. .set('@' + process.env.VUE_APP_ENV, resolve(__dirname, process.env.VUE_APP_ROOT))
  35. config.plugin('compressionPlugin')
  36. .use(new CompressionPlugin({
  37. test: /\.js$|\.html$|\.css/, // 匹配文件名
  38. threshold: 10240, // 对超过10k的数据压缩
  39. }))
  40. config.plugin('fork-ts-checker')
  41. .use(new ForkTsCheckerWebpackPlugin({
  42. typescript: {
  43. memoryLimit: 4096,
  44. },
  45. }))
  46. }
  47. })