Skip to content

Commit

Permalink
Add version in js chunk file name (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
maudetes committed Apr 18, 2023
1 parent 4b17efc commit d81b3a5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -29,7 +29,7 @@ jobs:
command: |
virtualenv venv
source venv/bin/activate
pip install setuptools==66.1.1
pip install --force-reinstall setuptools==66.1.1
pip install pip-tools
- run:
name: Upgrade udata to latest pypi release if tagged release
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
- Update the login form after Flask-Security and WTForms upgrade [#224](https://github.com/etalab/udata-front/pull/224)
- Align reuse sidebar with image [#234](https://github.com/etalab/udata-front/pull/234)
- Show relative date on dataset and resource cards [#231](https://github.com/etalab/udata-front/pull/231)
- Add version in chunk file names for cache invalidation [#239](https://github.com/etalab/udata-front/pull/239)

## 3.2.1 (2023-03-28)

Expand Down
1 change: 1 addition & 0 deletions bumpr.rc
Expand Up @@ -10,6 +10,7 @@ tests = inv test
publish = inv dist
files =
README.md
package.json

[bump]
unsuffix = true
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "udata-front",
"version": "1.0.0",
"version": "3.2.2.dev",
"description": "Open Data Portal - French customization",
"author": "Etalab",
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions udata_front/theme/__init__.py
Expand Up @@ -30,8 +30,13 @@ def get_current_theme():


@pass_context
def theme_static_with_version(ctx, filename, external=False):
'''Override the default theme static to add cache burst'''
def theme_static_with_version(ctx, filename, external=False, inline_burst=False):
'''
Override the default theme static to add cache burst, ex: [file].js?_=[burst]
If inline_burst is true, burst is not added as a dummy param but in filename directly:
Ex: [file].[burst].js
It is useful for generated chunks that follow this pattern
'''
if current_app.theme_manager.static_folder:
url = assets.cdn_for('_themes.static',
filename=current.identifier + '/' + filename,
Expand All @@ -47,6 +52,9 @@ def theme_static_with_version(ctx, filename, external=False):
burst = time()
else:
burst = current.entrypoint.dist.version
if inline_burst:
url_parts = url.split(".")
return '.'.join(url_parts[:-1] + [str(burst), url_parts[-1]])
return '{url}?_={burst}'.format(url=url, burst=burst)


Expand Down
2 changes: 1 addition & 1 deletion udata_front/theme/gouvfr/templates/raw.html
Expand Up @@ -65,7 +65,7 @@
<script nomodule src="{{ theme_static('js/s.min.js') }}"></script>
<script nomodule src="{{ theme_static('js/vue.esm-browser.prod-legacy.js') }}"></script>
<script nomodule src="{{ theme_static('js/vue-content-loader.es-legacy.js') }}"></script>
<script nomodule src="{{ theme_static('js/_commonjsHelpers-legacy.js') }}"></script>
<script nomodule src="{{ theme_static('js/_commonjsHelpers-legacy.js', inline_burst=True) }}"></script>
<script nomodule src="{{ theme_static('js/polyfills-legacy.js') }}"></script>
<script nomodule src="{{ theme_static('js/index-legacy.js') }}"></script>
{% block extra_js %}{% endblock %}
Expand Down
8 changes: 7 additions & 1 deletion vite.config.js
Expand Up @@ -6,6 +6,12 @@ import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'url'
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'


function get_package_version(){
var pjson = require('./package.json');
return pjson.version
}

// https://vitejs.dev/config/
export default defineConfig({
base: "/_themes/gouvfr/",
Expand Down Expand Up @@ -49,7 +55,7 @@ export default defineConfig({
output: {
dir: "./udata_front/theme/gouvfr/static/",
entryFileNames: `js/[name].js`,
chunkFileNames: `js/[name].js`,
chunkFileNames: `js/[name].${get_package_version()}.js`,
assetFileNames: `assets/[name].[ext]`,
// Provide global variables to use in the UMD build
// for externalized deps
Expand Down

0 comments on commit d81b3a5

Please sign in to comment.