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 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* global __dirname */
  2. require('babel-polyfill'); // Define Object.assign() from ES6 in ES5.
  3. var HasteResolverPlugin = require('haste-resolver-webpack-plugin');
  4. var process = require('process');
  5. var webpack = require('webpack');
  6. var aui_css = __dirname + '/node_modules/@atlassian/aui/dist/aui/css/';
  7. /**
  8. * The URL of the Jitsi Meet deployment to be proxy to in the context of
  9. * development with webpack-dev-server.
  10. */
  11. var devServerProxyTarget
  12. = process.env.WEBPACK_DEV_SERVER_PROXY_TARGET || 'https://beta.meet.jit.si';
  13. var minimize
  14. = process.argv.indexOf('-p') !== -1
  15. || process.argv.indexOf('--optimize-minimize') !== -1;
  16. var node_modules = __dirname + '/node_modules/';
  17. var plugins = [
  18. new HasteResolverPlugin()
  19. ];
  20. var strophe = /\/node_modules\/strophe(js-plugins)?\/.*\.js$/;
  21. if (minimize) {
  22. // XXX Webpack's command line argument -p is not enough. Further
  23. // optimizations are made possible by the use of DefinePlugin and NODE_ENV
  24. // with value 'production'. For example, React takes advantage of these.
  25. plugins.push(new webpack.DefinePlugin({
  26. 'process.env': {
  27. NODE_ENV: JSON.stringify('production')
  28. }
  29. }));
  30. }
  31. // The base Webpack configuration to bundle the JavaScript artifacts of
  32. // jitsi-meet such as app.bundle.js and external_api.js.
  33. var config = {
  34. devServer: {
  35. https: true,
  36. inline: true,
  37. proxy: {
  38. '/': {
  39. bypass: devServerProxyBypass,
  40. secure: false,
  41. target: devServerProxyTarget
  42. }
  43. }
  44. },
  45. devtool: 'source-map',
  46. module: {
  47. loaders: [ {
  48. // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
  49. // as well.
  50. exclude: node_modules,
  51. loader: 'babel',
  52. query: {
  53. // XXX The require.resolve bellow solves failures to locate the
  54. // presets when lib-jitsi-meet, for example, is npm linked in
  55. // jitsi-meet. The require.resolve, of course, mandates the use
  56. // of the prefix babel-preset- in the preset names.
  57. presets: [
  58. 'babel-preset-es2015',
  59. 'babel-preset-react',
  60. 'babel-preset-stage-1'
  61. ].map(require.resolve)
  62. },
  63. test: /\.jsx?$/
  64. }, {
  65. // Expose jquery as the globals $ and jQuery because it is expected
  66. // to be available in such a form by multiple jitsi-meet
  67. // dependencies including AUI, lib-jitsi-meet.
  68. loader: 'expose?$!expose?jQuery',
  69. test: /\/node_modules\/jquery\/.*\.js$/
  70. }, {
  71. // Disable AMD for the Strophe.js library or its imports will fail
  72. // at runtime.
  73. loader: 'imports?define=>false&this=>window',
  74. test: strophe
  75. }, {
  76. // Allow CSS to be imported into JavaScript.
  77. loaders: [
  78. 'style',
  79. 'css'
  80. ],
  81. test: /\.css$/
  82. }, {
  83. // Emit the static assets of AUI such as images that are referenced
  84. // by CSS into the output path.
  85. include: aui_css,
  86. loader: 'file',
  87. query: {
  88. context: aui_css,
  89. name: '[path][name].[ext]'
  90. },
  91. test: /\.(gif|png|svg)$/
  92. }, {
  93. // Enable the import of JSON files.
  94. loader: 'json',
  95. exclude: node_modules,
  96. test: /\.json$/
  97. } ],
  98. noParse: [
  99. // Do not parse the files of the Strophe.js library or at least
  100. // parts of the properties of the Strophe global variable will be
  101. // missing and strophejs-plugins will fail at runtime.
  102. strophe
  103. ]
  104. },
  105. node: {
  106. // Allow the use of the real filename of the module being executed. By
  107. // default Webpack does not leak path-related information and provides a
  108. // value that is a mock (/index.js).
  109. __filename: true
  110. },
  111. output: {
  112. filename: '[name]' + (minimize ? '.min' : '') + '.js',
  113. libraryTarget: 'umd',
  114. path: __dirname + '/build',
  115. publicPath: '/libs/',
  116. sourceMapFilename: '[name].' + (minimize ? 'min' : 'js') + '.map'
  117. },
  118. plugins: plugins,
  119. resolve: {
  120. alias: {
  121. jquery: 'jquery/dist/jquery' + (minimize ? '.min' : '') + '.js'
  122. },
  123. packageAlias: 'browser'
  124. }
  125. };
  126. var configs = [
  127. // The Webpack configuration to bundle app.bundle.js (aka APP).
  128. Object.assign({}, config, {
  129. entry: {
  130. 'app.bundle': './app.js'
  131. },
  132. output: Object.assign({}, config.output, {
  133. library: 'APP'
  134. })
  135. }),
  136. // The Webpack configuration to bundle external_api.js (aka
  137. // JitsiMeetExternalAPI).
  138. Object.assign({}, config, {
  139. entry: {
  140. 'external_api': './modules/API/external/external_api.js'
  141. },
  142. output: Object.assign({}, config.output, {
  143. library: 'JitsiMeetExternalAPI'
  144. })
  145. })
  146. ];
  147. module.exports = configs;
  148. /**
  149. * Determines whether a specific (HTTP) request is to bypass the proxy of
  150. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  151. * which local file is to be served in response to the request.
  152. *
  153. * @param {Object} request - The (HTTP) request received by the proxy.
  154. * @returns {string|undefined} If the request is to be served by the proxy
  155. * target, undefined; otherwise, the path to the local file to be served.
  156. */
  157. function devServerProxyBypass(request) {
  158. var path = request.path;
  159. // Use local files from the css and libs directories.
  160. if (path.startsWith('/css/')) {
  161. return path;
  162. }
  163. if (configs.some(function (c) {
  164. if (path.startsWith(c.output.publicPath)) {
  165. if (!minimize) {
  166. // Since webpack-dev-server is serving non-minimized
  167. // artifacts, serve them even if the minimized ones are
  168. // requested.
  169. Object.keys(c.entry).some(function (e) {
  170. var name = e + '.min.js';
  171. if (path.indexOf(name) !== -1) {
  172. path = path.replace(name, e + '.js');
  173. return true;
  174. }
  175. });
  176. }
  177. return true;
  178. }
  179. })) {
  180. return path;
  181. }
  182. }