From e27c227090f2228ecacfb01a16043dcd38afb3d4 Mon Sep 17 00:00:00 2001 From: Romeo Van Snick Date: Wed, 1 Feb 2017 21:02:23 +0100 Subject: [PATCH] Also update dist --- dist/server/config.js | 2 +- dist/server/config/defaults/webpack.config.js | 22 ++++++++++++++----- dist/server/config/utils.js | 4 +++- dist/server/config/webpack.config.js | 12 ++++++---- dist/server/config/webpack.config.prod.js | 12 ++++++---- dist/server/middleware.js | 8 ++++++- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/dist/server/config.js b/dist/server/config.js index 7223fd32da10..c8eeab42d136 100644 --- a/dist/server/config.js +++ b/dist/server/config.js @@ -72,7 +72,7 @@ exports.default = function (configType, baseConfig, configDir) { }) }); - addJsonLoaderIfNotAvailable(newConfig); + // addJsonLoaderIfNotAvailable(newConfig); return newConfig; }; diff --git a/dist/server/config/defaults/webpack.config.js b/dist/server/config/defaults/webpack.config.js index 8afac3101dc2..4aa99d4281db 100644 --- a/dist/server/config/defaults/webpack.config.js +++ b/dist/server/config/defaults/webpack.config.js @@ -14,6 +14,10 @@ var _autoprefixer2 = _interopRequireDefault(_autoprefixer); var _utils = require('../utils'); +var _webpack = require('webpack'); + +var _webpack2 = _interopRequireDefault(_webpack); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // Add a default custom config which is similar to what React Create App does. @@ -44,11 +48,19 @@ module.exports = function (storybookBaseConfig) { } }]); - newConfig.postcss = function () { - return [(0, _autoprefixer2.default)({ - browsers: ['>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 9'] - })]; - }; + var postcssPlugins = [(0, _autoprefixer2.default)({ + browsers: ['>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 9'] + })]; + + if (_utils.webpackVersion === 1) { + newConfig.postcss = function () { + return postcssPlugins; + }; + } else { + newConfig.plugins.push(new _webpack2.default.LoaderOptionsPlugin({ + postcss: postcssPlugins + })); + } newConfig.resolve.alias = (0, _extends3.default)({}, storybookBaseConfig.resolve.alias, { // This is to support NPM2 diff --git a/dist/server/config/utils.js b/dist/server/config/utils.js index dade99544b10..468e4c12cf73 100644 --- a/dist/server/config/utils.js +++ b/dist/server/config/utils.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.nodePaths = exports.nodeModulesPaths = exports.excludePaths = exports.includePaths = exports.OccurenceOrderPlugin = undefined; +exports.nodePaths = exports.nodeModulesPaths = exports.excludePaths = exports.includePaths = exports.webpackVersion = exports.OccurenceOrderPlugin = undefined; var _stringify = require('babel-runtime/core-js/json/stringify'); @@ -31,6 +31,8 @@ exports.OccurenceOrderPlugin = _webpack2.default.optimize.OccurrenceOrderPlugin // for webpack 1 _webpack2.default.optimize.OccurenceOrderPlugin; +var webpackVersion = exports.webpackVersion = _webpack2.default.optimize.OccurrenceOrderPlugin ? 2 : 1; + var includePaths = exports.includePaths = [_path2.default.resolve('./')]; var excludePaths = exports.excludePaths = [_path2.default.resolve('./node_modules')]; diff --git a/dist/server/config/webpack.config.js b/dist/server/config/webpack.config.js index 414776f9d611..c408f9d2bf22 100644 --- a/dist/server/config/webpack.config.js +++ b/dist/server/config/webpack.config.js @@ -29,10 +29,7 @@ exports.default = function () { resolve: { // Since we ship with json-loader always, it's better to move extensions to here // from the default config. - extensions: ['.js', '.json', '.jsx', ''], - // Add support to NODE_PATH. With this we could avoid relative path imports. - // Based on this CRA feature: https://github.com/facebookincubator/create-react-app/issues/253 - fallback: _utils.nodePaths, + extensions: ['.js', '.json', '.jsx'], alias: { // This is to add addon support for NPM2 '@kadira/storybook-addons': require.resolve('@kadira/storybook-addons') @@ -40,6 +37,13 @@ exports.default = function () { } }; + if (_utils.webpackVersion === 1) { + // Add support to NODE_PATH. With this we could avoid relative path imports. + // Based on this CRA feature: https://github.com/facebookincubator/create-react-app/issues/253 + config.fallback = _utils.nodePaths; + config.resolve.extensions.push(''); + } + return config; }; diff --git a/dist/server/config/webpack.config.prod.js b/dist/server/config/webpack.config.prod.js index 6dc307dca3ab..8413af109bb8 100644 --- a/dist/server/config/webpack.config.prod.js +++ b/dist/server/config/webpack.config.prod.js @@ -46,10 +46,7 @@ exports.default = function () { resolve: { // Since we ship with json-loader always, it's better to move extensions to here // from the default config. - extensions: ['.js', '.json', '.jsx', ''], - // Add support to NODE_PATH. With this we could avoid relative path imports. - // Based on this CRA feature: https://github.com/facebookincubator/create-react-app/issues/253 - fallback: _utils.nodePaths, + extensions: ['.js', '.json', '.jsx'], alias: { // This is to add addon support for NPM2 '@kadira/storybook-addons': require.resolve('@kadira/storybook-addons') @@ -63,6 +60,13 @@ exports.default = function () { config.plugins.unshift(new _utils.OccurenceOrderPlugin()); } + if (webpackVersion === 1) { + // Add support to NODE_PATH. With this we could avoid relative path imports. + // Based on this CRA feature: https://github.com/facebookincubator/create-react-app/issues/253 + config.fallback = _utils.nodePaths; + config.resolve.extensions.push(''); + } + return config; }; diff --git a/dist/server/middleware.js b/dist/server/middleware.js index 2101e2319c4a..eef8229cb3c8 100644 --- a/dist/server/middleware.js +++ b/dist/server/middleware.js @@ -16,7 +16,13 @@ exports.default = function (configDir) { publicPath = publicPath.slice(1); } - var compiler = (0, _webpack2.default)(config); + var compiler = void 0; + try { + compiler = (0, _webpack2.default)(config); + } catch (err) { + console.log(err); + } + var devMiddlewareOptions = { noInfo: true, publicPath: config.output.publicPath,