Skip to content

Commit

Permalink
Merge pull request #16653 from storybookjs/16647-manager-cache-features
Browse files Browse the repository at this point in the history
Core: Ensure manager caching respects globals
  • Loading branch information
shilman committed Nov 11, 2021
2 parents 74cc476 + 2955e4a commit 2009029
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 42 deletions.
9 changes: 3 additions & 6 deletions lib/builder-webpack4/src/preview/iframe-webpack.config.ts
Expand Up @@ -179,10 +179,8 @@ export default async (options: Options & Record<string, any>): Promise<Configura
chunksSortMode: 'none' as any,
alwaysWriteToDisk: true,
inject: false,
templateParameters: (compilation, files, templateOptions) => ({
compilation,
files,
options: templateOptions,
template,
templateParameters: {
version: packageJson.version,
globals: {
CONFIG_TYPE: configType,
Expand All @@ -198,7 +196,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
},
headHtmlSnippet,
bodyHtmlSnippet,
}),
},
minify: {
collapseWhitespace: true,
removeComments: true,
Expand All @@ -207,7 +205,6 @@ export default async (options: Options & Record<string, any>): Promise<Configura
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
},
template,
}),
new DefinePlugin({
...stringifyProcessEnvs(envs),
Expand Down
9 changes: 3 additions & 6 deletions lib/builder-webpack5/src/preview/iframe-webpack.config.ts
Expand Up @@ -177,10 +177,8 @@ export default async (options: Options & Record<string, any>): Promise<Configura
chunksSortMode: 'none' as any,
alwaysWriteToDisk: true,
inject: false,
templateParameters: (compilation, files, templateOptions) => ({
compilation,
files,
options: templateOptions,
template,
templateParameters: {
version: packageJson.version,
globals: {
CONFIG_TYPE: configType,
Expand All @@ -196,7 +194,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
},
headHtmlSnippet,
bodyHtmlSnippet,
}),
},
minify: {
collapseWhitespace: true,
removeComments: true,
Expand All @@ -205,7 +203,6 @@ export default async (options: Options & Record<string, any>): Promise<Configura
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
},
template,
}),
new DefinePlugin({
...stringifyProcessEnvs(envs),
Expand Down
32 changes: 14 additions & 18 deletions lib/core-common/src/templates/index.ejs
Expand Up @@ -2,16 +2,16 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title><%= options.title || 'Storybook'%></title>
<title><%= htmlWebpackPlugin.options.title || 'Storybook'%></title>

<% if (files.favicon) { %>
<link rel="shortcut icon" href="<%= files.favicon%>" />
<% if (htmlWebpackPlugin.files.favicon) { %>
<link rel="shortcut icon" href="<%= htmlWebpackPlugin.files.favicon%>" />
<% } %>

<meta name="viewport" content="width=device-width, initial-scale=1" />

<% if (typeof headHtmlSnippet !== 'undefined') { %> <%= headHtmlSnippet %> <% } %> <%
files.css.forEach(file => { %>
htmlWebpackPlugin.files.css.forEach(file => { %>
<link href="<%= file %>" rel="stylesheet" />
<% }); %>

Expand All @@ -23,25 +23,21 @@
</style>
</head>
<body>
<% if (typeof bodyHtmlSnippet !== 'undefined') { %>
<%= bodyHtmlSnippet %>
<% } %>
<% if (typeof bodyHtmlSnippet !== 'undefined') { %> <%= bodyHtmlSnippet %> <% } %>

<div id="root"></div>
<div id="docs-root"></div>

<% if (typeof globals !== 'undefined' && Object.keys(globals).length) { %>
<script>
<% for (var varName in globals) { %>
<% if (globals[varName] != undefined) { %>
window['<%=varName%>'] = <%= JSON.stringify(globals[varName]) %>;
<% } %>
<% } %>
</script>
<% } %>

<% files.js.forEach(file => { %>
<script src="<%= file %>"></script>
<script>
<% for (var varName in globals) { %>
<% if (globals[varName] != undefined) { %>
window['<%=varName%>'] = <%= JSON.stringify(globals[varName]) %>;
<% } %>
<% } %>
</script>
<% } %> <% htmlWebpackPlugin.files.js.forEach(file => { %>
<script src="<%= file %>"></script>
<% }); %>
</body>
</html>
9 changes: 3 additions & 6 deletions lib/manager-webpack4/src/presets/manager-preset.ts
Expand Up @@ -93,10 +93,8 @@ export async function managerWebpack(
chunksSortMode: 'none' as any,
alwaysWriteToDisk: true,
inject: false,
templateParameters: (compilation, files, options) => ({
compilation,
files,
options,
template,
templateParameters: {
version,
globals: {
CONFIG_TYPE: configType,
Expand All @@ -109,8 +107,7 @@ export async function managerWebpack(
SERVER_CHANNEL_URL: serverChannelUrl,
},
headHtmlSnippet,
}),
template,
},
}) as any) as WebpackPluginInstance,
(new CaseSensitivePathsPlugin() as any) as WebpackPluginInstance,
// graphql sources check process variable
Expand Down
9 changes: 3 additions & 6 deletions lib/manager-webpack5/src/presets/manager-preset.ts
Expand Up @@ -92,10 +92,8 @@ export async function managerWebpack(
chunksSortMode: 'none' as any,
alwaysWriteToDisk: true,
inject: false,
templateParameters: (compilation, files, options) => ({
compilation,
files,
options,
template,
templateParameters: {
version,
globals: {
CONFIG_TYPE: configType,
Expand All @@ -108,8 +106,7 @@ export async function managerWebpack(
SERVER_CHANNEL_URL: serverChannelUrl,
},
headHtmlSnippet,
}),
template,
},
}) as any) as WebpackPluginInstance,
(new CaseSensitivePathsPlugin() as any) as WebpackPluginInstance,
// graphql sources check process variable
Expand Down

0 comments on commit 2009029

Please sign in to comment.