webpack.config.js 5.4 KB

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