Skip to content

Commit f223bcd

Browse files
author
xhlulu
committed
Extend _js_dist in __init__.py with async chunks
1 parent 493b37d commit f223bcd

File tree

1 file changed

+59
-19
lines changed
  • {{cookiecutter.project_shortname}}/{{cookiecutter.project_shortname}}

1 file changed

+59
-19
lines changed

{{cookiecutter.project_shortname}}/{{cookiecutter.project_shortname}}/__init__.py

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,67 @@
2828

2929
_this_module = _sys.modules[__name__]
3030

31-
32-
_js_dist = [
33-
{
34-
'relative_package_path': '{{cookiecutter.project_shortname}}.min.js',
35-
{% if cookiecutter.publish_on_npm == 'True' -%}
36-
'external_url': 'https://unpkg.com/{0}@{2}/{1}/{1}.min.js'.format(
37-
package_name, __name__, __version__),
38-
{%- endif %}
39-
'namespace': package_name
40-
},
41-
{
42-
'relative_package_path': '{{cookiecutter.project_shortname}}.min.js.map',
43-
{% if cookiecutter.publish_on_npm == 'True' -%}
44-
'external_url': 'https://unpkg.com/{0}@{2}/{1}/{1}.min.js.map'.format(
45-
package_name, __name__, __version__),
46-
{%- endif %}
47-
'namespace': package_name,
48-
'dynamic': True
49-
}
31+
async_resources = [
32+
{%- if cookiecutter.use_async == "True" -%}
33+
"{{cookiecutter.component_name}}",
34+
{%- endif -%}
5035
]
5136

37+
_js_dist = []
38+
39+
_js_dist.extend(
40+
[
41+
{
42+
"relative_package_path": "async-{}.js".format(async_resource),
43+
"external_url": (
44+
"https://unpkg.com/{0}@{2}"
45+
"/{1}/async-{3}.js"
46+
).format(package_name, __name__, __version__, async_resource),
47+
"namespace": package_name,
48+
"async": True,
49+
}
50+
for async_resource in async_resources
51+
]
52+
)
53+
54+
# TODO: Figure out if unpkg link works
55+
_js_dist.extend(
56+
[
57+
{
58+
"relative_package_path": "async-{}.js.map".format(async_resource),
59+
"external_url": (
60+
"https://unpkg.com/{0}@{2}"
61+
"/{1}/async-{3}.js.map"
62+
).format(package_name, __name__, __version__, async_resource),
63+
"namespace": package_name,
64+
"dynamic": True,
65+
}
66+
for async_resource in async_resources
67+
]
68+
)
69+
70+
_js_dist.extend(
71+
[
72+
{
73+
'relative_package_path': '{{cookiecutter.project_shortname}}.min.js',
74+
{% if cookiecutter.publish_on_npm == 'True' -%}
75+
'external_url': 'https://unpkg.com/{0}@{2}/{1}/{1}.min.js'.format(
76+
package_name, __name__, __version__),
77+
{%- endif %}
78+
'namespace': package_name
79+
},
80+
{
81+
'relative_package_path': '{{cookiecutter.project_shortname}}.min.js.map',
82+
{% if cookiecutter.publish_on_npm == 'True' -%}
83+
'external_url': 'https://unpkg.com/{0}@{2}/{1}/{1}.min.js.map'.format(
84+
package_name, __name__, __version__),
85+
{%- endif %}
86+
'namespace': package_name,
87+
'dynamic': True
88+
}
89+
]
90+
)
91+
5292
_css_dist = []
5393

5494

0 commit comments

Comments
 (0)