webpack.config.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. const path = require("path");
  2. const MiniCSSExtractPlugin = require("mini-css-extract-plugin");
  3. const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
  4. const RemoveEmptyScriptsPlugin = require("webpack-remove-empty-scripts");
  5. const { CleanWebpackPlugin: CleanPlugin } = require("clean-webpack-plugin");
  6. module.exports = (env, argv) => ({
  7. mode: "development",
  8. entry: {
  9. pluginSetupWizard: [
  10. path.join(__dirname, "src/main/js/pluginSetupWizard.js"),
  11. path.join(__dirname, "src/main/scss/pluginSetupWizard.scss"),
  12. ],
  13. "plugin-manager-ui": [
  14. path.join(__dirname, "src/main/js/plugin-manager-ui.js"),
  15. ],
  16. "add-item": [
  17. path.join(__dirname, "src/main/js/add-item.js"),
  18. path.join(__dirname, "src/main/js/add-item.scss"),
  19. ],
  20. "pages/computer-set": [
  21. path.join(__dirname, "src/main/js/pages/computer-set"),
  22. ],
  23. "pages/dashboard": [path.join(__dirname, "src/main/js/pages/dashboard")],
  24. "pages/manage-jenkins/system-information": [
  25. path.join(
  26. __dirname,
  27. "src/main/js/pages/manage-jenkins/system-information",
  28. ),
  29. ],
  30. app: [path.join(__dirname, "src/main/js/app.js")],
  31. header: [path.join(__dirname, "src/main/js/components/header/index.js")],
  32. "pages/cloud-set": [
  33. path.join(__dirname, "src/main/js/pages/cloud-set/index.js"),
  34. path.join(__dirname, "src/main/js/pages/cloud-set/index.scss"),
  35. ],
  36. "pages/manage-jenkins": [
  37. path.join(__dirname, "src/main/js/pages/manage-jenkins"),
  38. ],
  39. "pages/register": [path.join(__dirname, "src/main/js/pages/register")],
  40. "keyboard-shortcuts": [
  41. path.join(__dirname, "src/main/js/keyboard-shortcuts.js"),
  42. ],
  43. "sortable-drag-drop": [
  44. path.join(__dirname, "src/main/js/sortable-drag-drop.js"),
  45. ],
  46. "section-to-sidebar-items": [
  47. path.join(__dirname, "src/main/js/section-to-sidebar-items.js"),
  48. ],
  49. "section-to-tabs": [path.join(__dirname, "src/main/js/section-to-tabs.js")],
  50. "components/row-selection-controller": [
  51. path.join(__dirname, "src/main/js/components/row-selection-controller"),
  52. ],
  53. "pages/project/builds-card": [
  54. path.join(__dirname, "src/main/js/pages/project/builds-card.js"),
  55. ],
  56. "pages/project/builds-card-new": [
  57. path.join(__dirname, "src/main/js/pages/project/builds-card-new.js"),
  58. ],
  59. "pages/project/build": [
  60. path.join(__dirname, "src/main/js/pages/project/build.js"),
  61. ],
  62. "simple-page": [path.join(__dirname, "src/main/scss/simple-page.scss")],
  63. styles: [path.join(__dirname, "src/main/scss/styles.scss")],
  64. },
  65. output: {
  66. path: path.join(__dirname, "war/src/main/webapp/jsbundles"),
  67. },
  68. devtool:
  69. argv.mode === "production"
  70. ? "source-map"
  71. : "inline-cheap-module-source-map",
  72. plugins: [
  73. new RemoveEmptyScriptsPlugin({}),
  74. new MiniCSSExtractPlugin({
  75. filename: "[name].css",
  76. }),
  77. // Clean all assets within the specified output.
  78. // It will not clean copied fonts
  79. new CleanPlugin(),
  80. ],
  81. module: {
  82. rules: [
  83. {
  84. test: /\.(css|scss)$/,
  85. use: [
  86. "style-loader",
  87. {
  88. loader: MiniCSSExtractPlugin.loader,
  89. options: {
  90. esModule: false,
  91. },
  92. },
  93. {
  94. loader: "css-loader",
  95. options: {
  96. sourceMap: true,
  97. // ignore the URLS on the base styles and mask images as they are picked
  98. // from the war/src/main/webapp/images dir
  99. url: {
  100. filter: (url, resourcePath) => {
  101. return (
  102. !resourcePath.includes("styles.scss") &&
  103. !url.includes("../images/svgs/")
  104. );
  105. },
  106. },
  107. },
  108. },
  109. {
  110. loader: "postcss-loader",
  111. options: {
  112. sourceMap: true,
  113. },
  114. },
  115. {
  116. loader: "sass-loader",
  117. options: {
  118. sourceMap: true,
  119. },
  120. },
  121. ],
  122. },
  123. {
  124. test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
  125. type: "asset/resource",
  126. generator: {
  127. filename: "fonts/[name].[ext]",
  128. },
  129. },
  130. {
  131. test: /\.hbs$/,
  132. loader: "handlebars-loader",
  133. options: {
  134. // The preferred option for adding handlebars helpers is putting them
  135. // inside this helpers directory
  136. helperDirs: path.join(__dirname, "src/main/js/handlebars-helpers"),
  137. precompileOptions: {
  138. knownHelpersOnly: false,
  139. // Helpers registered with Handlebars.registerHelper must be listed so that
  140. // handlebars-loader will expect them when compiling the templates.
  141. // This helpers cannot be moved to the helpers directory because they are closures
  142. knownHelpers: [
  143. "pluginCountForCategory",
  144. "totalPluginCount",
  145. "inSelectedPlugins",
  146. "dependencyCount",
  147. "eachDependency",
  148. "ifVisibleDependency",
  149. ],
  150. },
  151. },
  152. },
  153. {
  154. test: /\.js$/,
  155. exclude: /node_modules/,
  156. loader: "babel-loader",
  157. },
  158. ],
  159. },
  160. optimization: {
  161. splitChunks: {
  162. chunks: "async",
  163. cacheGroups: {
  164. commons: {
  165. test: /[\\/]node_modules[\\/]/,
  166. name: "vendors",
  167. chunks: "all",
  168. },
  169. },
  170. },
  171. minimizer: [
  172. new CssMinimizerPlugin({
  173. minimizerOptions: {
  174. preset: [
  175. "default",
  176. {
  177. svgo: { exclude: true },
  178. },
  179. ],
  180. },
  181. }),
  182. ],
  183. },
  184. resolve: {
  185. alias: {
  186. "@": path.resolve(__dirname, "src/main/js"),
  187. // Needed to be able to register helpers at runtime
  188. handlebars: "handlebars/runtime",
  189. },
  190. },
  191. });