webpack.production.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //生产环境配置
  2. const path = require('path');
  3. const HtmlWebpackPlugin = require('html-webpack-plugin');
  4. const VueLoaderPlugin = require('vue-loader/lib/plugin');
  5. const {
  6. CleanWebpackPlugin
  7. } = require('clean-webpack-plugin'); //清除文件夹
  8. const CopyWebpackPlugin = require('copy-webpack-plugin'); //复制文件
  9. const WebpackSftpClient = require('webpack-sftp-client'); //打包完成自动上传
  10. module.exports = {
  11. mode: 'production',
  12. output: {
  13. path: path.resolve(__dirname, './../dist'),
  14. filename: 'js/[hash].min.js'
  15. },
  16. plugins: [
  17. new CopyWebpackPlugin([{
  18. from: "src/public",
  19. to:"public"
  20. }]),
  21. new HtmlWebpackPlugin({
  22. template: 'index.html',
  23. minify: {
  24. collapseWhitespace: true, //把生成的 index.html 文件的内容的没用空格去掉,减少空间
  25. },
  26. hash: true, //为了更好的 cache,可以在文件名后加个 hash。
  27. }),
  28. new VueLoaderPlugin(),
  29. /*new WebpackSftpClient({
  30. port: '22', //服务器端口
  31. host: '172.16.90.253', //服务器地址
  32. username: 'root', //用户名
  33. password: 'hywa$123', //密码
  34. path: path.resolve(__dirname, './../dist'), //本地路径
  35. remotePath: '/www/演示项目/湄潭一期/ht-H5', //服务器上的路径
  36. verbose: true
  37. }),*/
  38. new CleanWebpackPlugin()
  39. ]
  40. }