vue.config.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  2. const path = require('path')
  3. const CopyWebpackPlugin = require('copy-webpack-plugin')
  4. module.exports = {
  5. // eslint-loader 是否在保存的时候检查
  6. lintOnSave: true,
  7. // webpack配置
  8. configureWebpack: config => {
  9. if (process.env.UNI_PLATFORM === 'h5') {
  10. // 开启gzip压缩
  11. config.plugins = [
  12. ...config.plugins,
  13. new CompressionWebpackPlugin({
  14. filename: '[path].gz[query]',
  15. algorithm: 'gzip',
  16. test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'),
  17. threshold: 8192,
  18. minRatio: 0.8,
  19. }),
  20. ]
  21. // public目录下文件文件设置为静态资源目录
  22. config.plugins = [
  23. ...config.plugins,
  24. new CopyWebpackPlugin([
  25. {
  26. from: path.join(__dirname, 'public'),
  27. to: path.join(__dirname, 'dist', process.env.NODE_ENV === 'production' ? 'build' : 'dev', process.env.UNI_PLATFORM),
  28. },
  29. ]),
  30. ]
  31. }
  32. },
  33. // 生产环境是否生成 sourceMap 文件
  34. productionSourceMap: false,
  35. // css相关配置
  36. css: {
  37. sourceMap: process.env.NODE_ENV !== 'production',
  38. loaderOptions: {
  39. scss: {
  40. prependData: `@import "~@/common/scss/public.scss";`,
  41. },
  42. },
  43. },
  44. // webpack-dev-server 相关配置
  45. devServer: {
  46. open: false, // 配置自动启动浏览器
  47. port: 8080, // 端口号
  48. https: false,
  49. hotOnly: true,
  50. disableHostCheck: true,
  51. proxy: '',// 设置代理
  52. },
  53. // 第三方插件配置
  54. pluginOptions: {},
  55. }