Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

chore(webpack): build dotenv config path #359

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ module.exports = {
'scope-enum': [
2,
'always',
['workspace', 'guardoni', 'ycai', 'taboule', 'tktrex', 'yttrex'],
[
'workspace',
'shared',
'taboule',
'backend',
'guardoni',
'ycai',
'tktrex',
],
],
'type-enum': [
2,
Expand Down
24 changes: 17 additions & 7 deletions packages/shared/src/webpack/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import D from 'debug';
import dotenv from 'dotenv';
import { pipe } from 'fp-ts/lib/function';
import * as R from 'fp-ts/lib/Record';
Expand Down Expand Up @@ -52,19 +53,28 @@ interface GetConfigParams<E extends t.Props> {
const getConfig = <E extends t.Props>(
opts: GetConfigParams<E>
): WebpackConfig => {
const mode =
process.env.NODE_ENV === 'production' ? 'production' : 'development';

const DOTENV_CONFIG_PATH =
process.env.DOTENV_CONFIG_PATH ??
path.resolve(opts.cwd, mode === 'production' ? '.env' : '.env.development');

// const tsConfigFile = path.resolve(opts.cwd, './tsconfig.json');
path.resolve(
opts.cwd,
process.env.NODE_ENV === 'production' ? '.env' : '.env.development'
);

webpackLogger.debug(`DOTENV_CONFIG_PATH %s`, DOTENV_CONFIG_PATH);
// eslint-disable-next-line
console.log(
`Reading process.env from %s for %s (%s)`,
DOTENV_CONFIG_PATH,
path.basename(opts.cwd),
Object.keys(opts.entry).join(', ')
);

dotenv.config({ path: DOTENV_CONFIG_PATH });

D.enable(process.env.DEBUG ?? '');

const mode =
process.env.NODE_ENV === 'production' ? 'production' : 'development';

const buildENV = pipe(
{
BUNDLE_TARGET: 'chrome',
Expand Down