Skip to content

Commit 8f1c19f

Browse files
committed
Add HtmlWebpackPlugin - rough draft
1 parent 5d64d49 commit 8f1c19f

15 files changed

+717
-263
lines changed

app/webpack.config.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const BundleAnalyzerPlugin =
1515

1616
const Build = require('@jupyterlab/builder').Build;
1717
const WPPlugin = require('@jupyterlab/builder').WPPlugin;
18+
const HtmlWebpackPlugin = require('html-webpack-plugin');
1819
const baseConfig = require('@jupyterlab/builder/lib/webpack.config.base');
1920

2021
const data = require('./package.json');
@@ -210,6 +211,7 @@ module.exports = [
210211
entry: ['./publicpath.js', './' + path.relative(__dirname, entryPoint)],
211212
output: {
212213
path: path.resolve(__dirname, '..', 'notebook/static/'),
214+
publicPath: '{{page_config.fullStaticUrl}}/',
213215
library: {
214216
type: 'var',
215217
name: ['_JUPYTERLAB', 'CORE_OUTPUT'],
@@ -231,6 +233,78 @@ module.exports = [
231233
fallback: { util: false },
232234
},
233235
plugins: [
236+
new HtmlWebpackPlugin({
237+
chunksSortMode: 'none',
238+
template: path.join(
239+
path.resolve(__dirname, '..', 'notebook/templates'),
240+
'consoles_template.html'
241+
),
242+
title: data.jupyterlab.name,
243+
filename: path.join(
244+
path.resolve(__dirname, '..', 'notebook/templates'),
245+
'consoles.html'
246+
),
247+
}),
248+
new HtmlWebpackPlugin({
249+
chunksSortMode: 'none',
250+
template: path.join(
251+
path.resolve(__dirname, '..', 'notebook/templates'),
252+
'edit_template.html'
253+
),
254+
title: data.jupyterlab.name,
255+
filename: path.join(
256+
path.resolve(__dirname, '..', 'notebook/templates'),
257+
'edit.html'
258+
),
259+
}),
260+
new HtmlWebpackPlugin({
261+
chunksSortMode: 'none',
262+
template: path.join(
263+
path.resolve(__dirname, '..', 'notebook/templates'),
264+
'error_template.html'
265+
),
266+
title: data.jupyterlab.name,
267+
filename: path.join(
268+
path.resolve(__dirname, '..', 'notebook/templates'),
269+
'error.html'
270+
),
271+
}),
272+
new HtmlWebpackPlugin({
273+
chunksSortMode: 'none',
274+
template: path.join(
275+
path.resolve(__dirname, '..', 'notebook/templates'),
276+
'notebooks_template.html'
277+
),
278+
title: data.jupyterlab.name,
279+
filename: path.join(
280+
path.resolve(__dirname, '..', 'notebook/templates'),
281+
'notebooks.html'
282+
),
283+
}),
284+
new HtmlWebpackPlugin({
285+
chunksSortMode: 'none',
286+
template: path.join(
287+
path.resolve(__dirname, '..', 'notebook/templates'),
288+
'terminals_template.html'
289+
),
290+
title: data.jupyterlab.name,
291+
filename: path.join(
292+
path.resolve(__dirname, '..', 'notebook/templates'),
293+
'terminals.html'
294+
),
295+
}),
296+
new HtmlWebpackPlugin({
297+
chunksSortMode: 'none',
298+
template: path.join(
299+
path.resolve(__dirname, '..', 'notebook/templates'),
300+
'tree_template.html'
301+
),
302+
title: data.jupyterlab.name,
303+
filename: path.join(
304+
path.resolve(__dirname, '..', 'notebook/templates'),
305+
'tree.html'
306+
),
307+
}),
234308
new WPPlugin.JSONLicenseWebpackPlugin({
235309
excludedPackageTest: (packageName) =>
236310
packageName === '@jupyter-notebook/app',
@@ -246,3 +320,6 @@ module.exports = [
246320
],
247321
}),
248322
].concat(extras);
323+
324+
const logPath = path.join(buildDir, 'build_log.json');
325+
fs.writeFileSync(logPath, JSON.stringify(module.exports, null, ' '));

notebook/templates/consoles.html

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<meta charset="utf-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
<title>{{page_config['appName'] | e}} - Console</title>
7-
{% block favicon %}
8-
<link rel="icon" type="image/x-icon" href="{{ page_config['fullStaticUrl'] | e }}/favicons/favicon-console.ico" class="favicon">
9-
{% endblock %}
10-
11-
{% if custom_css %}
12-
<link rel="stylesheet" type="text/css" href="{{ base_url | escape }}custom/custom.css">
13-
{% endif %}
14-
</head>
15-
<body class="jp-ThemedContainer">
16-
17-
{# Copy so we do not modify the page_config with updates. #}
18-
{% set page_config_full = page_config.copy() %}
19-
20-
{# Set a dummy variable - we just want the side effect of the update. #}
21-
{% set _ = page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %}
22-
23-
{# Sentinel value to say that we are on the tree page #}
24-
{% set _ = page_config_full.update(notebookPage='consoles') %}
25-
26-
<script id="jupyter-config-data" type="application/json">
27-
{{ page_config_full | tojson }}
28-
</script>
29-
<script src="{{page_config['fullStaticUrl'] | e}}/bundle.js" main="index"></script>
30-
31-
<script type="text/javascript">
32-
/* Remove token from URL. */
33-
(function () {
34-
var parsedUrl = new URL(window.location.href);
35-
if (parsedUrl.searchParams.get('token')) {
36-
parsedUrl.searchParams.delete('token');
37-
window.history.replaceState({ }, '', parsedUrl.href);
38-
}
39-
})();
40-
</script>
41-
42-
</body>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width,initial-scale=1" />
6+
<title>{{page_config['appName'] | e}} - Console</title>
7+
{% block favicon %}
8+
<link
9+
rel="icon"
10+
type="image/x-icon"
11+
href="{{ page_config['fullStaticUrl'] | e }}/favicons/favicon-console.ico"
12+
class="favicon"
13+
/>
14+
{% endblock %} {% if custom_css %}
15+
<link rel="stylesheet" href="{{ base_url | escape }}custom/custom.css" />
16+
{% endif %}
17+
<script
18+
defer="defer"
19+
src="{{page_config.fullStaticUrl}}/main.a4b72be68233e26a3717.js?v=a4b72be68233e26a3717"
20+
></script>
21+
</head>
22+
<body class="jp-ThemedContainer">
23+
{# Copy so we do not modify the page_config with updates. #} {% set
24+
page_config_full = page_config.copy() %} {# Set a dummy variable - we just
25+
want the side effect of the update. #} {% set _ =
26+
page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %} {# Sentinel value
27+
to say that we are on the tree page #} {% set _ =
28+
page_config_full.update(notebookPage='consoles') %}
29+
<script id="jupyter-config-data" type="application/json">
30+
{{ page_config_full | tojson }}
31+
</script>
32+
<script>
33+
/* Remove token from URL. */
34+
(function () {
35+
var parsedUrl = new URL(window.location.href);
36+
if (parsedUrl.searchParams.get('token')) {
37+
parsedUrl.searchParams.delete('token');
38+
window.history.replaceState({}, '', parsedUrl.href);
39+
}
40+
})();
41+
</script>
42+
</body>
4343
</html>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>{{page_config['appName'] | e}} - Console</title>
7+
{% block favicon %}
8+
<link
9+
rel="icon"
10+
type="image/x-icon"
11+
href="{{ page_config['fullStaticUrl'] | e }}/favicons/favicon-console.ico"
12+
class="favicon"
13+
/>
14+
{% endblock %} {% if custom_css %}
15+
<link
16+
rel="stylesheet"
17+
type="text/css"
18+
href="{{ base_url | escape }}custom/custom.css"
19+
/>
20+
{% endif %}
21+
</head>
22+
<body class="jp-ThemedContainer">
23+
{# Copy so we do not modify the page_config with updates. #} {% set
24+
page_config_full = page_config.copy() %} {# Set a dummy variable - we just
25+
want the side effect of the update. #} {% set _ =
26+
page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %} {# Sentinel value
27+
to say that we are on the tree page #} {% set _ =
28+
page_config_full.update(notebookPage='consoles') %}
29+
30+
<script id="jupyter-config-data" type="application/json">
31+
{{ page_config_full | tojson }}
32+
</script>
33+
34+
<script type="text/javascript">
35+
/* Remove token from URL. */
36+
(function () {
37+
var parsedUrl = new URL(window.location.href);
38+
if (parsedUrl.searchParams.get('token')) {
39+
parsedUrl.searchParams.delete('token');
40+
window.history.replaceState({}, '', parsedUrl.href);
41+
}
42+
})();
43+
</script>
44+
</body>
45+
</html>

notebook/templates/edit.html

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,8 @@
1-
<!DOCTYPE html>
2-
<html>
3-
<head>
4-
<meta charset="utf-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
<title>{{page_config['appName'] | e}} - Edit</title>
7-
{% block favicon %}
8-
<link rel="icon" type="image/x-icon" href="{{ base_url | escape }}static/favicons/favicon-file.ico" class="favicon">
9-
{% endblock %}
10-
</head>
11-
<body class="jp-ThemedContainer" data-notebook="edit">
12-
13-
{# Copy so we do not modify the page_config with updates. #}
14-
{% set page_config_full = page_config.copy() %}
15-
16-
{# Set a dummy variable - we just want the side effect of the update. #}
17-
{% set _ = page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %}
18-
19-
{# Sentinel value to say that we are on the tree page #}
20-
{% set _ = page_config_full.update(notebookPage='edit') %}
21-
22-
<script id="jupyter-config-data" type="application/json">
23-
{{ page_config_full | tojson }}
24-
</script>
25-
<script src="{{page_config['fullStaticUrl'] | e}}/bundle.js" main="index"></script>
26-
27-
<script type="text/javascript">
28-
/* Remove token from URL. */
29-
(function () {
30-
var parsedUrl = new URL(window.location.href);
31-
if (parsedUrl.searchParams.get('token')) {
32-
parsedUrl.searchParams.delete('token');
33-
window.history.replaceState({ }, '', parsedUrl.href);
34-
}
35-
})();
36-
</script>
37-
38-
</body>
39-
</html>
1+
<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>{{page_config['appName'] | e}} - Edit</title>{% block favicon %}<link rel="icon" type="image/x-icon" href="{{ base_url | escape }}static/favicons/favicon-file.ico" class="favicon"/>{% endblock %}<script defer="defer" src="{{page_config.fullStaticUrl}}/main.a4b72be68233e26a3717.js?v=a4b72be68233e26a3717"></script></head><body class="jp-ThemedContainer" data-notebook="edit">{# Copy so we do not modify the page_config with updates. #} {% set page_config_full = page_config.copy() %} {# Set a dummy variable - we just want the side effect of the update. #} {% set _ = page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %} {# Sentinel value to say that we are on the tree page #} {% set _ = page_config_full.update(notebookPage='edit') %}<script id="jupyter-config-data" type="application/json">{{ page_config_full | tojson }}</script><script>/* Remove token from URL. */
2+
(function () {
3+
var parsedUrl = new URL(window.location.href);
4+
if (parsedUrl.searchParams.get('token')) {
5+
parsedUrl.searchParams.delete('token');
6+
window.history.replaceState({}, '', parsedUrl.href);
7+
}
8+
})();</script></body></html>

notebook/templates/edit_template.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>{{page_config['appName'] | e}} - Edit</title>
7+
{% block favicon %}
8+
<link
9+
rel="icon"
10+
type="image/x-icon"
11+
href="{{ base_url | escape }}static/favicons/favicon-file.ico"
12+
class="favicon"
13+
/>
14+
{% endblock %}
15+
</head>
16+
<body class="jp-ThemedContainer" data-notebook="edit">
17+
{# Copy so we do not modify the page_config with updates. #} {% set
18+
page_config_full = page_config.copy() %} {# Set a dummy variable - we just
19+
want the side effect of the update. #} {% set _ =
20+
page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %} {# Sentinel value
21+
to say that we are on the tree page #} {% set _ =
22+
page_config_full.update(notebookPage='edit') %}
23+
24+
<script id="jupyter-config-data" type="application/json">
25+
{{ page_config_full | tojson }}
26+
</script>
27+
28+
<script type="text/javascript">
29+
/* Remove token from URL. */
30+
(function () {
31+
var parsedUrl = new URL(window.location.href);
32+
if (parsedUrl.searchParams.get('token')) {
33+
parsedUrl.searchParams.delete('token');
34+
window.history.replaceState({}, '', parsedUrl.href);
35+
}
36+
})();
37+
</script>
38+
</body>
39+
</html>

notebook/templates/error.html

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,10 @@
1-
<!DOCTYPE html>
2-
<!--
3-
Copyright (c) Jupyter Development Team.
4-
Distributed under the terms of the Modified BSD License.
5-
-->
6-
<html>
7-
8-
<head>
9-
<meta charset="utf-8">
10-
11-
<title>{% block title %}{{page_title | e}}{% endblock %}</title>
12-
13-
{% block favicon %}<link rel="shortcut icon" type="image/x-icon" href="/static/favicons/favicon.ico">{% endblock %}
14-
15-
</head>
16-
17-
<body class="jp-ThemedContainer">
18-
19-
{% block stylesheet %}
20-
<style type="text/css">
21-
/* disable initial hide */
1+
<!doctype html><html><head><meta charset="utf-8"><title>{% block title %}{{page_title | e}}{% endblock %}</title>{% block favicon %}<link rel="shortcut icon" type="image/x-icon" href="/static/favicons/favicon.ico">{% endblock %}<script defer="defer" src="{{page_config.fullStaticUrl}}/main.a4b72be68233e26a3717.js?v=a4b72be68233e26a3717"></script></head><body class="jp-ThemedContainer">{% block stylesheet %}<style>/* disable initial hide */
222
div#header, div#site {
233
display: block;
24-
}
25-
</style>
26-
{% endblock %}
27-
{% block site %}
28-
29-
<div class="error">
30-
{% block h1_error %}
31-
<h1>{{status_code | e}} : {{status_message | e}}</h1>
32-
{% endblock h1_error %}
33-
{% block error_detail %}
34-
{% if message %}
35-
<p>The error was:</p>
36-
<div class="traceback-wrapper">
37-
<pre class="traceback">{{message | e}}</pre>
38-
</div>
39-
{% endif %}
40-
{% endblock %}
41-
</header>
42-
43-
{% endblock %}
44-
45-
{% block script %}
46-
<script type='text/javascript'>
47-
window.onload = function () {
4+
}</style>{% endblock %} {% block site %}<div class="error">{% block h1_error %}<h1>{{status_code | e}} : {{status_message | e}}</h1>{% endblock h1_error %} {% block error_detail %} {% if message %}<p>The error was:</p><div class="traceback-wrapper"><pre class="traceback">{{message | e}}</pre></div>{% endif %} {% endblock %}{% endblock %} {% block script %}<script>window.onload = function () {
485
var tb = document.getElementsByClassName('traceback')[0];
496
tb.scrollTop = tb.scrollHeight;
507
{% if message %}
518
console.error("{{message | e}}")
529
{% endif %}
53-
};
54-
</script>
55-
{% endblock script %}
56-
57-
</body>
58-
59-
</html>
10+
};</script>{% endblock script %}</div></body></html>

0 commit comments

Comments
 (0)