You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webpack.config.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* global __dirname */
  2. const process = require('process');
  3. const webpack = require('webpack');
  4. const aui_css = __dirname + '/node_modules/@atlassian/aui/dist/aui/css/';
  5. /**
  6. * The URL of the Jitsi Meet deployment to be proxy to in the context of
  7. * development with webpack-dev-server.
  8. */
  9. const devServerProxyTarget
  10. = process.env.WEBPACK_DEV_SERVER_PROXY_TARGET || 'https://beta.meet.jit.si';
  11. const minimize
  12. = process.argv.indexOf('-p') !== -1
  13. || process.argv.indexOf('--optimize-minimize') !== -1;
  14. const node_modules = __dirname + '/node_modules/';
  15. const plugins = [
  16. new webpack.LoaderOptionsPlugin({
  17. debug: !minimize,
  18. minimize: minimize
  19. })
  20. ];
  21. const strophe = /\/node_modules\/strophe(js-plugins)?\/.*\.js$/;
  22. if (minimize) {
  23. // XXX Webpack's command line argument -p is not enough. Further
  24. // optimizations are made possible by the use of DefinePlugin and NODE_ENV
  25. // with value 'production'. For example, React takes advantage of these.
  26. plugins.push(new webpack.DefinePlugin({
  27. 'process.env': {
  28. NODE_ENV: JSON.stringify('production')
  29. }
  30. }));
  31. // While webpack will automatically insert UglifyJsPlugin when minimize is
  32. // true, the defaults of UglifyJsPlugin in webpack 1 and webpack 2 are
  33. // different. Explicitly state what we want even if we want defaults in
  34. // order to prepare for webpack 2.
  35. plugins.push(new webpack.optimize.UglifyJsPlugin({
  36. compress: {
  37. // It is nice to see warnings from UglifyJsPlugin that something is
  38. // unused and, consequently, is removed. The default is false in
  39. // webpack 2.
  40. warnings: true
  41. },
  42. extractComments: true,
  43. // Use the source map to map error message locations to modules. The
  44. // default is false in webpack 2.
  45. sourceMap: true
  46. }));
  47. }
  48. // The base Webpack configuration to bundle the JavaScript artifacts of
  49. // jitsi-meet such as app.bundle.js and external_api.js.
  50. const config = {
  51. devServer: {
  52. https: true,
  53. inline: true,
  54. proxy: {
  55. '/': {
  56. bypass: devServerProxyBypass,
  57. secure: false,
  58. target: devServerProxyTarget
  59. }
  60. }
  61. },
  62. devtool: 'source-map',
  63. module: {
  64. rules: [ {
  65. // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
  66. // as well.
  67. exclude: node_modules,
  68. loader: 'babel-loader',
  69. options: {
  70. // XXX The require.resolve bellow solves failures to locate the
  71. // presets when lib-jitsi-meet, for example, is npm linked in
  72. // jitsi-meet. The require.resolve, of course, mandates the use
  73. // of the prefix babel-preset- in the preset names.
  74. presets: [
  75. [
  76. require.resolve('babel-preset-es2015'),
  77. // Tell babel to avoid compiling imports into CommonJS
  78. // so that webpack may do tree shaking.
  79. { modules: false }
  80. ],
  81. require.resolve('babel-preset-react'),
  82. require.resolve('babel-preset-stage-1')
  83. ]
  84. },
  85. test: /\.jsx?$/
  86. }, {
  87. // Expose jquery as the globals $ and jQuery because it is expected
  88. // to be available in such a form by multiple jitsi-meet
  89. // dependencies including AUI, lib-jitsi-meet.
  90. loader: 'expose-loader?$!expose-loader?jQuery',
  91. test: /\/node_modules\/jquery\/.*\.js$/
  92. }, {
  93. // Disable AMD for the Strophe.js library or its imports will fail
  94. // at runtime.
  95. loader: 'imports-loader?define=>false&this=>window',
  96. test: strophe
  97. }, {
  98. // Set scope to window for URL polyfill.
  99. loader: 'imports-loader?this=>window',
  100. test: /\/node_modules\/url-polyfill\/.*\.js$/
  101. }, {
  102. // Allow CSS to be imported into JavaScript.
  103. test: /\.css$/,
  104. use: [
  105. 'style-loader',
  106. 'css-loader'
  107. ]
  108. }, {
  109. // Emit the static assets of AUI such as images that are referenced
  110. // by CSS into the output path.
  111. include: aui_css,
  112. loader: 'file-loader',
  113. options: {
  114. context: aui_css,
  115. name: '[path][name].[ext]'
  116. },
  117. test: /\.(gif|png|svg)$/
  118. } ],
  119. noParse: [
  120. // Do not parse the files of the Strophe.js library or at least
  121. // parts of the properties of the Strophe global variable will be
  122. // missing and strophejs-plugins will fail at runtime.
  123. strophe
  124. ]
  125. },
  126. node: {
  127. // Allow the use of the real filename of the module being executed. By
  128. // default Webpack does not leak path-related information and provides a
  129. // value that is a mock (/index.js).
  130. __filename: true
  131. },
  132. output: {
  133. filename: '[name]' + (minimize ? '.min' : '') + '.js',
  134. libraryTarget: 'umd',
  135. path: __dirname + '/build',
  136. publicPath: '/libs/',
  137. sourceMapFilename: '[name].' + (minimize ? 'min' : 'js') + '.map'
  138. },
  139. plugins: plugins,
  140. resolve: {
  141. alias: {
  142. jquery: 'jquery/dist/jquery' + (minimize ? '.min' : '') + '.js'
  143. },
  144. aliasFields: [
  145. 'browser'
  146. ],
  147. extensions: [
  148. // Webpack 2 broke haste-resolver-webpack-plugin and I could not fix
  149. // it. But given that there is resolve.extensions and the only
  150. // non-default extension we have is .web.js, drop
  151. // haste-resolver-webpack-plugin and go with resolve.extensions.
  152. '.web.js',
  153. // Webpack defaults:
  154. '.js',
  155. '.json'
  156. ]
  157. }
  158. };
  159. const configs = [
  160. // The Webpack configuration to bundle app.bundle.js (aka APP).
  161. Object.assign({}, config, {
  162. entry: {
  163. 'app.bundle': [
  164. // XXX Required by at least IE11 at the time of this writing.
  165. 'babel-polyfill',
  166. './app.js'
  167. ]
  168. },
  169. output: Object.assign({}, config.output, {
  170. library: 'APP'
  171. })
  172. }),
  173. // The Webpack configuration to bundle device_selection_popup_bundle.js
  174. // (i.e. js file for the device selection popup dialog).
  175. Object.assign({}, config, {
  176. entry: {
  177. 'device_selection_popup_bundle':
  178. './react/features/device-selection/popup.js'
  179. }
  180. }),
  181. // The Webpack configuration to bundle do_external_connect.js (which
  182. // attempts to optimize Jitsi Meet's XMPP connection and, consequently, is
  183. // also known as HTTP pre-bind).
  184. Object.assign({}, config, {
  185. entry: {
  186. 'do_external_connect':
  187. './connection_optimization/do_external_connect.js'
  188. }
  189. }),
  190. // The Webpack configuration to bundle external_api.js (aka
  191. // JitsiMeetExternalAPI).
  192. Object.assign({}, config, {
  193. entry: {
  194. 'external_api': './modules/API/external/index.js'
  195. },
  196. output: Object.assign({}, config.output, {
  197. library: 'JitsiMeetExternalAPI'
  198. })
  199. })
  200. ];
  201. module.exports = configs;
  202. /**
  203. * Determines whether a specific (HTTP) request is to bypass the proxy of
  204. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  205. * which local file is to be served in response to the request.
  206. *
  207. * @param {Object} request - The (HTTP) request received by the proxy.
  208. * @returns {string|undefined} If the request is to be served by the proxy
  209. * target, undefined; otherwise, the path to the local file to be served.
  210. */
  211. function devServerProxyBypass(request) {
  212. let path = request.path;
  213. // Use local files from the css and libs directories.
  214. if (path.startsWith('/css/')) {
  215. return path;
  216. }
  217. if (configs.some(function (c) {
  218. if (path.startsWith(c.output.publicPath)) {
  219. if (!minimize) {
  220. // Since webpack-dev-server is serving non-minimized
  221. // artifacts, serve them even if the minimized ones are
  222. // requested.
  223. Object.keys(c.entry).some(function (e) {
  224. var name = e + '.min.js';
  225. if (path.indexOf(name) !== -1) {
  226. path = path.replace(name, e + '.js');
  227. return true;
  228. }
  229. });
  230. }
  231. return true;
  232. }
  233. })) {
  234. return path;
  235. }
  236. }