webpack.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. },
  42. },
  43. },
  44. module: {
  45. rules: [
  46. {
  47. test: /\.jsx?$/,
  48. exclude: /node_modules/,
  49. use: {
  50. loader: "babel-loader",
  51. options: {
  52. cacheDirectory: true,
  53. cacheCompression: false,
  54. envName: isProduction ? "production" : "development",
  55. },
  56. },
  57. },
  58. {
  59. test: /\.less$/i,
  60. use: [
  61. "style-loader",
  62. "css-loader",
  63. "less-loader",
  64. ],
  65. use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"],
  66. },
  67. {
  68. test: /\.(woff|ttf|eot|woff2)/,
  69. type: "asset/resource",
  70. generator: {
  71. filename: "../fonts/[name][ext]"
  72. }
  73. },
  74. ],
  75. },
  76. resolve: {
  77. alias: {
  78. misago: path.resolve(__dirname, "src"),
  79. "at-js": path.resolve(modules, "at.js/dist/js/jquery.atwho.js"),
  80. "jquery-caret": path.resolve(modules, "jquery.caret/dist/jquery.caret.js"),
  81. "waypoints": path.resolve(modules, "waypoints/lib/jquery.waypoints.js"),
  82. highlight: path.resolve(__dirname, "highlight/highlight.pack.js"),
  83. },
  84. extensions: [".js", ".jsx"],
  85. },
  86. plugins: [
  87. new ESLintPlugin(
  88. {
  89. extensions: ["js", "jsx"],
  90. files: "./src/"
  91. },
  92. ),
  93. new CopyPlugin(
  94. {
  95. patterns: [
  96. {
  97. from: "./static",
  98. to: misago,
  99. },
  100. {
  101. from: "./node_modules/zxcvbn/dist",
  102. to: path.resolve(misago, "js"),
  103. },
  104. ],
  105. }
  106. ),
  107. new MiniCssExtractPlugin(
  108. {
  109. filename: "../css/misago.css",
  110. }
  111. ),
  112. new ProvidePlugin({
  113. $: "jquery",
  114. "window.$": "jquery",
  115. jQuery: "jquery",
  116. "window.jQuery": "jquery",
  117. moment: "moment",
  118. "window.moment": "moment",
  119. }),
  120. ],
  121. watchOptions: {
  122. ignored: "**/node_modules",
  123. poll: 2000, // Check for changes every two seconds
  124. stdin: true,
  125. },
  126. };
  127. };