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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cannot load the advanced configurations #239

Merged
merged 1 commit into from
Jan 23, 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
42 changes: 24 additions & 18 deletions webpack/plugins/dotenv-webpack-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ const NODE_ENV = process.env.NODE_ENV;

const envPath = path.resolve(process.cwd(), `.env`);

const loadEnv = (...paths) => {
const envFiles = [
`${envPath}.${NODE_ENV}.local`,
/**
* Don't include `.env.local` for `test` environment
* since normally you expect tests to produce the same
* results for everyone
*/
NODE_ENV !== 'test' && `${envPath}.local`,
`${envPath}.${NODE_ENV}`,
envPath,
...paths,
].filter(Boolean);

envFiles.forEach((file) => {
if (fs.existsSync(file)) {
dotenvExpand(dotenv.config({ path: file }));
}
});
};
exports.loadEnv = loadEnv;

class DotenvWebpackPlugin {
/**
* @param {Object} [options]
Expand All @@ -22,23 +44,7 @@ class DotenvWebpackPlugin {

this.options = { ...options };

const envFiles = [
`${envPath}.${NODE_ENV}.local`,
/**
* Don't include `.env.local` for `test` environment
* since normally you expect tests to produce the same
* results for everyone
*/
NODE_ENV !== 'test' && `${envPath}.local`,
`${envPath}.${NODE_ENV}`,
this.options.path || envPath,
].filter(Boolean);

envFiles.forEach((file) => {
if (fs.existsSync(file)) {
dotenvExpand(dotenv.config({ path: file }));
}
});
loadEnv(this.options.path);
}

/**
Expand Down Expand Up @@ -84,4 +90,4 @@ class DotenvWebpackPlugin {
}
}

module.exports = DotenvWebpackPlugin;
exports.DotenvWebpackPlugin = DotenvWebpackPlugin;
4 changes: 3 additions & 1 deletion webpack/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const ESLintPlugin = require('eslint-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const eslintFormatter = require('react-dev-utils/eslintFormatter');

const DotenvWebpackPlugin = require('./plugins/dotenv-webpack-plugin');
const { DotenvWebpackPlugin, loadEnv } = require('./plugins/dotenv-webpack-plugin');

// load default env
loadEnv();
const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';

Expand Down