fix(storybook): install nx/vite for non-buildable libs (#18778)
This commit is contained in:
parent
016c89fed6
commit
57463ed25a
@ -3,17 +3,21 @@
|
|||||||
exports[`react:storybook-configuration should configure everything and install correct dependencies 1`] = `
|
exports[`react:storybook-configuration should configure everything and install correct dependencies 1`] = `
|
||||||
"import type { StorybookConfig } from '@storybook/react-vite';
|
"import type { StorybookConfig } from '@storybook/react-vite';
|
||||||
|
|
||||||
|
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
||||||
|
import { mergeConfig } from 'vite';
|
||||||
|
|
||||||
const config: StorybookConfig = {
|
const config: StorybookConfig = {
|
||||||
stories: ['../src/lib/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
|
stories: ['../src/lib/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
|
||||||
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
|
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
|
||||||
framework: {
|
framework: {
|
||||||
name: '@storybook/react-vite',
|
name: '@storybook/react-vite',
|
||||||
options: {
|
options: {},
|
||||||
builder: {
|
|
||||||
viteConfigPath: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
viteFinal: async (config) =>
|
||||||
|
mergeConfig(config, {
|
||||||
|
plugins: [nxViteTsPaths()],
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|||||||
@ -3,17 +3,21 @@
|
|||||||
exports[`@nx/storybook:configuration for workspaces with Root project basic functionalities should generate Storybook files for nested project only 1`] = `
|
exports[`@nx/storybook:configuration for workspaces with Root project basic functionalities should generate Storybook files for nested project only 1`] = `
|
||||||
"import type { StorybookConfig } from '@storybook/react-vite';
|
"import type { StorybookConfig } from '@storybook/react-vite';
|
||||||
|
|
||||||
|
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
||||||
|
import { mergeConfig } from 'vite';
|
||||||
|
|
||||||
const config: StorybookConfig = {
|
const config: StorybookConfig = {
|
||||||
stories: ['../src/app/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
|
stories: ['../src/app/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
|
||||||
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
|
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
|
||||||
framework: {
|
framework: {
|
||||||
name: '@storybook/react-vite',
|
name: '@storybook/react-vite',
|
||||||
options: {
|
options: {},
|
||||||
builder: {
|
|
||||||
viteConfigPath: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
viteFinal: async (config) =>
|
||||||
|
mergeConfig(config, {
|
||||||
|
plugins: [nxViteTsPaths()],
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|||||||
@ -98,7 +98,6 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
|
|||||||
await configurationGenerator(tree, {
|
await configurationGenerator(tree, {
|
||||||
name: 'test-ui-lib',
|
name: 'test-ui-lib',
|
||||||
standaloneConfig: false,
|
standaloneConfig: false,
|
||||||
|
|
||||||
uiFramework: '@storybook/react-webpack5',
|
uiFramework: '@storybook/react-webpack5',
|
||||||
});
|
});
|
||||||
const tsconfigJson = readJson<TsConfig>(
|
const tsconfigJson = readJson<TsConfig>(
|
||||||
|
|||||||
@ -198,6 +198,17 @@ export async function configurationGenerator(
|
|||||||
devDeps['core-js'] = coreJsVersion;
|
devDeps['core-js'] = coreJsVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
schema.uiFramework.endsWith('-vite') &&
|
||||||
|
(!viteBuildTarget || !viteConfigFilePath)
|
||||||
|
) {
|
||||||
|
// This means that the user has selected a Vite framework
|
||||||
|
// but the project does not have Vite configuration.
|
||||||
|
// We need to install the @nx/vite plugin in order to be able to use
|
||||||
|
// the nxViteTsPaths plugin to register the tsconfig paths in Vite.
|
||||||
|
devDeps['@nx/vite'] = nxVersion;
|
||||||
|
}
|
||||||
|
|
||||||
tasks.push(addDependenciesToPackageJson(tree, {}, devDeps));
|
tasks.push(addDependenciesToPackageJson(tree, {}, devDeps));
|
||||||
|
|
||||||
if (!schema.skipFormat) {
|
if (!schema.skipFormat) {
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
import type { StorybookConfig } from '<%= uiFramework %>';
|
import type { StorybookConfig } from '<%= uiFramework %>';
|
||||||
|
<% if (usesVite && !viteConfigFilePath) { %>
|
||||||
|
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
||||||
|
import { mergeConfig } from 'vite';
|
||||||
|
<% } %>
|
||||||
|
|
||||||
const config: StorybookConfig = {
|
const config: StorybookConfig = {
|
||||||
stories: [
|
stories: [
|
||||||
@ -10,13 +14,19 @@ const config: StorybookConfig = {
|
|||||||
framework: {
|
framework: {
|
||||||
name: '<%= uiFramework %>',
|
name: '<%= uiFramework %>',
|
||||||
options: {
|
options: {
|
||||||
<% if (usesVite) { %>
|
<% if (usesVite && viteConfigFilePath) { %>
|
||||||
builder: {
|
builder: {
|
||||||
viteConfigPath: '<%= viteConfigFilePath %>',
|
viteConfigPath: '<%= viteConfigFilePath %>',
|
||||||
},
|
},
|
||||||
<% } %>
|
<% } %>
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
<% if (usesVite && !viteConfigFilePath) { %>
|
||||||
|
viteFinal: async (config) =>
|
||||||
|
mergeConfig(config, {
|
||||||
|
plugins: [nxViteTsPaths()],
|
||||||
|
}),
|
||||||
|
<% } %>
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|||||||
@ -1,3 +1,8 @@
|
|||||||
|
<% if (usesVite && !viteConfigFilePath) { %>
|
||||||
|
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
||||||
|
import { mergeConfig } from 'vite';
|
||||||
|
<% } %>
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
stories: [
|
stories: [
|
||||||
<% if(uiFramework === '@storybook/angular' && projectType === 'library') { %>
|
<% if(uiFramework === '@storybook/angular' && projectType === 'library') { %>
|
||||||
@ -8,13 +13,19 @@ const config = {
|
|||||||
framework: {
|
framework: {
|
||||||
name: '<%= uiFramework %>',
|
name: '<%= uiFramework %>',
|
||||||
options: {
|
options: {
|
||||||
<% if (usesVite) { %>
|
<% if (usesVite && viteConfigFilePath) { %>
|
||||||
builder: {
|
builder: {
|
||||||
viteConfigPath: '<%= viteConfigFilePath %>',
|
viteConfigPath: '<%= viteConfigFilePath %>',
|
||||||
},
|
},
|
||||||
<% } %>
|
<% } %>
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
<% if (usesVite && !viteConfigFilePath) { %>
|
||||||
|
viteFinal: async (config) =>
|
||||||
|
mergeConfig(config, {
|
||||||
|
plugins: [nxViteTsPaths()],
|
||||||
|
}),
|
||||||
|
<% } %>
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user