webpack.config.js 5.9 KB

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