webpack.config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. test: /\.(ico|eot|ttf|woff|woff2)$/,
  104. loader: "url-loader",
  105. options: {
  106. limit: 10000,
  107. name: "[hash].[ext]",
  108. outputPath: "assets"
  109. }
  110. },
  111. {
  112. test: /\.svg$/,
  113. loader: "svg-url-loader",
  114. options: {
  115. encoding: "base64"
  116. }
  117. },
  118. { // Store font .fnt and .png files in a separate fonts folder
  119. test: /(\.fnt$|bmfonts\/.+\.png$)/,
  120. loader: "file-loader",
  121. options: {
  122. name: "[name].[ext]",
  123. outputPath: "assets/fonts"
  124. }
  125. },
  126. { // First party images are saved as files to be cached
  127. test: /\.(png|jpg|gif)$/,
  128. exclude: /(node_modules|bmfonts)/,
  129. loader: "file-loader",
  130. options: {
  131. name: "images/[name].[ext]"
  132. }
  133. },
  134. { // Third party images are inlined
  135. test: /\.(png|jpg|gif)$/,
  136. exclude: /web\/static/,
  137. loader: "url-loader",
  138. options: {
  139. limit: 10000,
  140. name: "[hash].[ext]",
  141. outputPath: "assets"
  142. }
  143. },
  144. ]
  145. },
  146. stats: {
  147. children: false,
  148. chunks: false,
  149. modules: false,
  150. entrypoints: false,
  151. warningsFilter: [
  152. /source-map/,
  153. /dependency is an expression/,
  154. /export 'default'/,
  155. /Can't resolve 'sodium'/
  156. ],
  157. },
  158. node: {
  159. fs: "empty",
  160. "child_process": "empty",
  161. net: "empty",
  162. tls: "empty"
  163. },
  164. performance: {
  165. hints: false
  166. }
  167. };