webpack.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. "use strict";
  2. const path = require('path');
  3. const glob = require('glob');
  4. const { ProvidePlugin } = require("webpack");
  5. const CopyPlugin = require("copy-webpack-plugin");
  6. const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
  7. const ESLintPlugin = require("eslint-webpack-plugin");
  8. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  9. const misago = path.resolve(__dirname, "../misago/static/misago/");
  10. const modules = path.resolve(__dirname, "node_modules");
  11. const getEntries = () => {
  12. const entry = ["./src/index.js"];
  13. glob.sync("./src/initializers/**/*.js").forEach((path) => entry.push(path));
  14. return entry;
  15. };
  16. module.exports = (env, argv) => {
  17. const isProduction = argv.mode === "production";
  18. return {
  19. mode: isProduction ? "production" : "development",
  20. devtool: "source-map",
  21. entry: {
  22. misago: getEntries(),
  23. },
  24. output: {
  25. path: path.resolve(misago, "js"),
  26. filename: "[name].js",
  27. },
  28. optimization: {
  29. minimize: isProduction,
  30. minimizer: [
  31. "...",
  32. new CssMinimizerPlugin(),
  33. ],
  34. splitChunks: {
  35. cacheGroups: {
  36. vendor: {
  37. test: /[\\/]node_modules[\\/]/,
  38. name: "vendor",
  39. chunks: "all",
  40. },
  41. hljs: {
  42. test: /[\\/]highlight[\\/]/,
  43. name: "hljs",
  44. chunks: "all",
  45. },
  46. },
  47. },
  48. },
  49. module: {
  50. rules: [
  51. {
  52. test: /\.jsx?$/,
  53. exclude: /node_modules/,
  54. use: {
  55. loader: "babel-loader",
  56. options: {
  57. cacheDirectory: true,
  58. cacheCompression: false,
  59. envName: isProduction ? "production" : "development",
  60. },
  61. },
  62. },
  63. {
  64. test: /\.less$/i,
  65. use: [
  66. "style-loader",
  67. "css-loader",
  68. "less-loader",
  69. ],
  70. use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"],
  71. },
  72. {
  73. test: /\.(woff|ttf|eot|woff2)/,
  74. type: "asset/resource",
  75. generator: {
  76. filename: "../fonts/[name][ext]"
  77. }
  78. },
  79. ],
  80. },
  81. resolve: {
  82. alias: {
  83. misago: path.resolve(__dirname, "src"),
  84. "at-js": path.resolve(modules, "at.js/dist/js/jquery.atwho.js"),
  85. "jquery-caret": path.resolve(modules, "jquery.caret/dist/jquery.caret.js"),
  86. "waypoints": path.resolve(modules, "waypoints/lib/jquery.waypoints.js"),
  87. highlight: path.resolve(__dirname, "highlight/highlight.js"),
  88. },
  89. extensions: [".js", ".jsx"],
  90. },
  91. plugins: [
  92. new ESLintPlugin(
  93. {
  94. extensions: ["js", "jsx"],
  95. files: "./src/"
  96. },
  97. ),
  98. new CopyPlugin(
  99. {
  100. patterns: [
  101. {
  102. from: "./static",
  103. to: misago,
  104. },
  105. {
  106. from: "./node_modules/zxcvbn/dist",
  107. to: path.resolve(misago, "js"),
  108. },
  109. ],
  110. }
  111. ),
  112. new MiniCssExtractPlugin(
  113. {
  114. filename: "../css/misago.css",
  115. }
  116. ),
  117. new ProvidePlugin({
  118. $: "jquery",
  119. "window.$": "jquery",
  120. jQuery: "jquery",
  121. "window.jQuery": "jquery",
  122. moment: "moment",
  123. "window.moment": "moment",
  124. }),
  125. ],
  126. watchOptions: {
  127. ignored: "**/node_modules",
  128. poll: 2000, // Check for changes every two seconds
  129. stdin: true,
  130. },
  131. };
  132. };