Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

webpack.config.js 8.1KB

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