Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

webpack.config.js 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. // While webpack will automatically insert UglifyJsPlugin when minimize is
  31. // true, the defaults of UglifyJsPlugin in webpack 1 and webpack 2 are
  32. // different. Explicitly state what we want even if we want defaults in
  33. // order to prepare for webpack 2.
  34. plugins.push(new webpack.optimize.UglifyJsPlugin({
  35. compress: {
  36. // It is nice to see warnings from UglifyJsPlugin that something is
  37. // unused and, consequently, is removed. The default is false in
  38. // webpack 2.
  39. warnings: true
  40. },
  41. // Use the source map to map error message locations to modules. The
  42. // default is false in webpack 2.
  43. sourceMap: true
  44. }));
  45. }
  46. // The base Webpack configuration to bundle the JavaScript artifacts of
  47. // jitsi-meet such as app.bundle.js and external_api.js.
  48. var config = {
  49. devServer: {
  50. https: true,
  51. inline: true,
  52. proxy: {
  53. '/': {
  54. bypass: devServerProxyBypass,
  55. secure: false,
  56. target: devServerProxyTarget
  57. }
  58. }
  59. },
  60. devtool: 'source-map',
  61. module: {
  62. loaders: [ {
  63. // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
  64. // as well.
  65. exclude: node_modules,
  66. loader: 'babel-loader',
  67. query: {
  68. // XXX The require.resolve bellow solves failures to locate the
  69. // presets when lib-jitsi-meet, for example, is npm linked in
  70. // jitsi-meet. The require.resolve, of course, mandates the use
  71. // of the prefix babel-preset- in the preset names.
  72. presets: [
  73. 'babel-preset-es2015',
  74. 'babel-preset-react',
  75. 'babel-preset-stage-1'
  76. ].map(require.resolve)
  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. loaders: [
  97. 'style-loader',
  98. 'css-loader'
  99. ],
  100. test: /\.css$/
  101. }, {
  102. // Emit the static assets of AUI such as images that are referenced
  103. // by CSS into the output path.
  104. include: aui_css,
  105. loader: 'file-loader',
  106. query: {
  107. context: aui_css,
  108. name: '[path][name].[ext]'
  109. },
  110. test: /\.(gif|png|svg)$/
  111. }, {
  112. // Enable the import of JSON files.
  113. loader: 'json-loader',
  114. exclude: node_modules,
  115. test: /\.json$/
  116. } ],
  117. noParse: [
  118. // Do not parse the files of the Strophe.js library or at least
  119. // parts of the properties of the Strophe global variable will be
  120. // missing and strophejs-plugins will fail at runtime.
  121. strophe
  122. ]
  123. },
  124. node: {
  125. // Allow the use of the real filename of the module being executed. By
  126. // default Webpack does not leak path-related information and provides a
  127. // value that is a mock (/index.js).
  128. __filename: true
  129. },
  130. output: {
  131. filename: '[name]' + (minimize ? '.min' : '') + '.js',
  132. libraryTarget: 'umd',
  133. path: __dirname + '/build',
  134. publicPath: '/libs/',
  135. sourceMapFilename: '[name].' + (minimize ? 'min' : 'js') + '.map'
  136. },
  137. plugins: plugins,
  138. resolve: {
  139. alias: {
  140. jquery: 'jquery/dist/jquery' + (minimize ? '.min' : '') + '.js'
  141. },
  142. packageAlias: 'browser'
  143. }
  144. };
  145. var configs = [
  146. // The Webpack configuration to bundle app.bundle.js (aka APP).
  147. Object.assign({}, config, {
  148. entry: {
  149. 'app.bundle': './app.js'
  150. },
  151. output: Object.assign({}, config.output, {
  152. library: 'APP'
  153. })
  154. }),
  155. // The Webpack configuration to bundle external_api.js (aka
  156. // JitsiMeetExternalAPI).
  157. Object.assign({}, config, {
  158. entry: {
  159. 'external_api': './modules/API/external/external_api.js'
  160. },
  161. output: Object.assign({}, config.output, {
  162. library: 'JitsiMeetExternalAPI'
  163. })
  164. })
  165. ];
  166. module.exports = configs;
  167. /**
  168. * Determines whether a specific (HTTP) request is to bypass the proxy of
  169. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  170. * which local file is to be served in response to the request.
  171. *
  172. * @param {Object} request - The (HTTP) request received by the proxy.
  173. * @returns {string|undefined} If the request is to be served by the proxy
  174. * target, undefined; otherwise, the path to the local file to be served.
  175. */
  176. function devServerProxyBypass(request) {
  177. var path = request.path;
  178. // Use local files from the css and libs directories.
  179. if (path.startsWith('/css/')) {
  180. return path;
  181. }
  182. if (configs.some(function (c) {
  183. if (path.startsWith(c.output.publicPath)) {
  184. if (!minimize) {
  185. // Since webpack-dev-server is serving non-minimized
  186. // artifacts, serve them even if the minimized ones are
  187. // requested.
  188. Object.keys(c.entry).some(function (e) {
  189. var name = e + '.min.js';
  190. if (path.indexOf(name) !== -1) {
  191. path = path.replace(name, e + '.js');
  192. return true;
  193. }
  194. });
  195. }
  196. return true;
  197. }
  198. })) {
  199. return path;
  200. }
  201. }