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

Core: Replaced process.env override in DefinePlugin config #15925

Merged
merged 2 commits into from
Sep 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/vue-kitchen-sink/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ if (process.env.NODE_ENV === 'production') {
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
'process.env.NODE_ENV': '"production"',
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
Expand Down
4 changes: 2 additions & 2 deletions lib/builder-webpack4/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import themingPaths from '@storybook/theming/paths';

import {
toRequireContextString,
stringifyEnvs,
stringifyProcessEnvs,
es6Transpiler,
interpolate,
nodeModulesPaths,
Expand Down Expand Up @@ -178,7 +178,7 @@ export default async ({
template,
}),
new DefinePlugin({
'process.env': stringifyEnvs(envs),
...stringifyProcessEnvs(envs),
NODE_ENV: JSON.stringify(envs.NODE_ENV),
}),
isProd ? null : new WatchMissingNodeModulesPlugin(nodeModulesPaths),
Expand Down
4 changes: 2 additions & 2 deletions lib/builder-webpack5/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import themingPaths from '@storybook/theming/paths';
import {
toRequireContextString,
es6Transpiler,
stringifyEnvs,
stringifyProcessEnvs,
nodeModulesPaths,
interpolate,
Options,
Expand Down Expand Up @@ -178,7 +178,7 @@ export default async ({
template,
}),
new DefinePlugin({
'process.env': stringifyEnvs(envs),
...stringifyProcessEnvs(envs),
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
}),
isProd ? null : new WatchMissingNodeModulesPlugin(nodeModulesPaths),
Expand Down
13 changes: 13 additions & 0 deletions lib/core-common/src/utils/envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,21 @@ export function loadEnvs(
};
}

/** @deprecated use `stringifyProcessEnvs` */
export const stringifyEnvs = (raw: Record<string, string>): Record<string, string> =>
Object.entries(raw).reduce<Record<string, string>>((acc, [key, value]) => {
acc[key] = JSON.stringify(value);
return acc;
}, {});

export const stringifyProcessEnvs = (raw: Record<string, string>): Record<string, string> =>
Object.entries(raw).reduce<Record<string, string>>(
(acc, [key, value]) => {
acc[`process.env.${key}`] = JSON.stringify(value);
return acc;
},
{
// Default fallback
'process.env.XSTORYBOOK_EXAMPLE_APP': '""',
}
);
4 changes: 2 additions & 2 deletions lib/manager-webpack4/src/presets/manager-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import readPackage from 'read-pkg-up';
import {
loadManagerOrAddonsFile,
resolvePathInStorybookCache,
stringifyEnvs,
stringifyProcessEnvs,
es6Transpiler,
getManagerHeadTemplate,
getManagerMainTemplate,
Expand Down Expand Up @@ -113,7 +113,7 @@ export async function managerWebpack(
(new Dotenv({ silent: true }) as any) as WebpackPluginInstance,
// graphql sources check process variable
new DefinePlugin({
'process.env': stringifyEnvs(envs),
...stringifyProcessEnvs(envs),
NODE_ENV: JSON.stringify(envs.NODE_ENV),
}) as WebpackPluginInstance,
// isProd &&
Expand Down
4 changes: 2 additions & 2 deletions lib/manager-webpack5/src/presets/manager-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import readPackage from 'read-pkg-up';
import {
loadManagerOrAddonsFile,
resolvePathInStorybookCache,
stringifyEnvs,
stringifyProcessEnvs,
es6Transpiler,
getManagerHeadTemplate,
getManagerMainTemplate,
Expand Down Expand Up @@ -113,7 +113,7 @@ export async function managerWebpack(
hasDotenv() ? new Dotenv({ silent: true }) : null,
// graphql sources check process variable
new DefinePlugin({
'process.env': stringifyEnvs(envs),
...stringifyProcessEnvs(envs),
NODE_ENV: JSON.stringify(envs.NODE_ENV),
}) as WebpackPluginInstance,
// isProd &&
Expand Down