webpack.config.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. const webpack = require("webpack");
  2. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  3. const path = require("path");
  4. /**
  5. * Webpack configuration details for use with Grunt.
  6. *
  7. * @author n1474335 [n1474335@gmail.com]
  8. * @copyright Crown Copyright 2017
  9. * @license Apache-2.0
  10. */
  11. const banner = `/**
  12. * CyberChef - The Cyber Swiss Army Knife
  13. *
  14. * @copyright Crown Copyright 2016
  15. * @license Apache-2.0
  16. *
  17. * Copyright 2016 Crown Copyright
  18. *
  19. * Licensed under the Apache License, Version 2.0 (the "License");
  20. * you may not use this file except in compliance with the License.
  21. * You may obtain a copy of the License at
  22. *
  23. * http://www.apache.org/licenses/LICENSE-2.0
  24. *
  25. * Unless required by applicable law or agreed to in writing, software
  26. * distributed under the License is distributed on an "AS IS" BASIS,
  27. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  28. * See the License for the specific language governing permissions and
  29. * limitations under the License.
  30. */`;
  31. module.exports = {
  32. plugins: [
  33. new webpack.ProvidePlugin({
  34. $: "jquery",
  35. jQuery: "jquery",
  36. log: "loglevel"
  37. }),
  38. new webpack.BannerPlugin({
  39. banner: banner,
  40. raw: true,
  41. entryOnly: true
  42. }),
  43. new webpack.DefinePlugin({
  44. "process.browser": "true"
  45. }),
  46. new MiniCssExtractPlugin({
  47. filename: "assets/[name].css"
  48. }),
  49. ],
  50. resolve: {
  51. alias: {
  52. jquery: "jquery/src/jquery",
  53. },
  54. },
  55. module: {
  56. rules: [
  57. {
  58. test: /\.m?js$/,
  59. exclude: /node_modules\/(?!jsesc|crypto-api|bootstrap)/,
  60. options: {
  61. configFile: path.resolve(__dirname, "babel.config.js"),
  62. cacheDirectory: true,
  63. compact: false
  64. },
  65. type: "javascript/auto",
  66. loader: "babel-loader"
  67. },
  68. {
  69. test: /forge.min.js$/,
  70. loader: "imports-loader?jQuery=>null"
  71. },
  72. {
  73. test: /bootstrap-material-design/,
  74. loader: "imports-loader?Popper=popper.js/dist/umd/popper.js"
  75. },
  76. {
  77. test: /\.css$/,
  78. use: [
  79. {
  80. loader: MiniCssExtractPlugin.loader,
  81. options: {
  82. publicPath: "../"
  83. }
  84. },
  85. "css-loader",
  86. "postcss-loader",
  87. ]
  88. },
  89. {
  90. test: /\.scss$/,
  91. use: [
  92. {
  93. loader: MiniCssExtractPlugin.loader,
  94. options: {
  95. publicPath: "../"
  96. }
  97. },
  98. "css-loader",
  99. "sass-loader",
  100. ]
  101. },
  102. /**
  103. * The limit for these files has been increased to 60,000 (60KB)
  104. * to ensure the material icons font is inlined.
  105. *
  106. * See: https://github.com/gchq/CyberChef/issues/612
  107. */
  108. {
  109. test: /\.(ico|eot|ttf|woff|woff2)$/,
  110. loader: "url-loader",
  111. options: {
  112. limit: 60000,
  113. name: "[hash].[ext]",
  114. outputPath: "assets"
  115. }
  116. },
  117. {
  118. test: /\.svg$/,
  119. loader: "svg-url-loader",
  120. options: {
  121. encoding: "base64"
  122. }
  123. },
  124. { // Store font .fnt and .png files in a separate fonts folder
  125. test: /(\.fnt$|bmfonts\/.+\.png$)/,
  126. loader: "file-loader",
  127. options: {
  128. name: "[name].[ext]",
  129. outputPath: "assets/fonts"
  130. }
  131. },
  132. { // First party images are saved as files to be cached
  133. test: /\.(png|jpg|gif)$/,
  134. exclude: /(node_modules|bmfonts)/,
  135. loader: "file-loader",
  136. options: {
  137. name: "images/[name].[ext]"
  138. }
  139. },
  140. { // Third party images are inlined
  141. test: /\.(png|jpg|gif)$/,
  142. exclude: /web\/static/,
  143. loader: "url-loader",
  144. options: {
  145. limit: 10000,
  146. name: "[hash].[ext]",
  147. outputPath: "assets"
  148. }
  149. },
  150. ]
  151. },
  152. stats: {
  153. children: false,
  154. chunks: false,
  155. modules: false,
  156. entrypoints: false,
  157. warningsFilter: [
  158. /source-map/,
  159. /dependency is an expression/,
  160. /export 'default'/,
  161. /Can't resolve 'sodium'/
  162. ],
  163. },
  164. node: {
  165. fs: "empty",
  166. "child_process": "empty",
  167. net: "empty",
  168. tls: "empty"
  169. },
  170. performance: {
  171. hints: false
  172. }
  173. };