plugins.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // const path = require('path')
  2. const webpack = require('webpack')
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. const VueLoaderPlugin = require('vue-loader/lib/plugin')
  5. const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
  6. const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
  7. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  8. module.exports = (env, defineEnv, publicPath, port, appHtml) => [
  9. appHtml && new webpack.DefinePlugin({
  10. 'process.env': {
  11. PUBLIC_PATH: `"${publicPath}"`,
  12. ...defineEnv[env],
  13. },
  14. }),
  15. appHtml && new HtmlWebpackPlugin(
  16. Object.assign(
  17. {},
  18. {
  19. template: appHtml,
  20. inject: true,
  21. },
  22. env === 'development'
  23. ? undefined
  24. : {
  25. minify: {
  26. collapseWhitespace: true,
  27. removeAttributeQuotes: true,
  28. removeComments: true,
  29. },
  30. }
  31. )
  32. ),
  33. new VueLoaderPlugin(),
  34. env === 'development' && new webpack.HotModuleReplacementPlugin(),
  35. env === 'development' && new CaseSensitivePathsPlugin(),
  36. env === 'development' && new FriendlyErrorsWebpackPlugin({
  37. compilationSuccessInfo: {
  38. messages: [
  39. `Your app is running here http://localhost:${port}`,
  40. ],
  41. },
  42. }),
  43. env !== 'development' && new webpack.HashedModuleIdsPlugin(),
  44. env !== 'development' && (
  45. appHtml
  46. ? new MiniCssExtractPlugin({
  47. filename: 'assets/styles/[name].[contenthash:8].css',
  48. chunkFilename: 'assets/styles/[name].[contenthash:8].chunk.css',
  49. })
  50. : new MiniCssExtractPlugin({
  51. filename: 'reverse.css',
  52. chunkFilename: 'reverse.chunk.css',
  53. })
  54. ),
  55. ].filter(Boolean)