webpack.config.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. plugins: [
  34. new webpack.ProvidePlugin({
  35. $: "jquery",
  36. jQuery: "jquery",
  37. log: "loglevel",
  38. // process and Buffer are no longer polyfilled in webpack 5 but
  39. // many of our dependencies expect them, so it is easiest to just
  40. // provide them everywhere as was the case in webpack 4-
  41. process: "process",
  42. Buffer: ["buffer", "Buffer"]
  43. }),
  44. new webpack.BannerPlugin({
  45. banner: banner,
  46. raw: true,
  47. entryOnly: true
  48. }),
  49. new webpack.DefinePlugin({
  50. // Required by Jimp to improve loading speed in browsers
  51. "process.browser": "true"
  52. }),
  53. new MiniCssExtractPlugin({
  54. filename: "assets/[name].css"
  55. }),
  56. new CopyWebpackPlugin({
  57. patterns: [
  58. {
  59. context: "src/core/vendor/",
  60. from: "tesseract/**/*",
  61. to: "assets/"
  62. }, {
  63. context: "node_modules/tesseract.js/",
  64. from: "dist/worker.min.js",
  65. to: "assets/tesseract"
  66. }, {
  67. context: "node_modules/tesseract.js-core/",
  68. from: "tesseract-core.wasm.js",
  69. to: "assets/tesseract"
  70. }
  71. ]
  72. })
  73. ],
  74. resolve: {
  75. extensions: [".mjs", ".js", ".json"], // Allows importing files without extensions
  76. alias: {
  77. jquery: "jquery/src/jquery",
  78. },
  79. fallback: {
  80. "fs": false,
  81. "child_process": false,
  82. "net": false,
  83. "tls": false,
  84. "path": require.resolve("path/"),
  85. "buffer": require.resolve("buffer/"),
  86. "crypto": require.resolve("crypto-browserify"),
  87. "stream": require.resolve("stream-browserify"),
  88. "zlib": require.resolve("browserify-zlib")
  89. }
  90. },
  91. module: {
  92. rules: [
  93. {
  94. test: /\.m?js$/,
  95. exclude: /node_modules\/(?!crypto-api|bootstrap)/,
  96. options: {
  97. configFile: path.resolve(__dirname, "babel.config.js"),
  98. cacheDirectory: true,
  99. compact: false
  100. },
  101. type: "javascript/auto",
  102. loader: "babel-loader"
  103. },
  104. {
  105. test: /node-forge/,
  106. loader: "imports-loader",
  107. options: {
  108. additionalCode: "var jQuery = false;"
  109. }
  110. },
  111. {
  112. test: /bootstrap-material-design/,
  113. loader: "imports-loader",
  114. options: {
  115. imports: "default popper.js/dist/umd/popper.js Popper"
  116. }
  117. },
  118. {
  119. test: /blueimp-load-image/,
  120. loader: "imports-loader",
  121. options: {
  122. type: "commonjs",
  123. imports: "nodom",
  124. additionalCode: "var document = new nodom.Document();"
  125. }
  126. },
  127. {
  128. test: /\.css$/,
  129. use: [
  130. {
  131. loader: MiniCssExtractPlugin.loader,
  132. options: {
  133. publicPath: "../"
  134. }
  135. },
  136. "css-loader",
  137. "postcss-loader",
  138. ]
  139. },
  140. {
  141. test: /\.scss$/,
  142. use: [
  143. {
  144. loader: MiniCssExtractPlugin.loader,
  145. options: {
  146. publicPath: "../"
  147. }
  148. },
  149. "css-loader",
  150. "sass-loader",
  151. ]
  152. },
  153. /**
  154. * The limit for these files has been increased to 60,000 (60KB)
  155. * to ensure the material icons font is inlined.
  156. *
  157. * See: https://github.com/gchq/CyberChef/issues/612
  158. */
  159. {
  160. test: /\.(ico|eot|ttf|woff|woff2)$/,
  161. loader: "url-loader",
  162. options: {
  163. limit: 60000,
  164. name: "[hash].[ext]",
  165. outputPath: "assets"
  166. }
  167. },
  168. {
  169. test: /\.svg$/,
  170. loader: "svg-url-loader",
  171. options: {
  172. encoding: "base64"
  173. }
  174. },
  175. { // Store font .fnt and .png files in a separate fonts folder
  176. test: /(\.fnt$|bmfonts\/.+\.png$)/,
  177. loader: "file-loader",
  178. options: {
  179. name: "[name].[ext]",
  180. outputPath: "assets/fonts"
  181. }
  182. },
  183. { // First party images are saved as files to be cached
  184. test: /\.(png|jpg|gif)$/,
  185. exclude: /(node_modules|bmfonts)/,
  186. loader: "file-loader",
  187. options: {
  188. name: "images/[name].[ext]"
  189. }
  190. },
  191. { // Third party images are inlined
  192. test: /\.(png|jpg|gif)$/,
  193. exclude: /web\/static/,
  194. loader: "url-loader",
  195. options: {
  196. limit: 10000,
  197. name: "[hash].[ext]",
  198. outputPath: "assets"
  199. }
  200. },
  201. ]
  202. },
  203. stats: {
  204. children: false,
  205. chunks: false,
  206. modules: false,
  207. entrypoints: false,
  208. warningsFilter: [
  209. /source-map/,
  210. /dependency is an expression/,
  211. /export 'default'/,
  212. /Can't resolve 'sodium'/
  213. ],
  214. },
  215. performance: {
  216. hints: false
  217. }
  218. };