webpack.common.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. const CleanWebpackPlugin = require('clean-webpack-plugin')
  2. const { HTMLWebpackPlugins, entry } = require('./_build/genMultiEntry.js')
  3. const webpack = require('webpack')
  4. const path = require('path')
  5. module.exports = {
  6. entry: entry,
  7. output: {
  8. filename: 'js/[name]_[hash:5].js',
  9. chunkFilename: 'js/[name]_[contenthash:5].js'
  10. },
  11. resolve: {
  12. alias: {
  13. '@': path.resolve(__dirname, 'src')
  14. }
  15. },
  16. optimization: {
  17. splitChunks: {
  18. chunks: 'all',
  19. cacheGroups: {
  20. commons: {
  21. test: /[\\/]node_modules[\\/]/,
  22. priority: -10,
  23. name: 'commons'
  24. }
  25. }
  26. }
  27. },
  28. module: {
  29. rules: [
  30. {
  31. test: /\.js$/,
  32. exclude: /node_modules/,
  33. use: [
  34. 'babel-loader',
  35. {
  36. loader: 'eslint-loader',
  37. options: {
  38. fix: true
  39. }
  40. }
  41. ]
  42. },
  43. {
  44. test: /\.html$/,
  45. use: {
  46. loader: 'html-loader',
  47. options: {
  48. attrs: [':src']
  49. }
  50. }
  51. },
  52. {
  53. test: /\.(svg|jpe?g|gif|png|bmp)$/,
  54. use: {
  55. loader: 'url-loader',
  56. options: {
  57. name: '[name]_[hash:5].[ext]',
  58. outputPath: 'images',
  59. limit: 10240
  60. }
  61. }
  62. },
  63. {
  64. test: /\.(eot|ttf|woff2?|otf)$/,
  65. use: {
  66. loader: 'file-loader',
  67. options: {
  68. name: '[name]_[hash:5].[ext]',
  69. outputPath: 'fonts'
  70. }
  71. }
  72. }
  73. ]
  74. },
  75. plugins: [
  76. ...HTMLWebpackPlugins,
  77. new webpack.ProvidePlugin({
  78. $: 'jquery',
  79. jQuery: 'jquery'
  80. }),
  81. new CleanWebpackPlugin()
  82. ]
  83. }