From 5a97466c8c8db499dce5ecf07eabff8324448f56 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 19 Jan 2018 20:08:25 +0200 Subject: [PATCH 1/7] Move default webpack.config to core --- lib/core/package.json | 17 ++++- lib/core/server.js | 3 + .../server/config/defaults/webpack.config.js | 65 +++++++++++++++++++ yarn.lock | 2 +- 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 lib/core/server.js create mode 100644 lib/core/src/server/config/defaults/webpack.config.js diff --git a/lib/core/package.json b/lib/core/package.json index c42de1733667..7ed5c05372ce 100644 --- a/lib/core/package.json +++ b/lib/core/package.json @@ -17,10 +17,25 @@ "prepare": "node ../../scripts/prepare.js" }, "dependencies": { + "@storybook/addons": "^3.4.0-alpha.5", + "@storybook/channel-postmessage": "^3.4.0-alpha.5", "@storybook/client-logger": "^3.4.0-alpha.5", + "@storybook/ui": "^3.4.0-alpha.5", + "autoprefixer": "^7.2.5", + "babel-runtime": "^6.26.0", + "css-loader": "^0.28.9", "events": "^1.1.1", + "file-loader": "^1.1.6", "global": "^4.3.2", - "qs": "^6.5.1" + "json-loader": "^0.5.7", + "postcss-flexbugs-fixes": "^3.2.0", + "postcss-loader": "^2.0.10", + "prop-types": "^15.5.10", + "react": "^16.0.0", + "react-dom": "^16.0.0", + "style-loader": "^0.19.1", + "qs": "^6.5.1", + "url-loader": "^0.6.2" }, "devDependencies": { "babel-cli": "^6.26.0" diff --git a/lib/core/server.js b/lib/core/server.js new file mode 100644 index 000000000000..a87b975c2117 --- /dev/null +++ b/lib/core/server.js @@ -0,0 +1,3 @@ +const defaultWebpackConfig = require('./dist/server/config/defaults/webpack.config'); + +module.exports = defaultWebpackConfig; diff --git a/lib/core/src/server/config/defaults/webpack.config.js b/lib/core/src/server/config/defaults/webpack.config.js new file mode 100644 index 000000000000..8987fef8f2e3 --- /dev/null +++ b/lib/core/src/server/config/defaults/webpack.config.js @@ -0,0 +1,65 @@ +import autoprefixer from 'autoprefixer'; + +export function createDefaultWebpackConfig(storybookBaseConfig, includePaths) { + const newConfig = { ...storybookBaseConfig }; + + newConfig.module.rules = [ + ...storybookBaseConfig.module.rules, + { + test: /\.css$/, + use: [ + require.resolve('style-loader'), + { + loader: require.resolve('css-loader'), + options: { + importLoaders: 1, + }, + }, + { + loader: require.resolve('postcss-loader'), + options: { + ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options + plugins: () => [ + require('postcss-flexbugs-fixes'), // eslint-disable-line + autoprefixer({ + browsers: ['>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 9'], + flexbox: 'no-2009', + }), + ], + }, + }, + ], + }, + { + test: /\.json$/, + include: includePaths, + loader: require.resolve('json-loader'), + }, + { + test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/, + include: includePaths, + loader: require.resolve('file-loader'), + query: { + name: 'static/media/[name].[hash:8].[ext]', + }, + }, + { + test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/, + include: includePaths, + loader: require.resolve('url-loader'), + query: { + limit: 10000, + name: 'static/media/[name].[hash:8].[ext]', + }, + }, + ]; + + newConfig.resolve.alias = { + ...storybookBaseConfig.resolve.alias, + // This is to support NPM2 + 'babel-runtime/regenerator': require.resolve('babel-runtime/regenerator'), + }; + + // Return the altered config + return newConfig; +} diff --git a/yarn.lock b/yarn.lock index 82ccbb7a6a88..b3242fe0802b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11164,7 +11164,7 @@ postcss-flexbugs-fixes@3.2.0: dependencies: postcss "^6.0.1" -postcss-flexbugs-fixes@^3.3.0: +postcss-flexbugs-fixes@^3.2.0, postcss-flexbugs-fixes@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/postcss-flexbugs-fixes/-/postcss-flexbugs-fixes-3.3.0.tgz#e00849b536063749da50a0d410ba5d9ee65e27b8" dependencies: From d25cae65155a0a0844427862a4edbfcdd77c53fc Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 19 Jan 2018 20:09:18 +0200 Subject: [PATCH 2/7] use default webpack.config from core in angular app --- .../server/config/defaults/webpack.config.js | 74 +------------------ 1 file changed, 3 insertions(+), 71 deletions(-) diff --git a/app/angular/src/server/config/defaults/webpack.config.js b/app/angular/src/server/config/defaults/webpack.config.js index 477d1c4c62b8..a4ddafb7a54a 100644 --- a/app/angular/src/server/config/defaults/webpack.config.js +++ b/app/angular/src/server/config/defaults/webpack.config.js @@ -1,73 +1,5 @@ -// import webpack from 'webpack'; -import autoprefixer from 'autoprefixer'; +import { createDefaultWebpackConfig } from '@storybook/core/server'; import { includePaths } from '../utils'; -// Add a default custom config which is similar to what React Create App does. -module.exports = storybookBaseConfig => { - const newConfig = { ...storybookBaseConfig }; - - newConfig.module.rules = [ - ...storybookBaseConfig.module.rules, - { - test: /\.css$/, - use: [ - require.resolve('style-loader'), - { - loader: require.resolve('css-loader'), - options: { - importLoaders: 1, - }, - }, - { - loader: require.resolve('postcss-loader'), - options: { - ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options - plugins: () => [ - require('postcss-flexbugs-fixes'), // eslint-disable-line - autoprefixer({ - browsers: [ - '>1%', - 'last 4 versions', - 'Firefox ESR', - 'not ie < 9', // React doesn't support IE8 anyway - ], - flexbox: 'no-2009', - }), - ], - }, - }, - ], - }, - { - test: /\.json$/, - include: includePaths, - loader: require.resolve('json-loader'), - }, - { - test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/, - include: includePaths, - loader: require.resolve('file-loader'), - query: { - name: 'static/media/[name].[hash:8].[ext]', - }, - }, - { - test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/, - include: includePaths, - loader: require.resolve('url-loader'), - query: { - limit: 10000, - name: 'static/media/[name].[hash:8].[ext]', - }, - }, - ]; - - newConfig.resolve.alias = { - ...storybookBaseConfig.resolve.alias, - // This is to support NPM2 - 'babel-runtime/regenerator': require.resolve('babel-runtime/regenerator'), - }; - - // Return the altered config - return newConfig; -}; +module.exports = storybookBaseConfig => + createDefaultWebpackConfig(storybookBaseConfig, includePaths); From e82195952022024d723399f1f29f1b248fe4e64e Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 19 Jan 2018 20:10:03 +0200 Subject: [PATCH 3/7] Move manager to core and use it in angular app --- app/angular/src/server/config/webpack.config.js | 3 ++- app/angular/src/server/config/webpack.config.prod.js | 3 ++- lib/core/client.js | 6 ++++-- {app/angular => lib/core}/src/client/manager/index.js | 0 {app/angular => lib/core}/src/client/manager/preview.js | 0 {app/angular => lib/core}/src/client/manager/provider.js | 0 6 files changed, 8 insertions(+), 4 deletions(-) rename {app/angular => lib/core}/src/client/manager/index.js (100%) rename {app/angular => lib/core}/src/client/manager/preview.js (100%) rename {app/angular => lib/core}/src/client/manager/provider.js (100%) diff --git a/app/angular/src/server/config/webpack.config.js b/app/angular/src/server/config/webpack.config.js index fccf87ea32eb..3dff797121af 100644 --- a/app/angular/src/server/config/webpack.config.js +++ b/app/angular/src/server/config/webpack.config.js @@ -2,6 +2,7 @@ import path from 'path'; import webpack from 'webpack'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; +import { pathToManager } from '@storybook/core/client'; import WatchMissingNodeModulesPlugin from './WatchMissingNodeModulesPlugin'; import { includePaths, excludePaths, nodeModulesPaths, loadEnv, nodePaths } from './utils'; @@ -13,7 +14,7 @@ export default function(configDir) { const config = { devtool: 'cheap-module-source-map', entry: { - manager: [require.resolve('./polyfills'), require.resolve('../../client/manager')], + manager: [require.resolve('./polyfills'), pathToManager], preview: [ require.resolve('./polyfills'), require.resolve('./globals'), diff --git a/app/angular/src/server/config/webpack.config.prod.js b/app/angular/src/server/config/webpack.config.prod.js index 4adf3deba0e4..d409eb802546 100644 --- a/app/angular/src/server/config/webpack.config.prod.js +++ b/app/angular/src/server/config/webpack.config.prod.js @@ -2,6 +2,7 @@ import path from 'path'; import webpack from 'webpack'; import UglifyJsPlugin from 'uglifyjs-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; +import { pathToManager } from '@storybook/core/client'; import babelLoaderConfig from './babel.prod'; import { includePaths, excludePaths, loadEnv, nodePaths } from './utils'; @@ -11,7 +12,7 @@ import { version } from '../../../package.json'; export default function(configDir) { const entries = { preview: [require.resolve('./polyfills'), require.resolve('./globals')], - manager: [require.resolve('./polyfills'), path.resolve(__dirname, '../../client/manager')], + manager: [require.resolve('./polyfills'), pathToManager], }; const config = { diff --git a/lib/core/client.js b/lib/core/client.js index 6de6d9128855..c1a63b28f0e3 100644 --- a/lib/core/client.js +++ b/lib/core/client.js @@ -1,2 +1,4 @@ -/* eslint-disable global-require */ -module.exports = require('./dist/client').default; +const client = require('./dist/client').default; + +module.exports = client; +module.exports.pathToManager = require.resolve('./dist/client/manager'); diff --git a/app/angular/src/client/manager/index.js b/lib/core/src/client/manager/index.js similarity index 100% rename from app/angular/src/client/manager/index.js rename to lib/core/src/client/manager/index.js diff --git a/app/angular/src/client/manager/preview.js b/lib/core/src/client/manager/preview.js similarity index 100% rename from app/angular/src/client/manager/preview.js rename to lib/core/src/client/manager/preview.js diff --git a/app/angular/src/client/manager/provider.js b/lib/core/src/client/manager/provider.js similarity index 100% rename from app/angular/src/client/manager/provider.js rename to lib/core/src/client/manager/provider.js From 6832eda8d0a6da69c1acba7736a8cef55335b195 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 19 Jan 2018 20:15:45 +0200 Subject: [PATCH 4/7] Use core in polymer --- app/polymer/src/client/index.js | 16 ---- app/polymer/src/client/manager/index.js | 7 -- app/polymer/src/client/manager/preview.js | 39 ---------- app/polymer/src/client/manager/provider.js | 53 ------------- .../server/config/defaults/webpack.config.js | 74 +------------------ .../src/server/config/webpack.config.js | 4 +- .../src/server/config/webpack.config.prod.js | 4 +- 7 files changed, 8 insertions(+), 189 deletions(-) delete mode 100644 app/polymer/src/client/manager/index.js delete mode 100644 app/polymer/src/client/manager/preview.js delete mode 100644 app/polymer/src/client/manager/provider.js diff --git a/app/polymer/src/client/index.js b/app/polymer/src/client/index.js index 4d19c3fb217f..925ffed29bb3 100644 --- a/app/polymer/src/client/index.js +++ b/app/polymer/src/client/index.js @@ -1,17 +1 @@ -// import deprecate from 'util-deprecate'; - -// NOTE export these to keep backwards compatibility -// import { action as deprecatedAction } from '@storybook/addon-actions'; -// import { linkTo as deprecatedLinkTo } from '@storybook/addon-links'; - export { storiesOf, setAddon, addDecorator, configure, getStorybook } from './preview'; - -// export const action = deprecate( -// deprecatedAction, -// '@storybook/react action is deprecated. See: https://github.com/storybooks/storybook/tree/master/addons/actions' -// ); - -// export const linkTo = deprecate( -// deprecatedLinkTo, -// '@storybook/react linkTo is deprecated. See: https://github.com/storybooks/storybook/tree/master/addons/links' -// ); diff --git a/app/polymer/src/client/manager/index.js b/app/polymer/src/client/manager/index.js deleted file mode 100644 index 24082de7ca54..000000000000 --- a/app/polymer/src/client/manager/index.js +++ /dev/null @@ -1,7 +0,0 @@ -/* global document */ - -import renderStorybookUI from '@storybook/ui'; -import Provider from './provider'; - -const rootEl = document.getElementById('root'); -renderStorybookUI(rootEl, new Provider()); diff --git a/app/polymer/src/client/manager/preview.js b/app/polymer/src/client/manager/preview.js deleted file mode 100644 index 4f8e792d9641..000000000000 --- a/app/polymer/src/client/manager/preview.js +++ /dev/null @@ -1,39 +0,0 @@ -import PropTypes from 'prop-types'; -import React, { Component } from 'react'; - -const iframeStyle = { - width: '100%', - height: '100%', - border: 0, - margin: 0, - padding: 0, -}; - -class Preview extends Component { - shouldComponentUpdate() { - // When the manager is re-rendered, due to changes in the layout (going full screen / changing - // addon panel to right) Preview section will update. If its re-rendered the whole html page - // inside the html is re-rendered making the story to re-mount. - // We dont have to re-render this component for any reason since changes are communicated to - // story using the channel and necessary changes are done by it. - return false; - } - - render() { - return ( -