Skip to content

Commit

Permalink
fix(storybook): remove webpack from vite and install webpack if npm (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Dec 5, 2022
1 parent ddc2dca commit 8560453
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,10 @@ const config: StorybookConfig = {
'../src/app/**/*.stories.mdx',
'../src/app/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [...(rootMain.addons || []) , '@nrwl/react/plugins/storybook'
addons: [...(rootMain.addons || [])
],
webpackFinal: async (config, { configType }: Options) => {
// apply any global webpack configs that might have been specified in .storybook/main.ts
if (rootMain.webpackFinal) {
config = await rootMain.webpackFinal(config, { configType } as Options);
}
// add your own webpack tweaks if needed
return config;
},
]
};
module.exports = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,10 @@ const config: StorybookConfig = {
'../src/lib/**/*.stories.mdx',
'../src/lib/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [...(rootMain.addons || []) , '@nrwl/react/plugins/storybook'
addons: [...(rootMain.addons || [])
],
webpackFinal: async (config, { configType }: Options) => {
// apply any global webpack configs that might have been specified in .storybook/main.ts
if (rootMain.webpackFinal) {
config = await rootMain.webpackFinal(config, { configType } as Options);
}
// add your own webpack tweaks if needed
return config;
},
]
};
module.exports = config;
Expand Down Expand Up @@ -213,20 +203,10 @@ const config: StorybookConfig = {
'../src/lib/**/*.stories.mdx',
'../src/lib/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [...(rootMain.addons || []) , '@nrwl/react/plugins/storybook'
addons: [...(rootMain.addons || [])
],
webpackFinal: async (config, { configType }: Options) => {
// apply any global webpack configs that might have been specified in .storybook/main.ts
if (rootMain.webpackFinal) {
config = await rootMain.webpackFinal(config, { configType } as Options);
}
// add your own webpack tweaks if needed
return config;
},
]
};
module.exports = config;
Expand Down Expand Up @@ -272,7 +252,7 @@ const config: StorybookConfig = {
'../components/**/*.stories.mdx',
'../components/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [...(rootMain.addons || []) , '@nrwl/react/plugins/storybook'
addons: [...(rootMain.addons || [])
, 'storybook-addon-swc',
{
Expand All @@ -282,17 +262,7 @@ const config: StorybookConfig = {
},
}
],
webpackFinal: async (config, { configType }: Options) => {
// apply any global webpack configs that might have been specified in .storybook/main.ts
if (rootMain.webpackFinal) {
config = await rootMain.webpackFinal(config, { configType } as Options);
}
// add your own webpack tweaks if needed
return config;
},
]
};
module.exports = config;
Expand Down Expand Up @@ -338,20 +308,10 @@ const config: StorybookConfig = {
'../src/app/**/*.stories.mdx',
'../src/app/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [...(rootMain.addons || []) , '@nrwl/react/plugins/storybook'
addons: [...(rootMain.addons || [])
],
webpackFinal: async (config, { configType }: Options) => {
// apply any global webpack configs that might have been specified in .storybook/main.ts
if (rootMain.webpackFinal) {
config = await rootMain.webpackFinal(config, { configType } as Options);
}
// add your own webpack tweaks if needed
return config;
},
]
};
module.exports = config;
Expand Down Expand Up @@ -397,20 +357,10 @@ const config: StorybookConfig = {
'../src/app/**/*.stories.mdx',
'../src/app/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [...(rootMain.addons || []) , '@nrwl/react/plugins/storybook'
addons: [...(rootMain.addons || [])
, 'storybook-addon-swc'
],
webpackFinal: async (config, { configType }: Options) => {
// apply any global webpack configs that might have been specified in .storybook/main.ts
if (rootMain.webpackFinal) {
config = await rootMain.webpackFinal(config, { configType } as Options);
}
// add your own webpack tweaks if needed
return config;
},
]
};
module.exports = config;
Expand Down Expand Up @@ -456,20 +406,10 @@ const config: StorybookConfig = {
'../src/lib/**/*.stories.mdx',
'../src/lib/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [...(rootMain.addons || []) , '@nrwl/react/plugins/storybook'
addons: [...(rootMain.addons || [])
],
webpackFinal: async (config, { configType }: Options) => {
// apply any global webpack configs that might have been specified in .storybook/main.ts
if (rootMain.webpackFinal) {
config = await rootMain.webpackFinal(config, { configType } as Options);
}
// add your own webpack tweaks if needed
return config;
},
]
};
module.exports = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config: StorybookConfig = {
'../<%= projectDirectory %>/**/*.stories.mdx',
'../<%= projectDirectory %>/**/*.stories.@(js|jsx|ts|tsx)'
<% } %>],
addons: [...(rootMain.addons || []) <% if(uiFramework === '@storybook/react') { %>, '@nrwl/react/plugins/storybook' <% } %><% if(uiFramework === '@storybook/react-native') { %>, '@storybook/addon-ondevice-actions', '@storybook/addon-ondevice-backgrounds', '@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-notes' <% } %>
addons: [...(rootMain.addons || []) <% if(uiFramework === '@storybook/react' && !usesVite) { %>, '@nrwl/react/plugins/storybook' <% } %><% if(uiFramework === '@storybook/react-native') { %>, '@storybook/addon-ondevice-actions', '@storybook/addon-ondevice-backgrounds', '@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-notes' <% } %>
<% if(usesSwc && !isNextJs) { %>, 'storybook-addon-swc' <% } %>
<% if(isNextJs) { %>, 'storybook-addon-swc',
{
Expand All @@ -23,7 +23,7 @@ const config: StorybookConfig = {
},
}
<% } %>
],
]<% if (!usesVite) { %>,
webpackFinal: async (config, { configType }: Options) => {
// apply any global webpack configs that might have been specified in .storybook/main.ts
if (rootMain.webpackFinal) {
Expand All @@ -33,7 +33,7 @@ const config: StorybookConfig = {
// add your own webpack tweaks if needed

return config;
},
},<% } %>
};

module.exports = config;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if (!isRootProject){ %>const rootMain = require('<%= offsetFromRoot %>../.storybook/<%= rootMainName %>');<% } %>
<% if (isRootProject){ %>const rootMain = require('./main.root');<% } %>
<% if (existsRootWebpackConfig){ %>const rootWebpackConfig = require('<%= offsetFromRoot %>../.storybook/webpack.config'); <% } %>
<% if (existsRootWebpackConfig && !usesVite){ %>const rootWebpackConfig = require('<%= offsetFromRoot %>../.storybook/webpack.config'); <% } %>
<% if (isNextJs){ %>const path = require('path');<% } %>

module.exports = {
Expand All @@ -13,7 +13,7 @@ module.exports = {
'../<%= projectDirectory %>/**/*.stories.mdx',
'../<%= projectDirectory %>/**/*.stories.@(js|jsx|ts|tsx)'
<% } %>],
addons: [...rootMain.addons <% if(uiFramework === '@storybook/react') { %>, '@nrwl/react/plugins/storybook' <% } %><% if(uiFramework === '@storybook/react-native') { %>, '@storybook/addon-ondevice-actions', '@storybook/addon-ondevice-backgrounds', '@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-notes' <% } %>
addons: [...rootMain.addons <% if(uiFramework === '@storybook/react' && !usesVite) { %>, '@nrwl/react/plugins/storybook' <% } %><% if(uiFramework === '@storybook/react-native') { %>, '@storybook/addon-ondevice-actions', '@storybook/addon-ondevice-backgrounds', '@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-notes' <% } %>
<% if(usesSwc && !isNextJs) { %>, 'storybook-addon-swc' <% } %>
<% if(isNextJs) { %>, 'storybook-addon-swc',
{
Expand All @@ -23,7 +23,7 @@ module.exports = {
},
}
<% } %>
],
]<% if (!usesVite) { %>,
webpackFinal: async (config, { configType }) => {
// apply any global webpack configs that might have been specified in .storybook/main.js
if (rootMain.webpackFinal) {
Expand All @@ -39,5 +39,5 @@ module.exports = {
// add your own webpack tweaks if needed

return config;
},
},<% } %>
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Object {
"@storybook/core-server": "~6.5.9",
"@storybook/manager-webpack5": "~6.5.9",
"existing": "1.0.0",
"html-webpack-plugin": "^5.5.0",
"webpack": "^5.64.0",
},
"name": "test-name",
Expand Down
6 changes: 6 additions & 0 deletions packages/storybook/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import { isFramework } from '../../utils/utilities';

import {
babelCoreVersion,
babelLoaderVersion,
Expand All @@ -21,11 +22,13 @@ import {
urlLoaderVersion,
viteBuilderVeresion,
webpack5Version,
htmlWebpackPluginVersion,
} from '../../utils/versions';
import { Schema } from './schema';

function checkDependenciesInstalled(host: Tree, schema: Schema) {
const packageJson = readJson(host, 'package.json');

const devDependencies = {};
const dependencies = {};
packageJson.dependencies = packageJson.dependencies || {};
Expand All @@ -43,6 +46,9 @@ function checkDependenciesInstalled(host: Tree, schema: Schema) {
devDependencies['@storybook/manager-webpack5'] = storybookVersion;
}

// TODO(katerina): Remove this when Storybook 7.0 is added in Nx
devDependencies['html-webpack-plugin'] = htmlWebpackPluginVersion;

if (isFramework('angular', schema)) {
devDependencies['@storybook/angular'] = storybookVersion;
devDependencies['webpack'] = webpack5Version;
Expand Down
1 change: 1 addition & 0 deletions packages/storybook/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export const storybookSwcAddonVersion = '^1.1.7';
export const storybookNextAddonVersion = '^1.6.6';
export const storybookTestRunnerVersion = '^0.7.2';
export const litHtmlVersion = '^2.3.1';
export const htmlWebpackPluginVersion = '^5.5.0';

0 comments on commit 8560453

Please sign in to comment.