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