vue.config.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. var webpack = require("webpack");
  2. var TerserPlugin = require("terser-webpack-plugin");
  3. var CompressionPlugin = require("compression-webpack-plugin");
  4. var devProxy = {};
  5. try {
  6. devProxy = require("./dev-proxy");
  7. } catch (error) {}
  8. var proxy = process.env.NODE_ENV === "production" ? {} : devProxy;
  9. // 配置手册: https://cli.vuejs.org/zh/config/#vue-config-js
  10. var config = {
  11. // publicPath: './',
  12. productionSourceMap: false,
  13. devServer: {
  14. port: 8077
  15. },
  16. transpileDependencies: ["vue-echarts", "resize-detector"],
  17. chainWebpack: config => {
  18. // webpack-chain配置手册:github.com/neutrinojs/webpack-chain#getting-started
  19. // config.plugin("provide").use(webpack.ProvidePlugin, [
  20. // {
  21. // "window.Quill": "quill/dist/quill.js",
  22. // Quill: "quill/dist/quill.js"
  23. // }
  24. // ]);
  25. }
  26. };
  27. // compress配置手册:https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options
  28. if (process.env.NODE_ENV === "production") {
  29. config.configureWebpack = {
  30. plugins: [
  31. // gzip
  32. new CompressionPlugin({
  33. filename: "[path].gz[query]",
  34. algorithm: "gzip",
  35. test: new RegExp("\\.(js|css)$"),
  36. threshold: 10240,
  37. minRatio: 0.8
  38. })
  39. ],
  40. optimization: {
  41. minimizer: [
  42. new TerserPlugin({
  43. terserOptions: { compress: { drop_console: true } }
  44. })
  45. ]
  46. }
  47. };
  48. }
  49. if (proxy && Object.keys(proxy).length) {
  50. config.devServer.proxy = proxy;
  51. }
  52. // 解决iview自定义主题导入less报错
  53. config.css = {
  54. loaderOptions: {
  55. less: {
  56. javascriptEnabled: true
  57. }
  58. }
  59. };
  60. module.exports = config;