Skip to content

Commit

Permalink
Merge pull request #4375 from storybooks/tech/reapply-html-plugin
Browse files Browse the repository at this point in the history
CHANGE back to use html-webpack-plugin to keep compatibility with plugins that depend on it
  • Loading branch information
ndelangen authored Oct 12, 2018
2 parents 07f57a1 + d379a8d commit f29b163
Show file tree
Hide file tree
Showing 11 changed files with 3,236 additions and 136 deletions.
2 changes: 1 addition & 1 deletion app/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"ejs": "^2.6.1",
"express": "^4.16.3",
"find-cache-dir": "^2.0.0",
"generate-page-webpack-plugin": "^1.1.1",
"global": "^4.3.2",
"html-webpack-plugin": "^4.0.0-beta.1",
"json5": "^2.1.0",
"prop-types": "^15.6.2",
"raw-loader": "^0.5.1",
Expand Down
32 changes: 15 additions & 17 deletions app/react-native/src/server/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { getEnvironment } from 'universal-dotenv';
import Dotenv from 'dotenv-webpack';
import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin';
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';

import GeneratePagePlugin from 'generate-page-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import { getManagerHeadHtml } from '@storybook/core/server';

Expand All @@ -31,21 +30,20 @@ const getConfig = options => {
publicPath: '/',
},
plugins: [
new GeneratePagePlugin(
{
template: require.resolve('@storybook/core/dist/server/templates/index.html.ejs'),
// eslint-disable-next-line global-require
parser: require('ejs'),
filename: entry => (entry === 'manager' ? 'index' : entry),
},
{
data: { version },
headHtmlSnippet: entry =>
entriesMeta[entry] ? entriesMeta[entry].headHtmlSnippet : null,
bodyHtmlSnippet: entry =>
entriesMeta[entry] ? entriesMeta[entry].bodyHtmlSnippet : null,
}
),
new HtmlWebpackPlugin({
filename: `index.html`,
chunksSortMode: 'none',
alwaysWriteToDisk: true,
inject: false,
templateParameters: (compilation, files, o) => ({
compilation,
files,
options: o,
version,
...entriesMeta.manager,
}),
template: require.resolve(`@storybook/core/src/server/templates/index.ejs`),
}),
new webpack.HotModuleReplacementPlugin(),
new CaseSensitivePathsPlugin(),
new WatchMissingNodeModulesPlugin(nodeModulesPaths),
Expand Down
34 changes: 21 additions & 13 deletions app/react-native/src/server/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import path from 'path';
import webpack from 'webpack';
import { getEnvironment } from 'universal-dotenv';
import Dotenv from 'dotenv-webpack';
import GeneratePagePlugin from 'generate-page-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import { getManagerHeadHtml } from '@storybook/core/dist/server/utils';
import { version } from '../../../package.json';
import { includePaths, excludePaths } from './utils';

const getConfig = options => {
const entriesMeta = {
manager: {
headHtmlSnippet: getManagerHeadHtml(options.configDir, process.env),
},
};

const config = {
mode: 'production',
bail: true,
Expand All @@ -27,18 +33,20 @@ const getConfig = options => {
publicPath: '/',
},
plugins: [
new GeneratePagePlugin(
{
template: require.resolve('@storybook/core/dist/server/templates/index.html.ejs'),
// eslint-disable-next-line global-require
parser: require('ejs'),
filename: entry => (entry === 'manager' ? 'index' : entry),
},
{
data: { version },
headHtmlSnippet: getManagerHeadHtml(options.configDir, process.env),
}
),
new HtmlWebpackPlugin({
filename: `index.html`,
chunksSortMode: 'none',
alwaysWriteToDisk: true,
inject: false,
templateParameters: (compilation, files, o) => ({
compilation,
files,
options: o,
version,
...entriesMeta.manager,
}),
template: require.resolve(`@storybook/core/src/server/templates/index.ejs`),
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
storybookOptions: JSON.stringify(options),
Expand Down
2 changes: 1 addition & 1 deletion examples/polymer-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"devDependencies": {
"copy-webpack-plugin": "^4.5.3",
"html-webpack-plugin": "^3.2.0",
"html-webpack-plugin": "^4.0.0-beta.1",
"webpack-dev-server": "^3.1.9"
}
}
2 changes: 1 addition & 1 deletion lib/cli/test/fixtures/sfc_vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"extract-text-webpack-plugin": "^2.0.0",
"file-loader": "^0.11.1",
"friendly-errors-webpack-plugin": "^1.1.3",
"html-webpack-plugin": "^2.28.0",
"html-webpack-plugin": "^4.0.0-beta.1",
"http-proxy-middleware": "^0.17.3",
"opn": "^5.1.0",
"optimize-css-assets-webpack-plugin": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion lib/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"express": "^4.16.3",
"file-loader": "^2.0.0",
"find-cache-dir": "^2.0.0",
"generate-page-webpack-plugin": "^1.1.1",
"global": "^4.3.2",
"html-webpack-plugin": "^4.0.0-beta.1",
"inquirer": "^6.2.0",
"interpret": "^1.1.0",
"ip": "^1.1.5",
Expand Down
34 changes: 19 additions & 15 deletions lib/core/src/server/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { getEnvironment } from 'universal-dotenv';
import Dotenv from 'dotenv-webpack';
import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin';
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import GeneratePagePlugin from 'generate-page-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import {
includePaths,
excludePaths,
Expand Down Expand Up @@ -42,20 +43,23 @@ export default ({ configDir, quiet, babelOptions, entries }) => {
publicPath: '',
},
plugins: [
new GeneratePagePlugin(
{
template: require.resolve('../templates/index.html.ejs'),
// eslint-disable-next-line global-require
parser: require('ejs'),
filename: entry => (entry === 'manager' ? 'index' : entry),
},
{
data: { version },
headHtmlSnippet: entry =>
entriesMeta[entry] ? entriesMeta[entry].headHtmlSnippet : null,
bodyHtmlSnippet: entry =>
entriesMeta[entry] ? entriesMeta[entry].bodyHtmlSnippet : null,
}
...Object.keys(entries).map(
e =>
new HtmlWebpackPlugin({
filename: `${e === 'manager' ? 'index' : e}.html`,
excludeChunks: Object.keys(entries).filter(i => i !== e),
chunksSortMode: 'none',
alwaysWriteToDisk: true,
inject: false,
templateParameters: (compilation, files, options) => ({
compilation,
files,
options,
version,
...entriesMeta[e],
}),
template: require.resolve(`../templates/index.ejs`),
})
),
new webpack.DefinePlugin(loadEnv()),
new webpack.HotModuleReplacementPlugin(),
Expand Down
34 changes: 19 additions & 15 deletions lib/core/src/server/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import webpack from 'webpack';
import { getEnvironment } from 'universal-dotenv';
import Dotenv from 'dotenv-webpack';
import GeneratePagePlugin from 'generate-page-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import { version } from '../../../package.json';
import { includePaths, excludePaths, loadEnv, nodePaths, getBabelRuntimePath } from './utils';
import { getPreviewHeadHtml, getManagerHeadHtml, getPreviewBodyHtml } from '../utils';
Expand Down Expand Up @@ -32,20 +33,23 @@ export default ({ configDir, babelOptions, entries }) => {
publicPath: '',
},
plugins: [
new GeneratePagePlugin(
{
template: require.resolve('../templates/index.html.ejs'),
// eslint-disable-next-line global-require
parser: require('ejs'),
filename: entry => (entry === 'manager' ? 'index' : entry),
},
{
data: { version },
headHtmlSnippet: entry =>
entriesMeta[entry] ? entriesMeta[entry].headHtmlSnippet : null,
bodyHtmlSnippet: entry =>
entriesMeta[entry] ? entriesMeta[entry].bodyHtmlSnippet : null,
}
...Object.keys(entries).map(
e =>
new HtmlWebpackPlugin({
filename: `${e === 'manager' ? 'index' : e}.html`,
excludeChunks: Object.keys(entries).filter(i => i !== e),
chunksSortMode: 'none',
alwaysWriteToDisk: true,
inject: false,
templateParameters: (compilation, files, options) => ({
compilation,
files,
options,
version,
...entriesMeta[e],
}),
template: require.resolve(`../templates/index.ejs`),
})
),
new webpack.DefinePlugin(loadEnv({ production: true })),
new webpack.DefinePlugin(getEnvironment().webpack),
Expand Down
46 changes: 46 additions & 0 deletions lib/core/src/server/templates/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title><%= options.title || 'Storybook'%></title>

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

<% if (options.mobile) { %>
<meta name="viewport" content="width=device-width, initial-scale=1">
<% } %>

<% if (typeof headHtmlSnippet !== 'undefined') { %>
<%= headHtmlSnippet %>
<% } %>

<% files.css.forEach(file => { %>
<link href="<%= file %>" rel="stylesheet">
<% }); %>

</head>
<body>

<% if (typeof bodyHtmlSnippet !== 'undefined') { %>
<%= bodyHtmlSnippet %>
<% } %>

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

<% if (options.window) { %>
<script>
<% for (var varName in options.window) { %>
window['<%=varName%>'] = <%= JSON.stringify(options.window[varName]) %>;
<% } %>
</script>
<% } %>

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

</body>
</html>
62 changes: 0 additions & 62 deletions lib/core/src/server/templates/index.html.ejs

This file was deleted.

Loading

0 comments on commit f29b163

Please sign in to comment.