webpack.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. const data = require('./package.json');
  4. const Build = require('@jupyterlab/buildutils').Build;
  5. const webpack = require('webpack');
  6. const { ModuleFederationPlugin } = webpack.container;
  7. const path = require('path');
  8. const names = Object.keys(data.dependencies).filter(function(name) {
  9. const packageData = require(name + '/package.json');
  10. return packageData.jupyterlab !== undefined;
  11. });
  12. const extras = Build.ensureAssets({
  13. packageNames: names,
  14. output: './build'
  15. });
  16. const rules = [
  17. { test: /\.css$/, use: ['style-loader', 'css-loader'] },
  18. { test: /\.html$/, use: 'file-loader' },
  19. { test: /\.md$/, use: 'raw-loader' },
  20. { test: /\.(jpg|png|gif)$/, use: 'file-loader' },
  21. { test: /\.js.map$/, use: 'file-loader' },
  22. {
  23. test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
  24. use: 'url-loader?limit=10000&mimetype=application/font-woff'
  25. },
  26. {
  27. test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
  28. use: 'url-loader?limit=10000&mimetype=application/font-woff'
  29. },
  30. {
  31. test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
  32. use: 'url-loader?limit=10000&mimetype=application/octet-stream'
  33. },
  34. { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, use: 'file-loader' },
  35. {
  36. // In .css files, svg is loaded as a data URI.
  37. test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
  38. issuer: /\.css$/,
  39. use: {
  40. loader: 'svg-url-loader',
  41. options: { encoding: 'none', limit: 10000 }
  42. }
  43. },
  44. {
  45. // In .ts and .tsx files (both of which compile to .js), svg files
  46. // must be loaded as a raw string instead of data URIs.
  47. test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
  48. issuer: /\.js$/,
  49. use: {
  50. loader: 'raw-loader'
  51. }
  52. }
  53. ];
  54. const options = {
  55. devtool: 'source-map',
  56. bail: true,
  57. mode: 'development'
  58. };
  59. let dependencies = {
  60. ...data.dependencies,
  61. '@jupyterlab/rendermime': '^2.1.0',
  62. '@jupyterlab/coreutils': '^4.1.0',
  63. '@jupyterlab/settingregistry': '^2.1.0',
  64. '@lumino/algorithm': '^1.2.3',
  65. '@lumino/application': '^1.8.4',
  66. '@lumino/commands': '^1.10.1',
  67. '@lumino/coreutils': '^1.4.3',
  68. '@lumino/disposable': '^1.3.5',
  69. '@lumino/domutils': '^1.1.7',
  70. '@lumino/dragdrop': '^1.5.1',
  71. '@lumino/messaging': '^1.3.3',
  72. '@lumino/properties': '^1.1.6',
  73. '@lumino/signaling': '^1.3.5',
  74. '@lumino/virtualdom': '^1.6.1',
  75. '@lumino/widgets': '^1.11.1',
  76. react: '~16.9.0',
  77. 'react-dom': '~16.9.0'
  78. };
  79. delete dependencies['@jupyterlab/markdownviewer-extension'];
  80. let shared = Object.fromEntries(
  81. Object.entries(dependencies).filter(
  82. ([pkg]) => pkg.startsWith('@lumino') || pkg.startsWith('@jupyterlab')
  83. )
  84. );
  85. module.exports = [
  86. {
  87. entry: './index.js',
  88. output: {
  89. path: path.resolve(__dirname, 'build'),
  90. library: {
  91. type: 'var',
  92. name: ['MYNAMESPACE', 'NAME_OUTPUT']
  93. },
  94. filename: 'bundle.js',
  95. publicPath: '/foo/static/example/'
  96. },
  97. stats: 'verbose',
  98. ...options,
  99. module: { rules },
  100. plugins: [
  101. new ModuleFederationPlugin({
  102. library: {
  103. type: 'var',
  104. name: ['MYNAMESPACE', 'NAME_LIBRARY_FEDERATION']
  105. },
  106. name: 'NAME_FEDERATION',
  107. shared: Object.fromEntries(
  108. Object.entries(shared).map(([pkg, version]) => [
  109. pkg,
  110. { singleton: true, requiredVersion: version }
  111. ])
  112. )
  113. }),
  114. new webpack.DefinePlugin({
  115. 'process.env': '{}',
  116. process: {}
  117. })
  118. ]
  119. }
  120. ].concat(extras);