Open haruelrovix opened 5 years ago
Hi, I'm trying and trying to eliminate the size warnings, and nothing I've tried in the main.js config is working. Can someone show an example in the 'new' and better main.js config?
//.storybook/main.js const path = require('path') const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = {
stories: [
'../src//*.stories.mdx',
'../src/*/.stories.@(js|jsx|ts|tsx)',
'../src/components//*.stories.js',
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/preset-scss',
'@storybook/theming',
'@storybook/addon-storysource',
'@storybook/addon-notes/register',
'@etchteam/storybook-addon-status/register',
'@whitespace/storybook-addon-html',
],
presets: ['storybook-addon-deps/preset'],
webpackFinal: async (config, { configType }) => {
// configType
has a value of 'DEVELOPMENT' or 'PRODUCTION'
// You can change the configuration based on that.
// 'PRODUCTION' is used when building the static version of storybook.
// Make whatever fine-grained changes you need
config.module.rules.push({
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: [path.resolve(__dirname, './')],
})
// analyze webpack bundle size. To enable run storybook with `cross-env analyze=true`
// not needed, but helps debug the problem :)
const shouldAnalyze = process.env.analyze === 'true'
if (shouldAnalyze) {
config.plugins.push(new BundleAnalyzerPlugin())
}
// split into more chunks
config.optimization = {
splitChunks: {
chunks: 'async',
minSize: 30 * 1024, // 30KB
maxSize: 64 * 1024, // 1MB
},
}
// Return the altered config
return config
},
}
To reproduce, run
yarn build-storybook
. There are two asset size limit warnings that can impact web performance.Solution: implement Code Splitting.