Guest User

Untitled

a guest
Nov 19th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.95 KB | None | 0 0
  1. const path = require('path');
  2. const glob = require('glob');
  3. const webpack = require('webpack');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
  7. const TerserPlugin = require('terser-webpack-plugin');
  8. const CopyWebpackPlugin = require('copy-webpack-plugin');
  9. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  10.  
  11. module.exports = (env, argv) => {
  12. const isDevMode = argv.mode === 'development';
  13.  
  14. return {
  15. entry: {
  16. vendor: './webpack.vendor.js',
  17. app: './webpack.app.js'
  18. },
  19. output: {
  20. path: path.resolve(__dirname, 'dist'),
  21. filename: 'assets/js/[name].min.js'
  22. },
  23. module: {
  24. rules: [
  25. {
  26. test: /\.hbs$/,
  27. loader: 'handlebars-loader',
  28. },
  29. {
  30. test: /\.css$/,
  31. use: [
  32. MiniCssExtractPlugin.loader,
  33. 'css-loader',
  34. {
  35. loader: 'postcss-loader',
  36. options: {
  37. postcssOptions: {
  38. plugins: [
  39. require('autoprefixer')()
  40. ]
  41. }
  42. }
  43. }
  44. ]
  45. },
  46. {
  47. test: /\.scss$/,
  48. use: [
  49. MiniCssExtractPlugin.loader,
  50. 'css-loader',
  51. {
  52. loader: 'postcss-loader',
  53. options: {
  54. postcssOptions: {
  55. plugins: [
  56. require('autoprefixer')()
  57. ]
  58. }
  59. }
  60. },
  61. {
  62. loader: 'sass-loader',
  63. options: {
  64. sassOptions: {
  65. silenceDeprecations: ['mixed-decls', 'color-functions', 'global-builtin', 'import', 'legacy-js-api']
  66. }
  67. }
  68. }
  69. ]
  70. },
  71. {
  72. test: /\.(png|svg|jpg|jpeg|gif)$/,
  73. type: 'asset/resource',
  74. generator: {
  75. filename: 'assets/img/[name][ext][query]'
  76. }
  77. },
  78. {
  79. test: /\.(woff|woff2|eot|ttf|otf)$/,
  80. type: 'asset/resource',
  81. generator: {
  82. filename: 'assets/fonts/[name][ext][query]'
  83. }
  84. }
  85. ]
  86. },
  87. plugins: [
  88. new CleanWebpackPlugin(),
  89. new MiniCssExtractPlugin({
  90. filename: 'assets/css/[name].min.css'
  91. }),
  92. new webpack.HotModuleReplacementPlugin(),
  93. ...glob.sync('./src/html/*.hbs').map((templateFile) => {
  94. const filename = path.basename(templateFile, '.hbs') + '.html';
  95. return new HtmlWebpackPlugin({
  96. template: templateFile,
  97. filename: filename,
  98. minify: false,
  99. excludeChunks: ['app', 'vendor']
  100. });
  101. }),
  102. new CopyWebpackPlugin({
  103. patterns: [
  104. { from: 'src/img', to: 'assets/img' },
  105. { from: 'src/data', to: 'assets/data' },
  106. { from: 'src/js/demo', to: 'assets/js/demo' },
  107. { from: 'node_modules/bootstrap-icons/font/fonts/', to: 'assets/css/fonts/' },
  108. { from: 'node_modules/@fortawesome/fontawesome-free/webfonts', to: 'assets/webfonts' },
  109. { from: 'node_modules/@fortawesome/', to: 'assets/plugins/@fortawesome/' },
  110. { from: 'node_modules/@fullcalendar/', to: 'assets/plugins/@fullcalendar/' },
  111. { from: 'node_modules/@highlightjs/cdn-assets/', to: 'assets/plugins/@highlightjs/cdn-assets/' },
  112. { from: 'node_modules/apexcharts/', to: 'assets/plugins/apexcharts/' },
  113. { from: 'node_modules/blueimp-canvas-to-blob/', to: 'assets/plugins/blueimp-canvas-to-blob/' },
  114. { from: 'node_modules/blueimp-file-upload/', to: 'assets/plugins/blueimp-file-upload/' },
  115. { from: 'node_modules/blueimp-gallery/', to: 'assets/plugins/blueimp-gallery/' },
  116. { from: 'node_modules/blueimp-load-image/', to: 'assets/plugins/blueimp-load-image/' },
  117. { from: 'node_modules/blueimp-tmpl/', to: 'assets/plugins/blueimp-tmpl/' },
  118. { from: 'node_modules/bootstrap/', to: 'assets/plugins/bootstrap/' },
  119. { from: 'node_modules/bootstrap-datepicker/', to: 'assets/plugins/bootstrap-datepicker/' },
  120. { from: 'node_modules/bootstrap-daterangepicker/', to: 'assets/plugins/bootstrap-daterangepicker/' },
  121. { from: 'node_modules/bootstrap-icons/', to: 'assets/plugins/bootstrap-icons/' },
  122. { from: 'node_modules/bootstrap-slider/', to: 'assets/plugins/bootstrap-slider/' },
  123. { from: 'node_modules/bootstrap-table/', to: 'assets/plugins/bootstrap-table/' },
  124. { from: 'node_modules/bootstrap-timepicker/', to: 'assets/plugins/bootstrap-timepicker/' },
  125. { from: 'node_modules/chart.js/', to: 'assets/plugins/chart.js/' },
  126. { from: 'node_modules/datatables.net/', to: 'assets/plugins/datatables.net/' },
  127. { from: 'node_modules/datatables.net-bs5/', to: 'assets/plugins/datatables.net-bs5/' },
  128. { from: 'node_modules/datatables.net-autofill/', to: 'assets/plugins/datatables.net-autofill/' },
  129. { from: 'node_modules/datatables.net-autofill-bs5/', to: 'assets/plugins/datatables.net-autofill-bs5/' },
  130. { from: 'node_modules/datatables.net-buttons/', to: 'assets/plugins/datatables.net-buttons/' },
  131. { from: 'node_modules/datatables.net-buttons-bs5/', to: 'assets/plugins/datatables.net-buttons-bs5/' },
  132. { from: 'node_modules/datatables.net-colreorder/', to: 'assets/plugins/datatables.net-colreorder/' },
  133. { from: 'node_modules/datatables.net-colreorder-bs5/', to: 'assets/plugins/datatables.net-colreorder-bs5/' },
  134. { from: 'node_modules/datatables.net-fixedcolumns/', to: 'assets/plugins/datatables.net-fixedcolumns/' },
  135. { from: 'node_modules/datatables.net-fixedcolumns-bs5/', to: 'assets/plugins/datatables.net-fixedcolumns-bs5/' },
  136. { from: 'node_modules/datatables.net-fixedheader/', to: 'assets/plugins/datatables.net-fixedheader/' },
  137. { from: 'node_modules/datatables.net-fixedheader-bs5/', to: 'assets/plugins/datatables.net-fixedheader-bs5/' },
  138. { from: 'node_modules/datatables.net-keytable/', to: 'assets/plugins/datatables.net-keytable/' },
  139. { from: 'node_modules/datatables.net-keytable-bs5/', to: 'assets/plugins/datatables.net-keytable-bs5/' },
  140. { from: 'node_modules/datatables.net-responsive/', to: 'assets/plugins/datatables.net-responsive/' },
  141. { from: 'node_modules/datatables.net-responsive-bs5/', to: 'assets/plugins/datatables.net-responsive-bs5/' },
  142. { from: 'node_modules/datatables.net-rowgroup/', to: 'assets/plugins/datatables.net-rowgroup/' },
  143. { from: 'node_modules/datatables.net-rowgroup-bs5/', to: 'assets/plugins/datatables.net-rowgroup-bs5/' },
  144. { from: 'node_modules/datatables.net-rowreorder-bs5/', to: 'assets/plugins/datatables.net-rowreorder-bs5/' },
  145. { from: 'node_modules/datatables.net-scroller/', to: 'assets/plugins/datatables.net-scroller/' },
  146. { from: 'node_modules/datatables.net-scroller-bs5/', to: 'assets/plugins/datatables.net-scroller-bs5/' },
  147. { from: 'node_modules/datatables.net-select/', to: 'assets/plugins/datatables.net-select/' },
  148. { from: 'node_modules/datatables.net-select-bs5/', to: 'assets/plugins/datatables.net-select-bs5/' },
  149. { from: 'node_modules/jquery/', to: 'assets/plugins/jquery/' },
  150. { from: 'node_modules/jquery-migrate/', to: 'assets/plugins/jquery-migrate/' },
  151. { from: 'node_modules/jquery-typeahead/', to: 'assets/plugins/jquery-typeahead/' },
  152. { from: 'node_modules/jquery-ui-dist/', to: 'assets/plugins/jquery-ui-dist/' },
  153. { from: 'node_modules/jquery.maskedinput/', to: 'assets/plugins/jquery.maskedinput/' },
  154. { from: 'node_modules/js-cookie/', to: 'assets/plugins/js-cookie/' },
  155. { from: 'node_modules/jszip/', to: 'assets/plugins/jszip/' },
  156. { from: 'node_modules/jvectormap-content/', to: 'assets/plugins/jvectormap-content/' },
  157. { from: 'node_modules/jvectormap-next/', to: 'assets/plugins/jvectormap-next/' },
  158. { from: 'node_modules/lity/', to: 'assets/plugins/lity/' },
  159. { from: 'node_modules/kbw-countdown/', to: 'assets/plugins/kbw-countdown/' },
  160. { from: 'node_modules/masonry-layout/', to: 'assets/plugins/masonry-layout/' },
  161. { from: 'node_modules/moment/', to: 'assets/plugins/moment/' },
  162. { from: 'node_modules/perfect-scrollbar/', to: 'assets/plugins/perfect-scrollbar/' },
  163. { from: 'node_modules/photoswipe/', to: 'assets/plugins/photoswipe/' },
  164. { from: 'node_modules/select-picker/', to: 'assets/plugins/select-picker/' },
  165. { from: 'node_modules/spectrum-colorpicker2/', to: 'assets/plugins/spectrum-colorpicker2/' },
  166. { from: 'node_modules/summernote/', to: 'assets/plugins/summernote/' },
  167. { from: 'node_modules/tag-it/', to: 'assets/plugins/tag-it' }
  168. ]
  169. })
  170. ],
  171. optimization: {
  172. minimizer: [
  173. new TerserPlugin({
  174. exclude: /assets\/plugins\/jquery-migrate\/test\/runner\/command\.js/,
  175. }),
  176. new CssMinimizerPlugin()
  177. ],
  178. splitChunks: {
  179. cacheGroups: {
  180. vendorStyles: {
  181. type: 'css/mini-extract',
  182. test: /\.css$/,
  183. name: 'vendor',
  184. chunks: 'all',
  185. enforce: true,
  186. }
  187. }
  188. },
  189. },
  190. devServer: {
  191. static: {
  192. directory: path.join(__dirname, 'dist'),
  193. },
  194. devMiddleware: {
  195. writeToDisk: true,
  196. },
  197. liveReload: true,
  198. compress: false,
  199. port: 8000,
  200. hot: true
  201. },
  202. performance: {
  203. maxEntrypointSize: 1024000,
  204. maxAssetSize: 1024000,
  205. }
  206. }
  207. };
Advertisement
Add Comment
Please, Sign In to add comment