webpack.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. const data = require('./package.json');
  4. const webpack = require('webpack');
  5. const Build = require('@jupyterlab/builder').Build;
  6. const jlab = data.jupyterlab;
  7. // Create a list of application extensions and mime extensions from
  8. // jlab.extensions
  9. const extensions = {};
  10. const mimeExtensions = {};
  11. for (const key of jlab.extensions) {
  12. const {
  13. jupyterlab: { extension, mimeExtension }
  14. } = require(`${key}/package.json`);
  15. if (extension !== undefined) {
  16. extensions[key] = extension === true ? '' : extension;
  17. }
  18. if (mimeExtension !== undefined) {
  19. mimeExtensions[key] = mimeExtension === true ? '' : mimeExtension;
  20. }
  21. }
  22. const extensionAssetConfig = Build.ensureAssets({
  23. packageNames: [...Object.keys(jlab.extensions ?? {}), ...Object.keys(jlab.mimeExtensions ?? {})],
  24. output: './build'
  25. });
  26. module.exports = [
  27. {
  28. entry: ['whatwg-fetch', './index.js'],
  29. output: {
  30. path: __dirname + '/build',
  31. filename: 'bundle.js'
  32. },
  33. // node: {
  34. // fs: 'empty'
  35. // },
  36. bail: true,
  37. devtool: 'source-map',
  38. mode: 'development',
  39. module: {
  40. rules: [
  41. { test: /\.css$/, use: ['style-loader', 'css-loader'] },
  42. { test: /\.html$/, use: 'file-loader' },
  43. { test: /\.md$/, use: 'raw-loader' },
  44. { test: /\.(jpg|png|gif)$/, use: 'file-loader' },
  45. { test: /\.js.map$/, use: 'file-loader' },
  46. {
  47. test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
  48. use: 'url-loader?limit=10000&mimetype=application/font-woff'
  49. },
  50. {
  51. test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
  52. use: 'url-loader?limit=10000&mimetype=application/font-woff'
  53. },
  54. {
  55. test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
  56. use: 'url-loader?limit=10000&mimetype=application/octet-stream'
  57. },
  58. { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, use: 'file-loader' },
  59. {
  60. // In .css files, svg is loaded as a data URI.
  61. test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
  62. issuer: /\.css$/,
  63. use: {
  64. loader: 'svg-url-loader',
  65. options: { encoding: 'none', limit: 10000 }
  66. }
  67. },
  68. {
  69. // In .ts and .tsx files (both of which compile to .js), svg files
  70. // must be loaded as a raw string instead of data URIs.
  71. test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
  72. issuer: /\.js$/,
  73. use: {
  74. loader: 'raw-loader'
  75. }
  76. }
  77. ]
  78. },
  79. plugins: [
  80. new webpack.DefinePlugin({
  81. // Needed for Blueprint. See https://github.com/palantir/blueprint/issues/4393
  82. 'process.env': '{}',
  83. // Needed for various packages using cwd(), like the path polyfill
  84. process: { cwd: () => '/' }
  85. })
  86. ]
  87. }
  88. ].concat(extensionAssetConfig);