Skip to content
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

CHANGE define plugin variables to globals instead #7622

Merged
merged 3 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/standalone-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"storybook": "parcel ./storybook.html --port 1337"
},
"devDependencies": {
"@storybook/react": "5.1.0-alpha.32",
"@storybook/react": "5.2.0-beta.18",
"parcel": "^1.12.3",
"react": "^16.8.4",
"react-dom": "^16.8.4"
Expand Down
6 changes: 4 additions & 2 deletions lib/core/src/server/manager/manager-webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export default ({
options,
version,
dlls: dll ? ['./sb_dll/storybook_ui_dll.js'] : [],
globals: {
DOCS_MODE: docsMode, // global docs mode
PREVIEW_URL: previewUrl, // global preview URL
},
headHtmlSnippet: getManagerHeadHtml(configDir, process.env),
}),
template: require.resolve(`../templates/index.ejs`),
Expand All @@ -73,8 +77,6 @@ export default ({
new DefinePlugin({
'process.env': stringified,
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
DOCS_MODE: JSON.stringify(docsMode), // global docs mode
PREVIEW_URL: JSON.stringify(previewUrl), // global preview URL
}),
// See https://github.com/graphql/graphql-language-service/issues/111#issuecomment-306723400
new ContextReplacementPlugin(/graphql-language-service-interface[/\\]dist/, /\.js$/),
Expand Down
1 change: 1 addition & 0 deletions lib/core/src/server/preview/iframe-webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default ({
files,
options,
version: packageJson.version,
globals: {},
headHtmlSnippet: getPreviewHeadHtml(configDir, process.env),
dlls: [],
bodyHtmlSnippet: getPreviewBodyHtml(),
Expand Down
26 changes: 15 additions & 11 deletions lib/core/src/server/templates/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
<% }); %>
</head>
<body>
<% if (typeof bodyHtmlSnippet !== 'undefined') { %> <%= bodyHtmlSnippet %> <% } %>
<% if (typeof bodyHtmlSnippet !== 'undefined') { %>
<%= bodyHtmlSnippet %>
<% } %>

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

<% if (options.window) { %>
<script>
<% for (var varName in options.window) { %>
window['<%=varName%>'] = <%= JSON.stringify(options.window[varName]) %>;
<% } %>
</script>
<% } %> <% dlls.forEach(file => { %>
<script src="<%= file %>"></script>
<% }); %> <% files.js.forEach(file => { %>
<script src="<%= file %>"></script>
<% if (typeof globals !== 'undefined' && Object.keys(globals).length) { %>
<script>
Object.assign(window, <%= JSON.stringify(globals) %>);
</script>
<% } %>

<% dlls.forEach(file => { %>
<script src="<%= file %>"></script>
<% }); %>

<% files.js.forEach(file => { %>
<script src="<%= file %>"></script>
<% }); %>
</body>
</html>
4 changes: 2 additions & 2 deletions lib/ui/src/containers/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PREVIEW_URL } from 'global';
import React from 'react';

import { Consumer } from '@storybook/api';
Expand All @@ -22,8 +23,7 @@ const mapper = ({ api, state: { layout, location, selected, customQueryParams }

function getBaseUrl() {
try {
// eslint-disable-next-line no-undef
return PREVIEW_URL || 'iframe.html'; // webpack-injected
return PREVIEW_URL || 'iframe.html';
} catch (e) {
return 'iframe.html';
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DOCS_MODE } from 'global';
import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
Expand All @@ -16,8 +17,7 @@ HelmetProvider.displayName = 'HelmetProvider';

const getDocsMode = () => {
try {
// eslint-disable-next-line no-undef
return !!DOCS_MODE; // webpack-injected
return !!DOCS_MODE;
} catch (e) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/root",
"version": "5.2.0-beta.13",
"version": "5.2.0-beta.18",
"private": true,
"description": "Storybook is an open source tool for developing UI components in isolation for React, Vue and Angular. It makes building stunning UIs organized and efficient.",
"keywords": [
Expand Down
Loading