Skip to content

Commit 0fbc180

Browse files
committed
Clarify build output & Vue example
1 parent a5c6efd commit 0fbc180

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ Usage
1010

1111
🚧 **Work in progress** 🚧
1212

13-
A Heroku app uses this buildpack + an [npm module](https://github.com/mars/heroku-js-runtime-env).
13+
A Heroku app uses this buildpack + an [npm module](https://github.com/mars/heroku-js-runtime-env).
14+
15+
`RUNTIME_JS_`-prefixed environment variables will be made available in the running Heroku app via npm module [heroku-js-runtime-env](https://github.com/mars/heroku-js-runtime-env).
1416

1517
### with Vue
1618

19+
⚠️ Vue's `npm run dev` mode does pass arbitrary env vars instead requiring settings in `config/dev.env.js`. So, dev mode seems to be broken. (Help?)
20+
1721
✏️ *Replace `$APP_NAME` with your app's unique name.*
1822

1923
```bash
@@ -25,20 +29,29 @@ git add .
2529
git commit -m '🌱 create Vue app'
2630
heroku create $APP_NAME
2731
heroku buildpacks:add https://github.com/mars/heroku-js-runtime-env-buildpack
32+
heroku config:set JS_RUNTIME_TARGET_BUNDLE=/app/dist/static/js/vendor.*.js
2833
heroku buildpacks:add heroku/nodejs
2934
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static
3035

3136
# Serve it with static site buildpack
3237
echo '{ "root": "dist/" }' > static.json
3338
git add static.json
3439
git commit -m 'Serve it with static site buildpack'
40+
```
3541

36-
# Add Heroku build hook to `package.json`
42+
Add Heroku build hook to `package.json`. Merge the following `"heroku-postbuild"` property into the existing `"scripts"` section:
43+
44+
```json
3745
{
3846
"scripts": {
3947
"heroku-postbuild": "npm run build"
4048
}
4149
}
50+
```
51+
52+
Then, commit this change:
53+
54+
```
4255
git add package.json
4356
git commit -m 'Add Heroku build hook to `package.json`'
4457
```
@@ -61,6 +74,23 @@ export default {
6174
</script>
6275
```
6376

77+
Then, commit this code & deploy the app:
78+
79+
```bash
80+
git add src/components/HelloWorld.vue
81+
git commit -m 'Implement runtimeEnv() in a component'
82+
git push heroku master
83+
84+
heroku open
85+
```
86+
87+
Once deployed, you can set the `RUNTIME_JS_MESSAGE` var to see the new value take effect immediately after the app restarts:
88+
89+
```bash
90+
heroku config:set JS_RUNTIME_MESSAGE=🌈
91+
heroku open
92+
```
93+
6494
Background
6595
-----------
6696
Normally javascript apps are compiled into a bundle before being deployed. During this build phase, environment variables may be embedded in the javascript bundle, such as with [Webpack DefinePlugin](https://webpack.github.io/docs/list-of-plugins.html#defineplugin).

bin/compile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,21 @@ CACHE_DIR=$2
1515
ENV_DIR=$3
1616
BP_DIR=`cd $(dirname $0); cd ..; pwd`
1717

18-
echo '-----> Enabling runtime environment variables'
1918
cd $BUILD_DIR
2019

2120
# The following destination files are explicit dependencies in
2221
# .profile.d/inject_js_runtime_env.sh
2322
#
2423
# Keep any path or name changes in-sync.
2524

25+
echo " installing /app/.heroku-js-runtime-env/injectable_env.rb"
2626
lib_dir="$BUILD_DIR/.heroku-js-runtime-env"
2727
mkdir -p "$lib_dir"
2828
cp "$BP_DIR/lib/injectable_env.rb" "$lib_dir/"
29-
echo " installed /app/.heroku-js-runtime-env/injectable_env.rb"
3029

30+
echo " installing /app/.profile.d/zzzzz_inject_js_runtime_env.sh"
3131
profile_d_dir="$BUILD_DIR/.profile.d"
3232
mkdir -p "$profile_d_dir"
3333
# Prepend "zzzzz_" to force sort so it's the last profile script to run.
3434
# This helps to it to see env changes made by other profile scripts.
3535
cp "$BP_DIR/.profile.d/inject_js_runtime_env.sh" "$profile_d_dir/zzzzz_inject_js_runtime_env.sh"
36-
echo " installed /app/.profile.d/zzzzz_inject_js_runtime_env.sh"

0 commit comments

Comments
 (0)