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

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