Skip to content

Commit

Permalink
Smaller refactors suggested by @JReinhold
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Feb 7, 2024
1 parent d1f67dc commit b629fa7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions code/builders/builder-vite/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { sanitizeEnvVars } from './envs';
import type { WebpackStatsPlugin } from './plugins';
import type { InlineConfig } from 'vite';
import { logger } from '@storybook/node-logger';
import { hasVitePlugins } from './utils/has-vite-plugins';
import { withoutVitePlugins } from './utils/without-vite-plugins';

function findPlugin(config: InlineConfig, name: string) {
return config.plugins?.find((p) => p && 'name' in p && p.name === name);
Expand Down Expand Up @@ -36,13 +38,15 @@ export async function build(options: Options) {

const finalConfig = await presets.apply('viteFinal', config, options);

const turbosnapPlugin = findPlugin(finalConfig, 'rollup-plugin-turbosnap');
if (turbosnapPlugin) {
logger.warn(`Found 'rollup-plugin-turbosnap' which is now included by default in Storybook 8.`);
const turbosnapPluginName = 'rollup-plugin-turbosnap';
const hasTurbosnapPlugin =
finalConfig.plugins && hasVitePlugins(finalConfig.plugins, [turbosnapPluginName]);
if (hasTurbosnapPlugin) {
logger.warn(`Found '${turbosnapPluginName}' which is now included by default in Storybook 8.`);
logger.warn(
`Removing from your plugins list. Ensure you pass \`--webpack-stats-json\` to generate stats.`
);
finalConfig.plugins = finalConfig.plugins?.filter((p) => p !== turbosnapPlugin);
finalConfig.plugins = await withoutVitePlugins(finalConfig.plugins, [turbosnapPluginName]);
}

await viteBuild(await sanitizeEnvVars(options, finalConfig));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function pluginWebpackStats({ workingDir }: WebpackStatsPluginOptions): W
const statsMap = new Map<string, Module>();

return {
name: 'rollup-plugin-webpack-stats',
name: 'storybook:rollup-plugin-webpack-stats',
// We want this to run after the vite build plugins (https://vitejs.dev/guide/api-plugin.html#plugin-ordering)
enforce: 'post',
moduleParsed: function (mod) {
Expand Down

0 comments on commit b629fa7

Please sign in to comment.