vue.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. devServer: {
  13. port: 8076
  14. },
  15. chainWebpack: config => {
  16. // webpack-chain配置手册:github.com/neutrinojs/webpack-chain#getting-started
  17. // config.plugin("provide").use(webpack.ProvidePlugin, [
  18. // {
  19. // "window.Quill": "quill/dist/quill.js",
  20. // Quill: "quill/dist/quill.js"
  21. // }
  22. // ]);
  23. }
  24. };
  25. // compress配置手册:https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options
  26. if (process.env.NODE_ENV === "production") {
  27. config.configureWebpack = {
  28. plugins: [
  29. // gzip
  30. new CompressionPlugin({
  31. filename: "[path].gz[query]",
  32. algorithm: "gzip",
  33. test: new RegExp("\\.(js|css)$"),
  34. threshold: 10240,
  35. minRatio: 0.8
  36. })
  37. ],
  38. optimization: {
  39. minimizer: [
  40. new TerserPlugin({
  41. terserOptions: { compress: { drop_console: true } }
  42. })
  43. ]
  44. }
  45. };
  46. }
  47. if (proxy && Object.keys(proxy).length) {
  48. config.devServer.proxy = proxy;
  49. }
  50. // 解决iview自定义主题导入less报错
  51. config.css = {
  52. loaderOptions: {
  53. less: {
  54. javascriptEnabled: true
  55. }
  56. }
  57. };
  58. module.exports = config;