Skip to content

Commit

Permalink
Ensure posthtml loads env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfdsilva committed Dec 13, 2021
1 parent c11d69d commit 4f52228
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions posthtml.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
// https://github.com/parcel-bundler/parcel/issues/1209#issuecomment-942927265
const dotenv = require('dotenv');

const NODE_ENV = process.env.NODE_ENV;

const dotenvFiles = [
'.env',
// Don't include `.env.local` for `test` environment
// since normally you expect tests to produce the same
// results for everyone
NODE_ENV === 'test' ? null : '.env.local',
`.env.${NODE_ENV}`,
`.env.${NODE_ENV}.local`
].filter(Boolean);

const env = {};

for (let dotenvFile of dotenvFiles) {
const config = dotenv.config({ path: dotenvFile });
if (config.parsed) {
Object.assign(env, config.parsed);
}
}

module.exports = {
plugins: {
'posthtml-expressions': {
Expand Down

0 comments on commit 4f52228

Please sign in to comment.