@thepassle/app-tools 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/env/README.md +48 -0
- package/env/dev.js +8 -1
- package/env/prod.js +8 -1
- package/package.json +1 -1
- package/types/env/dev.d.ts +5 -0
- package/types/env/prod.d.ts +5 -0
package/env/README.md
CHANGED
|
@@ -20,6 +20,54 @@ if (PROD) {
|
|
|
20
20
|
}
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
OR
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { ENV } from '@thepassle/app-tools/env.js';
|
|
27
|
+
|
|
28
|
+
if (ENV === 'dev') {
|
|
29
|
+
console.log('Running in dev mode');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (ENV === 'prod') {
|
|
33
|
+
console.log('Running in prod mode');
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Custom Env Modes
|
|
38
|
+
|
|
39
|
+
In certain situations you might want to set your own env mode.
|
|
40
|
+
|
|
41
|
+
Demos that should use "just" json files instead of a full api server might be a good use case for it.
|
|
42
|
+
Here is an example using it in combination with the [Api Module](../api/README.md).
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import { ENV } from '@thepassle/app-tools/env.js';
|
|
46
|
+
|
|
47
|
+
const baseURLs = {
|
|
48
|
+
'prod': 'https://api.domain.com', // prod api server
|
|
49
|
+
'dev': 'http://localhost:8888', // local api server
|
|
50
|
+
'dev-static': 'http://localhost:8000' // demos using "just" json files
|
|
51
|
+
}
|
|
52
|
+
const typedEnv = /** @type {keyof baseURLs} */ (ENV);
|
|
53
|
+
|
|
54
|
+
export const api = new Api({
|
|
55
|
+
baseURL: baseURLs[typedEnv],
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Then in your HTML demo files you can set these special env values.
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<my-el api-endpoint="recommendation.json"></my-el>
|
|
63
|
+
|
|
64
|
+
<script type="module">
|
|
65
|
+
import { ENV, setEnv } from '@thepassle/app-tools/env.js';
|
|
66
|
+
setEnv('dev-static');
|
|
67
|
+
import '../my-el.js';
|
|
68
|
+
</script>
|
|
69
|
+
```
|
|
70
|
+
|
|
23
71
|
When resolving imports, Node will look for keys in the package export to figure out which file to use. For example "default", "import", or "require".
|
|
24
72
|
|
|
25
73
|
Tools however can use custom keys here as well, like "types", "browser", "development", or "production". Depending on what kind of import it is, and which environment (dev/prod) tools (like bundlers or dev servers) can resolve/distinguish between which file should actually be used.
|
package/env/dev.js
CHANGED
package/env/prod.js
CHANGED
package/package.json
CHANGED
package/types/env/dev.d.ts
CHANGED