-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Fix package duplication issues by aliasing all storybook packages #11092
+106
−22
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b4bf235
FIX paths and minification
ndelangen 541ce5c
FIX versions
ndelangen f48edc7
FIX alias pathing
ndelangen dc65657
Merge branch 'next' into fix/10887
ndelangen 262fca6
disable cra-preset for now
ndelangen 66e04ca
Allow monorepo project root dir to be imported in CRA examples
ndelangen bec1e35
Merge branch 'next' into fix/10887
ndelangen 0e21344
CLEANUP && FIX main.ts
ndelangen 764b689
CLEANUP as desired
ndelangen d91e0b2
Merge branch 'next' into fix/10887
ndelangen 6a15159
rename reserve-word variable
ndelangen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
stories: ['../src/stories/welcome.stories', '../src/stories/**/button.stories.js'], | ||
addons: [ | ||
'@storybook/preset-create-react-app', | ||
'@storybook/addon-actions', | ||
'@storybook/addon-links', | ||
], | ||
webpackFinal: (config) => { | ||
// add monorepo root as a valid directory to import modules from | ||
config.resolve.plugins.forEach((p) => { | ||
if (Array.isArray(p.appSrcs)) { | ||
p.appSrcs.push(path.join(__dirname, '..', '..', '..')); | ||
} | ||
}); | ||
return config; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; | |
|
||
import resolveFrom from 'resolve-from'; | ||
|
||
import themingPaths from '@storybook/theming/paths'; | ||
|
||
import { createBabelLoader } from './babel-loader-preview'; | ||
import es6Transpiler from '../common/es6Transpiler'; | ||
|
||
|
@@ -21,6 +23,30 @@ import { toRequireContextString } from './to-require-context'; | |
import { useBaseTsSupport } from '../config/useBaseTsSupport'; | ||
|
||
const reactPaths = {}; | ||
|
||
const storybookPaths = [ | ||
'addons', | ||
'addons', | ||
'api', | ||
'channels', | ||
'channel-postmessage', | ||
'components', | ||
'core-events', | ||
'router', | ||
'theming', | ||
'semver', | ||
'client-api', | ||
'client-logger', | ||
].reduce( | ||
(acc, package) => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
...acc, | ||
[`@storybook/${package}`]: path.dirname( | ||
resolveFrom(__dirname, `@storybook/${package}/package.json`) | ||
), | ||
}), | ||
{} | ||
); | ||
|
||
try { | ||
reactPaths.react = path.dirname(resolveFrom(process.cwd(), 'react/package.json')); | ||
reactPaths['react-dom'] = path.dirname(resolveFrom(process.cwd(), 'react-dom/package.json')); | ||
|
@@ -64,13 +90,8 @@ export default async ({ | |
const match = entryFilename.match(/(.*)-generated-(config|other)-entry.js$/); | ||
if (match) { | ||
const configFilename = match[1]; | ||
const isUsingYarnPnp = typeof process.versions.pnp !== 'undefined'; | ||
const clientApi = isUsingYarnPnp | ||
? `${require.resolve('@storybook/client-api')}` | ||
: '@storybook/client-api'; | ||
const clientLogger = isUsingYarnPnp | ||
? `${require.resolve('@storybook/client-logger')}` | ||
: '@storybook/client-logger'; | ||
const clientApi = storybookPaths['@storybook/client-api']; | ||
const clientLogger = storybookPaths['@storybook/client-logger']; | ||
|
||
virtualModuleMapping[entryFilename] = interpolate(entryTemplate, { | ||
configFilename, | ||
|
@@ -159,8 +180,8 @@ export default async ({ | |
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'], | ||
modules: ['node_modules'].concat(raw.NODE_PATH || []), | ||
alias: { | ||
'babel-runtime/core-js/object/assign': require.resolve('core-js/es/object/assign'), | ||
semver: require.resolve('@storybook/semver'), | ||
...themingPaths, | ||
...storybookPaths, | ||
...reactPaths, | ||
}, | ||
|
||
|
@@ -177,17 +198,19 @@ export default async ({ | |
chunks: 'all', | ||
}, | ||
runtimeChunk: true, | ||
minimizer: [ | ||
new TerserWebpackPlugin({ | ||
cache: true, | ||
parallel: true, | ||
sourceMap: true, | ||
terserOptions: { | ||
mangle: false, | ||
keep_fnames: true, | ||
}, | ||
}), | ||
], | ||
minimizer: isProd | ||
? [ | ||
new TerserWebpackPlugin({ | ||
cache: true, | ||
parallel: true, | ||
sourceMap: true, | ||
terserOptions: { | ||
mangle: false, | ||
keep_fnames: true, | ||
}, | ||
}), | ||
] | ||
: [], | ||
}, | ||
performance: { | ||
hints: isProd ? 'warning' : false, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are added to be sure to have them and be able to have a working alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah all packages of @storybook/* that are conceivably used are aliased here so that there can only 1 of them in the entire bundle.