Skip to content

Commit

Permalink
Merge pull request #19039 from storybookjs/symlinks-in-vite
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman authored Aug 29, 2022
2 parents 3691842 + f263f42 commit eaac795
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions code/lib/builder-vite/src/vite-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs';
import { Plugin } from 'vite';
import viteReact from '@vitejs/plugin-react';
import type { UserConfig } from 'vite';
import { isPreservingSymlinks } from '@storybook/core-common';
import { allowedEnvPrefix as envPrefix } from './envs';
import { codeGeneratorPlugin } from './code-generator-plugin';
import { injectExportOrderPlugin } from './inject-export-order-plugin';
Expand Down Expand Up @@ -33,6 +34,7 @@ export async function commonConfig(
cacheDir: 'node_modules/.vite-storybook',
envPrefix,
define: {},
resolve: { preserveSymlinks: isPreservingSymlinks() },
plugins: await pluginConfig(options, _type),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
normalizeStories,
readTemplate,
loadPreviewOrConfigFile,
isPreservingSymlinks,
} from '@storybook/core-common';
import { toRequireContextString, toImportFn } from '@storybook/core-webpack';
import type { BuilderOptions, TypescriptOptions } from '../types';
Expand Down Expand Up @@ -168,10 +169,6 @@ export default async (
const shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipBabel;
const tsCheckOptions = typescriptOptions.checkOptions || {};

const { NODE_OPTIONS, NODE_PRESERVE_SYMLINKS } = process.env;
const isPreservingSymlinks =
!!NODE_PRESERVE_SYMLINKS || NODE_OPTIONS?.includes('--preserve-symlinks');

return {
name: 'preview',
mode: isProd ? 'production' : 'development',
Expand Down Expand Up @@ -275,7 +272,7 @@ export default async (
},
// Set webpack to resolve symlinks based on whether the user has asked node to.
// This feels like it should be default out-of-the-box in webpack :shrug:
symlinks: !isPreservingSymlinks,
symlinks: !isPreservingSymlinks(),
},
optimization: {
splitChunks: {
Expand Down
1 change: 1 addition & 0 deletions code/lib/core-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export * from './utils/glob-to-regexp';
export * from './utils/normalize-stories';
export * from './utils/readTemplate';
export * from './utils/findDistEsm';
export * from './utils/symlinks';

export * from './types';

Expand Down
4 changes: 4 additions & 0 deletions code/lib/core-common/src/utils/symlinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function isPreservingSymlinks() {
const { NODE_OPTIONS, NODE_PRESERVE_SYMLINKS } = process.env;
return !!NODE_PRESERVE_SYMLINKS || NODE_OPTIONS?.includes('--preserve-symlinks');
}

0 comments on commit eaac795

Please sign in to comment.