Skip to content

Commit

Permalink
Apply NODE_ENV development for react-based projects
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Dec 14, 2024
1 parent 126f504 commit 76e10e5
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 4 deletions.
2 changes: 1 addition & 1 deletion code/builders/builder-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"url": "^0.11.0",
"util": "^0.12.4",
"util-deprecate": "^1.0.2",
"webpack": "5",
"webpack": "^5.97.1",
"webpack-dev-middleware": "^6.1.2",
"webpack-hot-middleware": "^2.25.1",
"webpack-virtual-modules": "^0.6.0"
Expand Down
5 changes: 5 additions & 0 deletions code/frameworks/experimental-nextjs-vite/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ export const viteFinal: StorybookConfigVite['viteFinal'] = async (config, option
const nextDir = nextConfigPath ? path.dirname(nextConfigPath) : undefined;
plugins.push(vitePluginStorybookNextjs({ dir: nextDir }));

reactConfig.define = {
...reactConfig.define,
'process.env.NODE_ENV': JSON.stringify('development'),
};

return reactConfig;
};
1 change: 1 addition & 0 deletions code/frameworks/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const setupRuntimeConfig = async (
serverRuntimeConfig: {},
publicRuntimeConfig: nextConfig.publicRuntimeConfig,
}),
'process.env.NODE_ENV': JSON.stringify('development'),
};

const newNextLinkBehavior = (nextConfig.experimental as any)?.newNextLinkBehavior;
Expand Down
5 changes: 5 additions & 0 deletions code/frameworks/react-vite/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ export const viteFinal: NonNullable<StorybookConfig['viteFinal']> = async (confi
);
}

config.define = {
...config.define,
'process.env.NODE_ENV': JSON.stringify('development'),
};

return config;
};
3 changes: 2 additions & 1 deletion code/frameworks/react-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"@storybook/builder-webpack5": "workspace:*",
"@storybook/preset-react-webpack": "workspace:*",
"@storybook/react": "workspace:*",
"@types/node": "^22.0.0"
"@types/node": "^22.0.0",
"webpack": "^5.97.1"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
Expand Down
9 changes: 9 additions & 0 deletions code/frameworks/react-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { dirname, join } from 'node:path';

import type { PresetProperty } from 'storybook/internal/types';

import webpackDep from 'webpack';

import type { StorybookConfig } from './types';

const getAbsolutePath = <I extends string>(input: I): I =>
Expand Down Expand Up @@ -31,5 +33,12 @@ export const webpack: StorybookConfig['webpack'] = async (config) => {
...config.resolve?.alias,
'@storybook/react': getAbsolutePath('@storybook/react'),
};
config.plugins = [
// @ts-expect-error TODO
...config.plugins,
new webpackDep.DefinePlugin({
NODE_ENV: JSON.stringify('development'),
}),
];
return config;
};
Loading

0 comments on commit 76e10e5

Please sign in to comment.