Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

webpack.config.js 7.9KB

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