Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

webpack.config.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. plugins: [
  54. 'transform-flow-strip-types'
  55. ],
  56. // XXX The require.resolve bellow solves failures to locate the
  57. // presets when lib-jitsi-meet, for example, is npm linked in
  58. // jitsi-meet. The require.resolve, of course, mandates the use
  59. // of the prefix babel-preset- in the preset names.
  60. presets: [
  61. 'babel-preset-es2015',
  62. 'babel-preset-react',
  63. 'babel-preset-stage-1'
  64. ].map(require.resolve)
  65. },
  66. test: /\.jsx?$/
  67. }, {
  68. // Expose jquery as the globals $ and jQuery because it is expected
  69. // to be available in such a form by multiple jitsi-meet
  70. // dependencies including AUI, lib-jitsi-meet.
  71. loader: 'expose?$!expose?jQuery',
  72. test: /\/node_modules\/jquery\/.*\.js$/
  73. }, {
  74. // Disable AMD for the Strophe.js library or its imports will fail
  75. // at runtime.
  76. loader: 'imports?define=>false&this=>window',
  77. test: strophe
  78. }, {
  79. // Allow CSS to be imported into JavaScript.
  80. loaders: [
  81. 'style',
  82. 'css'
  83. ],
  84. test: /\.css$/
  85. }, {
  86. // Emit the static assets of AUI such as images that are referenced
  87. // by CSS into the output path.
  88. include: aui_css,
  89. loader: 'file',
  90. query: {
  91. context: aui_css,
  92. name: '[path][name].[ext]'
  93. },
  94. test: /\.(gif|png|svg)$/
  95. }, {
  96. // Enable the import of JSON files.
  97. loader: 'json',
  98. exclude: node_modules,
  99. test: /\.json$/
  100. } ],
  101. noParse: [
  102. // Do not parse the files of the Strophe.js library or at least
  103. // parts of the properties of the Strophe global variable will be
  104. // missing and strophejs-plugins will fail at runtime.
  105. strophe
  106. ]
  107. },
  108. node: {
  109. // Allow the use of the real filename of the module being executed. By
  110. // default Webpack does not leak path-related information and provides a
  111. // value that is a mock (/index.js).
  112. __filename: true
  113. },
  114. output: {
  115. filename: '[name]' + (minimize ? '.min' : '') + '.js',
  116. libraryTarget: 'umd',
  117. path: __dirname + '/build',
  118. publicPath: '/libs/',
  119. sourceMapFilename: '[name].' + (minimize ? 'min' : 'js') + '.map'
  120. },
  121. plugins: plugins,
  122. resolve: {
  123. alias: {
  124. jquery: 'jquery/dist/jquery' + (minimize ? '.min' : '') + '.js'
  125. },
  126. packageAlias: 'browser'
  127. }
  128. };
  129. var configs = [
  130. // The Webpack configuration to bundle app.bundle.js (aka APP).
  131. Object.assign({}, config, {
  132. entry: {
  133. 'app.bundle': './app.js'
  134. },
  135. output: Object.assign({}, config.output, {
  136. library: 'APP'
  137. })
  138. }),
  139. // The Webpack configuration to bundle external_api.js (aka
  140. // JitsiMeetExternalAPI).
  141. Object.assign({}, config, {
  142. entry: {
  143. 'external_api': './modules/API/external/external_api.js'
  144. },
  145. output: Object.assign({}, config.output, {
  146. library: 'JitsiMeetExternalAPI'
  147. })
  148. })
  149. ];
  150. module.exports = configs;
  151. /**
  152. * Determines whether a specific (HTTP) request is to bypass the proxy of
  153. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  154. * which local file is to be served in response to the request.
  155. *
  156. * @param {Object} request - The (HTTP) request received by the proxy.
  157. * @returns {string|undefined} If the request is to be served by the proxy
  158. * target, undefined; otherwise, the path to the local file to be served.
  159. */
  160. function devServerProxyBypass(request) {
  161. var path = request.path;
  162. // Use local files from the css and libs directories.
  163. if (path.startsWith('/css/')) {
  164. return path;
  165. }
  166. if (configs.some(function (c) {
  167. if (path.startsWith(c.output.publicPath)) {
  168. if (!minimize) {
  169. // Since webpack-dev-server is serving non-minimized
  170. // artifacts, serve them even if the minimized ones are
  171. // requested.
  172. Object.keys(c.entry).some(function (e) {
  173. var name = e + '.min.js';
  174. if (path.indexOf(name) !== -1) {
  175. path = path.replace(name, e + '.js');
  176. return true;
  177. }
  178. });
  179. }
  180. return true;
  181. }
  182. })) {
  183. return path;
  184. }
  185. }