vue.config.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const path = require('path');
  2. const resolve = dir => {
  3. return path.join(__dirname, dir);
  4. };
  5. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  6. const CompressionWebpackPlugin = require('compression-webpack-plugin');
  7. const productionGzipExtensions = ['js', 'css'];
  8. // 项目部署基础
  9. // 默认情况下,我们假设你的应用将被部署在域的根目录下,
  10. // 例如:https://www.my-app.com/
  11. // 默认:'/'
  12. // 如果您的应用程序部署在子路径中,则需要在这指定子路径
  13. // 例如:https://www.foobar.com/my-app/
  14. // 需要将它改为'/my-app/'
  15. const publicPath = process.env.NODE_ENV === 'production' ? '/' : '/';
  16. const lintOnSave = process.env.NODE_ENV === 'production';
  17. module.exports = {
  18. devServer: {
  19. disableHostCheck: true
  20. },
  21. // Project deployment base
  22. // By default we assume your app will be deployed at the root of a domain,
  23. // e.g. https://www.my-app.com/
  24. // If your app is deployed at a sub-path, you will need to specify that
  25. // sub-path here. For example, if your app is deployed at
  26. // https://www.foobar.com/my-app/
  27. // then change this to '/my-app/'
  28. publicPath,
  29. // tweak internal webpack configuration.
  30. // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  31. // 如果你不需要使用eslint,把lintOnSave设为false即可
  32. lintOnSave:false,
  33. chainWebpack: config => {
  34. config.entry = {
  35. main: ['babel-polyfill', './src/main'],
  36. vendors: './src/vendors'
  37. };
  38. // config.entry('polyfill').add('@babel/polyfill')
  39. // config.module
  40. // .rule('view-design')
  41. // .test(/view-design.src.*?js$/)
  42. // .use('babel')
  43. // .loader('babel-loader')
  44. // .end();
  45. config.resolve.alias
  46. .set('@', resolve('src')) // key,value自行定义,比如.set('@@', resolve('src/components'))
  47. .set('_c', resolve('src/components'));
  48. if (process.env.use_analyzer) { // 分析
  49. config
  50. .plugin('webpack-bundle-analyzer')
  51. .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  52. }
  53. },
  54. transpileDependencies:['flyio'],
  55. // 设为false打包时不生成.map文件
  56. productionSourceMap: false,
  57. // 这里写你调用接口的基础路径,来解决跨域,如果设置了代理,那你本地开发环境的axios的baseUrl要写为 '' ,即空字符串
  58. // devServer: {
  59. // proxy: 'localhost:3000'
  60. // }
  61. configureWebpack: {
  62. plugins: [
  63. // 开启gzip压缩
  64. new CompressionWebpackPlugin({
  65. algorithm: 'gzip',
  66. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  67. threshold: 10240,
  68. minRatio: 0.8
  69. })
  70. ],
  71. optimization: {
  72. minimizer: [
  73. new UglifyJsPlugin({
  74. uglifyOptions: {
  75. compress: {
  76. warnings: true,
  77. drop_console: true, // console
  78. drop_debugger: true,
  79. pure_funcs: ['console.log'] // 移除console
  80. }
  81. }
  82. })
  83. ]
  84. }
  85. }
  86. };