Skip to content

Commit

Permalink
Override javascript base url at runtime (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
bameyrick authored Apr 4, 2019
1 parent aa166f8 commit 513113c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/js/public-path-override.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const baseURL = window.ONS_assets_base_URL;

if (baseURL) {
__webpack_public_path__ = baseURL;
}
3 changes: 3 additions & 0 deletions src/styles/page-template/_template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
{% endblock %}
{% block bodyEnd %}{% endblock %}
</div>
{% if data.version %}
<script>window.ONS_assets_base_URL = "/{{ data.version }}/" </script>
{% endif %}
<script type="module" src="{{ "/" + data.version if data.version }}{{ "https://cdn.ons.gov.uk/sdc/" + page.cdn if page.cdn }}/scripts/bundle.js"></script>
<script nomodule src="{{ "/" + data.version if data.version }}{{ "https://cdn.ons.gov.uk/sdc/" + page.cdn if page.cdn }}/scripts/bundle.es5.js"></script>
<script>document.documentElement.className = document.documentElement.className.replace("no-js","has-js")</script>
Expand Down
3 changes: 1 addition & 2 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ const core = {

const jsCore = merge(core, {
entry: {
'scripts/bundle': ['./js/polyfills/index.js', './js/index.js'],
'scripts/bundle': ['./js/public-path-override.js', './js/polyfills/index.js', './js/index.js'],
'scripts/patternlib': ['./js/patternlib/index.js']
},

output: {
publicPath: '/',
chunkFilename: 'scripts/[name].js'
},

Expand Down

0 comments on commit 513113c

Please sign in to comment.