Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

webpack.config.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* global __dirname */
  2. const process = require('process');
  3. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  4. const webpack = require('webpack');
  5. const auiCSS = `${__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. // eslint-disable-next-line camelcase
  16. const node_modules = `${__dirname}/node_modules/`;
  17. const plugins = [
  18. new webpack.LoaderOptionsPlugin({
  19. debug: !minimize,
  20. minimize
  21. })
  22. ];
  23. if (minimize) {
  24. // XXX Webpack's command line argument -p is not enough. Further
  25. // optimizations are made possible by the use of DefinePlugin and NODE_ENV
  26. // with value 'production'. For example, React takes advantage of these.
  27. plugins.push(new webpack.DefinePlugin({
  28. 'process.env': {
  29. NODE_ENV: JSON.stringify('production')
  30. }
  31. }));
  32. plugins.push(new webpack.optimize.ModuleConcatenationPlugin());
  33. plugins.push(new UglifyJsPlugin({
  34. cache: true,
  35. extractComments: true,
  36. parallel: true,
  37. sourceMap: true
  38. }));
  39. }
  40. // The base Webpack configuration to bundle the JavaScript artifacts of
  41. // jitsi-meet such as app.bundle.js and external_api.js.
  42. const config = {
  43. devServer: {
  44. https: true,
  45. inline: true,
  46. proxy: {
  47. '/': {
  48. bypass: devServerProxyBypass,
  49. secure: false,
  50. target: devServerProxyTarget
  51. }
  52. }
  53. },
  54. devtool: 'source-map',
  55. module: {
  56. rules: [ {
  57. // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
  58. // as well.
  59. exclude: node_modules, // eslint-disable-line camelcase
  60. loader: 'babel-loader',
  61. options: {
  62. // XXX The require.resolve bellow solves failures to locate the
  63. // presets when lib-jitsi-meet, for example, is npm linked in
  64. // jitsi-meet. The require.resolve, of course, mandates the use
  65. // of the prefix babel-preset- in the preset names.
  66. presets: [
  67. [
  68. require.resolve('babel-preset-env'),
  69. // Tell babel to avoid compiling imports into CommonJS
  70. // so that webpack may do tree shaking.
  71. { modules: false }
  72. ],
  73. require.resolve('babel-preset-react'),
  74. require.resolve('babel-preset-stage-1')
  75. ]
  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. // Set scope to window for URL polyfill.
  86. loader: 'imports-loader?this=>window',
  87. test: /\/node_modules\/url-polyfill\/.*\.js$/
  88. }, {
  89. // Allow CSS to be imported into JavaScript.
  90. test: /\.css$/,
  91. use: [
  92. 'style-loader',
  93. 'css-loader'
  94. ]
  95. }, {
  96. // Emit the static assets of AUI such as images that are referenced
  97. // by CSS into the output path.
  98. include: auiCSS,
  99. loader: 'file-loader',
  100. options: {
  101. context: auiCSS,
  102. name: '[path][name].[ext]'
  103. },
  104. test: /\.(gif|png|svg)$/
  105. } ]
  106. },
  107. node: {
  108. // Allow the use of the real filename of the module being executed. By
  109. // default Webpack does not leak path-related information and provides a
  110. // value that is a mock (/index.js).
  111. __filename: true
  112. },
  113. output: {
  114. filename: `[name]${minimize ? '.min' : ''}.js`,
  115. path: `${__dirname}/build`,
  116. publicPath: '/libs/',
  117. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  118. },
  119. plugins,
  120. resolve: {
  121. alias: {
  122. jquery: `jquery/dist/jquery${minimize ? '.min' : ''}.js`
  123. },
  124. aliasFields: [
  125. 'browser'
  126. ],
  127. extensions: [
  128. '.web.js',
  129. // Webpack defaults:
  130. '.js',
  131. '.json'
  132. ]
  133. }
  134. };
  135. module.exports = [
  136. Object.assign({}, config, {
  137. entry: {
  138. 'app.bundle': [
  139. // XXX Required by at least IE11 at the time of this writing.
  140. 'babel-polyfill',
  141. './app.js'
  142. ],
  143. 'device_selection_popup_bundle':
  144. './react/features/device-selection/popup.js',
  145. 'alwaysontop':
  146. './react/features/always-on-top/index.js',
  147. 'do_external_connect':
  148. './connection_optimization/do_external_connect.js'
  149. }
  150. }),
  151. // The Webpack configuration to bundle external_api.js (aka
  152. // JitsiMeetExternalAPI).
  153. Object.assign({}, config, {
  154. entry: {
  155. 'external_api': [
  156. // XXX Required by at least IE11 at the time of this writing.
  157. 'babel-polyfill',
  158. './modules/API/external/index.js'
  159. ]
  160. },
  161. output: Object.assign({}, config.output, {
  162. library: 'JitsiMeetExternalAPI',
  163. libraryTarget: 'umd'
  164. })
  165. })
  166. ];
  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({ path }) {
  177. if (path.startsWith('/css/') || path.startsWith('/doc/')) {
  178. return path;
  179. }
  180. const configs = module.exports;
  181. /* eslint-disable array-callback-return, indent */
  182. if ((Array.isArray(configs) ? configs : Array(configs)).some(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(e => {
  189. const name = `${e}.min.js`;
  190. if (path.indexOf(name) !== -1) {
  191. // eslint-disable-next-line no-param-reassign
  192. path = path.replace(name, `${e}.js`);
  193. return true;
  194. }
  195. });
  196. }
  197. return true;
  198. }
  199. })) {
  200. return path;
  201. }
  202. /* eslint-enable array-callback-return, indent */
  203. }