Skip to content

Commit 9c47cda

Browse files
Use Vite for build (#1218)
1 parent cf63c1d commit 9c47cda

File tree

20 files changed

+2991
-1285
lines changed

20 files changed

+2991
-1285
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ npm-debug.log*
2727
!/.nginx/.gitkeep
2828

2929
/.eslintcache
30+
public/index.html
3031
test-results
3132
playwright-report

Procfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
vue: vue-cli-service build --mode development --watch
1+
vite: vite dev
2+
build: vite build --mode development --watch
23
nginx: nginx -c "$PWD/main.nginx.conf" -p "$PWD"

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ Follow these instructions to run ODK Central Frontend in development. For deploy
4444

4545
First, run ODK Central Backend.
4646

47-
Next, build ODK Central Frontend files for development by running `npm run dev`. The files will be outputted to `dist/`. As you update the source code, the files will be automatically rebuilt. `npm run dev` will also start NGINX, which will serve the files. NGINX effectively places ODK Central Frontend and ODK Central Backend at the same origin, avoiding cross-origin requests.
48-
49-
ODK Central Frontend will be available on port 8989.
47+
Next, run ODK Central Frontend in development by running `npm run dev`. This will start a Vite dev server. ODK Central Frontend will be available on port 8989. `npm run dev` will also start NGINX, which will forward requests to ODK Central Backend.
5048

5149
ODK Central Frontend communicates with ODK Central Backend in part using a session cookie. The cookie is `Secure`, but will be sent over HTTP on localhost. ODK Central Frontend also interacts with data collection clients and with services:
5250

5351
- To upload an XLSForm, run [pyxform-http](https://github.com/getodk/pyxform-http). ODK Central Frontend communicates with pyxform-http through ODK Central Backend.
5452
- You can use ODK Collect to scan an app user QR code, download a form, and submit data. One option to do so is to use [`ngrok`](https://ngrok.com/download). ODK Central Frontend is available on port 8989, so you can run `ngrok http 8989` to expose a temporary HTTPS URL that you can use. Within ODK Central Backend, you will also need to set the `default.env.domain` property in [`config/default.json`](https://github.com/getodk/central-backend/blob/master/config/default.json) to the HTTPS URL, then restart ODK Central Backend if it is already running.
5553
- Enketo is a web form engine used to show form previews and allow for web-based data entry. Please see our [instructions](/docs/enketo.md) for optionally setting up an Enketo server for use in _development_ (it is already included in the production ODK Central stack).
5654

55+
### Running without HMR
56+
57+
If you run `npm run dev`, open ODK Central Frontend in a browser, then update the source code, the page will refresh automatically to reflect the new code. This is called hot module replacement (HMR). To develop without HMR, run `npm run dev:build`. Instead of running a Vite dev server, this builds ODK Central Frontend for development. It outputs files to `dist/`, which NGINX will serve on port 8686. (There will be nothing on port 8989.) If you update the source, the files will be rebuilt automatically, but the page will not be refreshed: you can choose when to refresh the page. Note that `npm run dev:build` is much slower than `npm run dev`.
58+
5759
## Deploying to production
5860

59-
To build ODK Central Frontend files for production with minification, run `npm run build`. The files will be outputted to `dist/`. For more details on this command, see the [documentation](https://cli.vuejs.org/) for Vue CLI.
61+
To build ODK Central Frontend files for production with minification, run `npm run build`. The files will be outputted to `dist/`.
6062

6163
Note that this repository's `main.nginx.conf` is for development only.
6264

public/index.html renamed to index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
<p>Powered by <a href="https://getodk.org">ODK</a>.</p>
2424
</noscript>
2525
<div id="app"></div>
26-
<!-- built files will be auto injected -->
26+
<script type="module" src="/src/main.js"></script>
2727
</body>
2828
</html>

karma.conf.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@ This config is based on:
77
- https://github.com/Nikku/karma-browserify
88
*/
99

10+
// eslint-disable-next-line import/no-unresolved
11+
const VueI18nPlugin = require('@intlify/unplugin-vue-i18n/webpack');
12+
const { resolve } = require('node:path');
1013
// eslint-disable-next-line import/extensions
1114
const webpackConfig = require('./node_modules/@vue/cli-service/webpack.config.js');
1215

1316
const { entry, ...webpackConfigForKarma } = webpackConfig;
17+
webpackConfigForKarma.plugins.push(VueI18nPlugin({
18+
include: resolve(__dirname, './src/locales/**'),
19+
compositionOnly: false,
20+
defaultSFCLang: 'json5',
21+
// `false` doesn't work for some reason. When `false` is specified, Vue I18n
22+
// warns that it's been installed already.
23+
fullInstall: true,
24+
dropMessageCompiler: true
25+
}));
1426
webpackConfigForKarma.devtool = 'inline-source-map';
1527
// See additional warning information.
1628
webpackConfigForKarma.stats = {
@@ -45,6 +57,9 @@ module.exports = (config) => {
4557
browsers: ['ChromeHeadless'],
4658
reporters: ['spec'],
4759
singleRun: true,
60+
client: {
61+
mocha: { grep: process.env.TEST_PATTERN || '.' }
62+
},
4863
customLaunchers: {
4964
ChromeDebugging: {
5065
base: 'Chrome',

main.nginx.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ http {
4747
}
4848

4949
server {
50-
listen 8989;
50+
listen 8686;
5151
server_name localhost;
5252

5353
server_tokens off;
@@ -131,7 +131,11 @@ http {
131131
include ./common-headers.nginx.conf;
132132
return 200 "{}";
133133
}
134+
location /version.txt {
135+
return 404;
136+
}
134137

138+
# Only relevant for `npm run dev:build`, not `npm run dev`.
135139
location / {
136140
root ./dist;
137141
try_files $uri $uri/ /index.html;

0 commit comments

Comments
 (0)