-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.js
126 lines (113 loc) · 3.23 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) Jupyter Development Team.
// Copyright (c) Voila Development Team.
// Distributed under the terms of the Modified BSD License.
const fs = require('fs-extra');
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge').default;
const { ModuleFederationPlugin } = webpack.container;
const Build = require('@jupyterlab/builder').Build;
const baseConfig = require('@jupyterlab/builder/lib/webpack.config.base');
const data = require('./package.json');
/**
* A helper for filtering deprecated webpack loaders, to be replaced with assets
*/
function filterDeprecatedRule(rule) {
if (typeof rule.use === 'string' && rule.use.match(/^(file|url)-loader/)) {
return false;
}
return true;
}
baseConfig.module.rules = [
{
test: /\.json$/,
use: ['json-loader'],
type: 'javascript/auto'
},
...baseConfig.module.rules.filter(filterDeprecatedRule)
];
const names = Object.keys(data.dependencies).filter(name => {
const packageData = require(path.join(name, 'package.json'));
return packageData.jupyterlab !== undefined;
});
// Ensure a clear build directory.
const buildDir = path.resolve(__dirname, 'build');
if (fs.existsSync(buildDir)) {
fs.removeSync(buildDir);
}
fs.ensureDirSync(buildDir);
// Copy files to the build directory
const libDir = path.resolve(__dirname, 'lib');
const style = path.resolve(__dirname, 'style.css');
fs.copySync(libDir, buildDir);
fs.copySync(style, path.resolve(buildDir, 'style.css'));
const distRoot = path.resolve(
__dirname,
'..',
'..',
'voici',
'static',
'build'
);
const extras = Build.ensureAssets({
packageNames: names,
output: buildDir,
staticOutput: path.resolve(distRoot)
});
// Make a bootstrap entrypoint
const entryPoint = path.join(buildDir, 'bootstrap.js');
const treeEntryPoint = path.join(buildDir, 'treebootstrap.js');
if (process.env.NODE_ENV === 'production') {
baseConfig.mode = 'production';
}
module.exports = [
merge(baseConfig, {
mode: 'development',
entry: {
voici: ['./publicpath.js', './' + path.relative(__dirname, entryPoint)],
treepage: [
'./publicpath.js',
'./' + path.relative(__dirname, treeEntryPoint)
]
},
output: {
path: distRoot,
library: {
type: 'var',
name: ['_JUPYTERLAB', 'CORE_OUTPUT']
},
filename: '[name].js'
},
module: {
rules: [
// just keep the woff2 fonts from fontawesome
{
test: /fontawesome-free.*\.(svg|eot|ttf|woff)$/,
loader: 'ignore-loader'
},
{
test: /\.(jpe?g|png|gif|ico|eot|ttf|map|woff2?)(\?v=\d+\.\d+\.\d+)?$/i,
type: 'asset/resource'
}
]
},
plugins: [
new webpack.DefinePlugin({
// Needed for Blueprint. See https://github.com/palantir/blueprint/issues/4393
'process.env': '{}',
// Needed for various packages using cwd(), like the path polyfill
process: { cwd: () => '/' }
}),
new ModuleFederationPlugin({
library: {
type: 'var',
name: ['_JUPYTERLAB', 'CORE_LIBRARY_FEDERATION']
},
name: 'CORE_FEDERATION',
shared: {
...data.dependencies
}
})
]
})
].concat(extras);