webpack.config.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. const webpack = require("webpack");
  2. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  3. const CopyWebpackPlugin = require("copy-webpack-plugin");
  4. const path = require("path");
  5. /**
  6. * Webpack configuration details for use with Grunt.
  7. *
  8. * @author n1474335 [n1474335@gmail.com]
  9. * @copyright Crown Copyright 2017
  10. * @license Apache-2.0
  11. */
  12. const banner = `/**
  13. * CyberChef - The Cyber Swiss Army Knife
  14. *
  15. * @copyright Crown Copyright 2016
  16. * @license Apache-2.0
  17. *
  18. * Copyright 2016 Crown Copyright
  19. *
  20. * Licensed under the Apache License, Version 2.0 (the "License");
  21. * you may not use this file except in compliance with the License.
  22. * You may obtain a copy of the License at
  23. *
  24. * http://www.apache.org/licenses/LICENSE-2.0
  25. *
  26. * Unless required by applicable law or agreed to in writing, software
  27. * distributed under the License is distributed on an "AS IS" BASIS,
  28. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  29. * See the License for the specific language governing permissions and
  30. * limitations under the License.
  31. */`;
  32. module.exports = {
  33. output: {
  34. publicPath: "",
  35. globalObject: "this",
  36. assetModuleFilename: "assets/[hash][ext][query]"
  37. },
  38. plugins: [
  39. new webpack.ProvidePlugin({
  40. $: "jquery",
  41. jQuery: "jquery",
  42. log: "loglevel",
  43. // process and Buffer are no longer polyfilled in webpack 5 but
  44. // many of our dependencies expect them, so it is easiest to just
  45. // provide them everywhere as was the case in webpack 4-
  46. process: "process",
  47. Buffer: ["buffer", "Buffer"]
  48. }),
  49. new webpack.BannerPlugin({
  50. banner: banner,
  51. raw: true,
  52. entryOnly: true
  53. }),
  54. new webpack.DefinePlugin({
  55. // Required by Jimp to improve loading speed in browsers
  56. "process.browser": "true"
  57. }),
  58. new MiniCssExtractPlugin({
  59. filename: "assets/[name].css"
  60. }),
  61. new CopyWebpackPlugin({
  62. patterns: [
  63. {
  64. context: "src/core/vendor/",
  65. from: "tesseract/**/*",
  66. to: "assets/"
  67. }, {
  68. context: "node_modules/tesseract.js/",
  69. from: "dist/worker.min.js",
  70. to: "assets/tesseract"
  71. }, {
  72. context: "node_modules/tesseract.js-core/",
  73. from: "tesseract-core.wasm.js",
  74. to: "assets/tesseract"
  75. }, {
  76. context: "node_modules/node-forge/dist",
  77. from: "prime.worker.min.js",
  78. to: "assets/forge/"
  79. }
  80. ]
  81. })
  82. ],
  83. resolve: {
  84. extensions: [".mjs", ".js", ".json"], // Allows importing files without extensions
  85. alias: {
  86. jquery: "jquery/src/jquery",
  87. },
  88. fallback: {
  89. "fs": false,
  90. "child_process": false,
  91. "net": false,
  92. "tls": false,
  93. "path": require.resolve("path/"),
  94. "buffer": require.resolve("buffer/"),
  95. "crypto": require.resolve("crypto-browserify"),
  96. "stream": require.resolve("stream-browserify"),
  97. "zlib": require.resolve("browserify-zlib")
  98. }
  99. },
  100. module: {
  101. rules: [
  102. {
  103. test: /\.m?js$/,
  104. exclude: /node_modules\/(?!crypto-api|bootstrap)/,
  105. options: {
  106. configFile: path.resolve(__dirname, "babel.config.js"),
  107. cacheDirectory: true,
  108. compact: false
  109. },
  110. type: "javascript/auto",
  111. loader: "babel-loader"
  112. },
  113. {
  114. test: /node-forge/,
  115. loader: "imports-loader",
  116. options: {
  117. additionalCode: "var jQuery = false;"
  118. }
  119. },
  120. {
  121. test: /prime.worker.min.js$/,
  122. type: "asset/source"
  123. },
  124. {
  125. test: /bootstrap-material-design/,
  126. loader: "imports-loader",
  127. options: {
  128. imports: "default popper.js/dist/umd/popper.js Popper"
  129. }
  130. },
  131. {
  132. test: /blueimp-load-image/,
  133. loader: "imports-loader",
  134. options: {
  135. type: "commonjs",
  136. imports: "single min-document document"
  137. }
  138. },
  139. {
  140. test: /\.css$/,
  141. use: [
  142. {
  143. loader: MiniCssExtractPlugin.loader,
  144. options: {
  145. publicPath: "../"
  146. }
  147. },
  148. "css-loader",
  149. "postcss-loader",
  150. ]
  151. },
  152. {
  153. test: /\.scss$/,
  154. use: [
  155. {
  156. loader: MiniCssExtractPlugin.loader,
  157. options: {
  158. publicPath: "../"
  159. }
  160. },
  161. "css-loader",
  162. "sass-loader",
  163. ]
  164. },
  165. {
  166. test: /\.(ico|eot|ttf|woff|woff2)$/,
  167. type: "asset/resource",
  168. },
  169. {
  170. test: /\.svg$/,
  171. type: "asset/inline",
  172. },
  173. { // Store font .fnt and .png files in a separate fonts folder
  174. test: /(\.fnt$|bmfonts\/.+\.png$)/,
  175. type: "asset/resource",
  176. generator: {
  177. filename: "assets/fonts/[name][ext]"
  178. }
  179. },
  180. { // First party images are saved as files to be cached
  181. test: /\.(png|jpg|gif)$/,
  182. exclude: /(node_modules|bmfonts)/,
  183. type: "asset/resource",
  184. generator: {
  185. filename: "images/[name][ext]"
  186. }
  187. },
  188. { // Third party images are inlined
  189. test: /\.(png|jpg|gif)$/,
  190. exclude: /web\/static/,
  191. type: "asset/inline",
  192. },
  193. ]
  194. },
  195. stats: {
  196. children: false,
  197. chunks: false,
  198. modules: false,
  199. entrypoints: false
  200. },
  201. ignoreWarnings: [
  202. /source-map/,
  203. /source map/,
  204. /dependency is an expression/,
  205. /export 'default'/,
  206. /Can't resolve 'sodium'/
  207. ],
  208. performance: {
  209. hints: false
  210. }
  211. };