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.5KB

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