Skip to content

Commit

Permalink
fix(storybook): Fix CSS file clashes for libraries (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcompiles committed Feb 19, 2019
1 parent 61e02d1 commit 470d549
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions config/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,30 @@ const makeWebpackConfig = ({ isStorybook = false, port = 0 } = {}) => {
...paths.compilePackages.map(utils.resolvePackage)
];

// The client file mask is set to just name in start/dev mode as contenthash
// is not supported for hot reloading. It can also cause non
// deterministic snapshots in jest tests.
const clientFileMask = isStartScript ? '[name]' : '[name]-[contenthash]';
const getFileMask = () => {
if (isStorybook) {
return '[name]';
}

// Libraries should always have the same file name
// unless we're building for storybook
if (isLibrary) {
return libraryName;
}

// The client file mask is set to just name in start/dev mode as contenthash
// is not supported for hot reloading. It can also cause non
// deterministic snapshots in jest tests.
if (isStartScript) {
return '[name]';
}

// Libraries should always have the same file name
const libraryFileMask = libraryName;
// Production builds should contain contenthash for optimal file caching
return '[name]-[contenthash]';
};

const jsFileMask = isLibrary
? `${libraryFileMask}.js`
: `${clientFileMask}.js`;
const cssFileMask = isLibrary
? `${libraryFileMask}.css`
: `${clientFileMask}.css`;
const jsFileMask = `${getFileMask()}.js`;
const cssFileMask = `${getFileMask()}.css`;

const sourceMapStyle = isStartScript ? 'inline-source-map' : 'source-map';
const useSourceMaps = isStartScript || sourceMapsProd;
Expand Down

0 comments on commit 470d549

Please sign in to comment.