Skip to content

Commit fedf8ec

Browse files
authored
feature: Vite dev server integration (part 2) (#5342)
* feature: Vite automatic entry point detection * feature: use Vite's actual dev server * feature: enable automatic Vite entry point detection * fix: add templates to build-js step in Dockerfile * fix: run cypress on dotrun in production mode * fix: add all aliases for localhost to Vite CORS origin * fix: Vite dev server listen on all hosts * fix: update docs to mention dotrun port issue on macOS and Windows
1 parent 66215bd commit fedf8ec

19 files changed

Lines changed: 94 additions & 40 deletions

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565

6666
- name: Run dotrun
6767
run: |
68-
dotrun &
68+
dotrun --env ENVIRONMENT="prod" serve &
6969
curl --head --fail --retry-delay 3 --retry 30 --retry-connrefused http://localhost:8004
7070
# END copy of the run-dotrun job
7171

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ RUN yarn run build-css
2929
FROM yarn-dependencies AS build-js
3030
ADD static/js static/js
3131
ADD vite.config.js .
32-
ADD vite.config.entry.js .
3332
ADD tsconfig.json .
3433
ADD babel.config.json .
34+
ADD templates .
3535
RUN yarn install
3636
RUN yarn run build-js
3737

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ dotrun
3434

3535
Once the server has started, you can visit `http://127.0.0.1:8004` in your browser. You stop the server using `<ctrl>+c`.
3636

37+
> If you're running dotrun on macOS or Windows, you will have to use a different command to launch dotrun with an additional argument in order to get JavaScript code working:
38+
```bash
39+
dotrun -p 5004:5004
40+
```
41+
3742
For more detailed local development instructions, see [HACKING.md](HACKING.md).
3843

3944
## Brand stores

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"start": "yarn run build && concurrently --raw 'yarn run watch-scss' 'yarn run watch-js' 'yarn run serve'",
2020
"watch": "watch -p 'static/sass/**/*.scss' -p 'static/js/**/*.js' -c 'yarn run build'",
2121
"watch-scss": "watch -p 'static/sass/**/*.scss' -c 'yarn run build-css'",
22-
"watch-js": "vite build --watch",
22+
"watch-js": "vite",
2323
"clean": "rm -rf node_modules yarn-error.log css static/js/modules static/css *.log *.sqlite _site/ build/ .jekyll-metadata .bundle cache.tmp",
2424
"percy": "node_modules/.bin/percy snapshot snapshots.yml"
2525
},

templates/_base-layout.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
<link rel="stylesheet" href="{{ static_url('css/styles.css') }}" />
2525

26+
{% if IS_DEVELOPMENT %}
27+
{{ vite_dev_tools() }}
28+
{% endif %}
29+
2630
{% block scripts_modules %}{% endblock %}
2731
<script src="{{ static_url('js/modules/raven.min.js') }}" defer></script>
2832
<script>
@@ -37,7 +41,7 @@
3741
});
3842
</script>
3943

40-
<script type="module" src="{{ static_url('js/dist/vite/base.js') }}" defer></script>
44+
{{ vite_import('static/js/base/base.ts') }}
4145
{% block scripts_includes %}{% endblock %}
4246
<script src="https://assets.ubuntu.com/v1/703e23c9-lazysizes+noscript+native-loading.5.1.2.min.js" defer></script>
4347

@@ -79,11 +83,11 @@
7983

8084
{% block header %}
8185
<!-- JS that is needed right away -->
82-
<script type="module" src="{{ static_url('js/dist/vite/cookie-policy.js') }}"></script>
86+
{{ vite_import('static/js/base/cookie-policy.ts') }}
8387

8488
{% from "_header_macros.html" import header %}
8589
{% if show_header != False %}
86-
<script type="module" src="{{ static_url('js/dist/vite/global-nav.js') }}"></script>
90+
{{ vite_import('static/js/base/global-nav.ts') }}
8791
{% from "_header_macros.html" import header %}
8892
{{ header() }}
8993
{% endif %}

templates/about/listing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,5 @@ <h3 class="p-heading--2">Get featured</h3>
185185
</div>
186186
</section>
187187

188-
<script type="module" src="{{ static_url('js/dist/vite/about-listing.js') }}" defer></script>
188+
{{ vite_import('static/js/public/about/listing.ts') }}
189189
{% endblock %}

templates/about/publish.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ <h3 class="p-heading--5">Trave CI, Circle CI and GitHub Actions are all supporte
192192
{% endblock %}
193193

194194
{% block scripts_includes %}
195-
<script type="module" src="{{ static_url('js/dist/vite/about.js') }}" defer></script>
195+
{{ vite_import('static/js/public/about/index.ts') }}
196196
{% endblock %}
197197

198198
{% block scripts %}

templates/admin/admin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
window.SENTRY_DSN = "{{ SENTRY_DSN }}";
1111
window.API_URL = "{{ api_url }}";
1212
</script>
13-
<script type="module" src="{{ static_url('js/dist/vite/brand-store.js') }}"></script>
13+
{{ vite_import('static/js/publisher/brand-store.tsx') }}
1414
{% endblock %}

templates/blog/article.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h5>
110110
{% endblock %}
111111

112112
{% block scripts_includes %}
113-
<script type="module" src="{{ static_url('js/dist/vite/blog.js') }}" defer></script>
113+
{{ vite_import('static/js/public/blog.ts') }}
114114
{% endblock %}
115115

116116
{% block scripts %}

templates/blog/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ <h5 class="p-notification__title">Success</h5>
144144
{% endblock %}
145145

146146
{% block scripts_includes %}
147-
<script type="module" src="{{ static_url('js/dist/vite/blog.js') }}" defer></script>
147+
{{ vite_import('static/js/public/blog.ts') }}
148148
{% endblock %}
149149

150150
{% block scripts %}

0 commit comments

Comments
 (0)