Debian Codegraph @

webpack.config.js

raw
1 const path = require('path');
2 const version = require('./package.json').version;
3
4 const luminoThemeImages = /^.*@lumino\/default-theme.*.png$/;
5
6 const crypto = require('crypto');
7
8 // Workaround for loaders using "md4" by default, which is not supported in FIPS-compliant OpenSSL
9 const cryptoOrigCreateHash = crypto.createHash;
10 crypto.createHash = (algorithm) =>
11 cryptoOrigCreateHash(algorithm == 'md4' ? 'sha256' : algorithm);
12
13
14 // Custom webpack rules
15 const rules = [
16 { test: /\.ts$/, loader: 'ts-loader' },
17 { test: /\.js$/, loader: 'source-map-loader' },
18 { test: /\.css$/, use: ['style-loader', 'css-loader'] },
19 {
20 test: luminoThemeImages,
21 issuer: /\.css$/,
22 use: {
23 loader: 'url-loader',
24 },
25 },
26 {
27 test: /\.(jpg|png|gif)$/,
28 exclude: luminoThemeImages,
29 use: ['file-loader'],
30 },
31 {
32 test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
33 issuer: /\.css$/,
34 use: {
35 loader: 'svg-url-loader',
36 options: { encoding: 'none', limit: 10000 },
37 },
38 },
39 ];
40
41 // Packages that shouldn't be bundled but loaded at runtime
42 const externals = ['@jupyter-widgets/base'];
43
44 const resolve = {
45 // Add '.ts' and '.tsx' as resolvable extensions.
46 extensions: ['.webpack.js', '.web.js', '.ts', '.js'],
47 fallback: { crypto: false },
48 };
49
50 module.exports = [
51 /**
52 * Notebook extension
53 *
54 * This bundle only contains the part of the JavaScript that is run on load of
55 * the notebook.
56 */
57 {
58 entry: './js/extension.ts',
59 output: {
60 filename: 'index.js',
61 path: path.resolve(__dirname, 'ipydatagrid', 'nbextension'),
62 libraryTarget: 'amd',
63 },
64 module: {
65 rules: rules,
66 },
67 devtool: 'source-map',
68 externals,
69 resolve,
70 },
71
72 /**
73 * Embeddable ipydatagrid bundle
74 *
75 * This bundle is almost identical to the notebook extension bundle. The only
76 * difference is in the configuration of the webpack public path for the
77 * static assets.
78 *
79 * The target bundle is always `dist/index.js`, which is the path required by
80 * the custom widget embedder.
81 */
82 {
83 entry: './js/index.ts',
84 output: {
85 filename: 'index.js',
86 path: path.resolve(__dirname, 'dist'),
87 libraryTarget: 'amd',
88 library: 'ipydatagrid',
89 publicPath: 'https://unpkg.com/ipydatagrid@' + version + '/dist/',
90 },
91 devtool: 'source-map',
92 module: {
93 rules: rules,
94 },
95 externals,
96 resolve,
97 },
98
99 /**
100 * Documentation widget bundle
101 *
102 * This bundle is used to embed widgets in the package documentation.
103 */
104 {
105 entry: './js/index.ts',
106 output: {
107 filename: 'embed-bundle.js',
108 path: path.resolve(__dirname, 'docs', 'source', '_static'),
109 library: 'ipydatagrid',
110 libraryTarget: 'amd',
111 },
112 module: {
113 rules: rules,
114 },
115 devtool: 'source-map',
116 externals,
117 resolve,
118 },
119 ];