Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

environment variables in Win #2

Closed
jshwlkr opened this issue Feb 20, 2019 · 3 comments
Closed

environment variables in Win #2

jshwlkr opened this issue Feb 20, 2019 · 3 comments

Comments

@jshwlkr
Copy link

jshwlkr commented Feb 20, 2019

This particular method of passing environment variables doesn't work in Windows.
https://stackoverflow.com/questions/25112510/how-to-set-environment-variables-from-within-package-json-node-js

@d2s
Copy link

d2s commented Feb 20, 2019

Steps to fix the issue

npm install --save-dev cross-env

Modify package.json npm scripts

Modify dev npm script from:

    "dev": "ELEVENTY_ENV=development eleventy --config=eleventy.config.js --serve & gulp dev",

to:

    "dev": "cross-env ELEVENTY_ENV=development eleventy --config=eleventy.config.js --serve  npm run gulp",
    "gulp": "cross-env-shell gulp dev",

This should fix the issue for the people who use Windows as their web development environment.

TODO: I haven't tested how the updated npm script works on Linux or macOS, so you might want to try the updated config on those before applying the change to the public Git repository.

More details

@d2s
Copy link

d2s commented Feb 20, 2019

Found a better way to solve the issue.

Steps to fix the issue

Install new dependencies for managing parallel & sequential tasks (npm-run-all) and for managing environmental variables on multiple platforms (cross-env).

npm install npm-run-all cross-env --only=dev

Modify package.json npm scripts

Modify package.json to make npm scripts have more clearly split tasks:

    "dev": "npm-run-all --parallel dev:eleventy dev:gulp",
    "dev:eleventy": "cross-env ELEVENTY_ENV=development eleventy --config=eleventy.config.js --serve",
    "dev:gulp": "cross-env-shell gulp dev",
    "build": "npm-run-all --parallel build:gulp build:eleventy",
    "build:gulp": "gulp build",
    "build:eleventy": "eleventy --config=eleventy.config.js",

This should fix the issue for the people who use Windows as their web development environment.

TODO: I haven't tested how the updated npm script works on Linux or macOS, so you might want to try the updated config on those before applying the change to the public Git repository.

npm-run-all

cross-env

Bonus: Add way to preview the built site

Install serve package.

npm install serve --only=dev

Modify package.json to add npm run serve task.

    "serve": "serve dist"

@atomtigerzoo
Copy link

Thank you for the workaround on Windows, but I spotted a bug in the line:

"dev:gulp": "cross-env-shell gulp dev",

It should be:

"dev:gulp": "cross-env-shell gulp",

because there is no dev task, only the default in gulp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants