Skip to content

Commit

Permalink
Add ECMAScript target and easy way to run examples in prod mode
Browse files Browse the repository at this point in the history
Target set to ES2019 which seems to be supported by WPE 2.28.

Fixes #44
  • Loading branch information
frank-weindel committed Oct 6, 2023
1 parent fc0ee7d commit b80c669
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ npm test
# Build API Documentation (builds into ./docs folder)
npm run typedoc
# Launch test examples (includes Build Renderer (watch mode))
# Launch test examples in dev mode (includes Build Renderer (watch mode))
npm start
# Launch test examples in production mode
# IMPORTANT: To run test examples on embedded devices that use older browser versions
# you MUST run the examples in this mode.
npm run prod
```

## Test Examples
Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "concurrently -c \"auto\" \"npm:watch-renderer\" \"npm:dev\"",
"dev": "vite --open",
"build": "vite build",
"preview": "vite preview",
"preview": "vite preview --host",
"watch-renderer": "cd .. && npm run watch"
},
"author": "Frank Weindel",
Expand Down
23 changes: 23 additions & 0 deletions examples/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ import { defineConfig } from 'vite';
import * as path from 'path';
import { importChunkUrl } from '@lightningjs/vite-plugin-import-chunk-url';

/**
* Targeting ES2019 gets us at least to WPE 2.28
*
* Despite setting the target in 3 different places in the Vite config below
* this does not seem to have an effect on the output when running Vite in
* development mode (`npm start`). In order to properly test on embedded devices
* that require the set target, you must run `npm run build` and then serve the
* content via `npm run preview -- --host`.
*
* See the following for any updates on this:
* https://github.com/vitejs/vite/issues/13756#issuecomment-1751085158
*/
const target = 'es2019';

/**
* Vite Config
*/
Expand All @@ -30,7 +44,16 @@ export default defineConfig(({ command, mode, ssrBuild }) => {
worker: {
format: 'es',
},
esbuild: {
target,
},
optimizeDeps: {
esbuildOptions: {
target,
},
},
build: {
target,
minify: false,
sourcemap: true,
outDir: path.resolve(__dirname, 'dist'),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"scripts": {
"start": "cd examples && npm start",
"prod": "npm run build && cd examples && npm run build && npm run preview",
"build": "tsc --build",
"watch": "tsc --build --watch",
"test": "vitest",
Expand Down

0 comments on commit b80c669

Please sign in to comment.