From cb15153810e885ce90b0ba9782f8ef57fef4d627 Mon Sep 17 00:00:00 2001 From: igor-dv Date: Wed, 5 Dec 2018 12:32:54 +0200 Subject: [PATCH 1/5] Remove "defaultConfigName" prop and use "defaultConfig" as a single config to be extended --- app/angular/src/server/options.js | 1 - app/ember/src/server/options.js | 1 - app/react/src/server/options.js | 1 - .../ember-cli/.storybook/webpack.config.js | 20 +++++++------ .../.storybook/webpack.config.js | 20 +++++++------ .../marko-cli/.storybook/webpack.config.js | 20 +++++++------ .../.storybook/webpack.config.js | 20 +++++++------ .../polymer-cli/.storybook/webpack.config.js | 24 +++++++-------- .../.storybook/webpack.config.js | 29 ++++++++++--------- .../.storybook/webpack.config.js | 20 +++++++------ .../.storybook/webpack.config.js | 20 +++++++------ .../server/preview/custom-webpack-preset.js | 21 ++++---------- 12 files changed, 99 insertions(+), 98 deletions(-) diff --git a/app/angular/src/server/options.js b/app/angular/src/server/options.js index 189c31521e3..6ddc4098b20 100644 --- a/app/angular/src/server/options.js +++ b/app/angular/src/server/options.js @@ -2,7 +2,6 @@ import packageJson from '../../package.json'; export default { packageJson, - defaultConfigName: 'angular-cli', frameworkPresets: [ require.resolve('./framework-preset-angular.js'), require.resolve('./framework-preset-angular-cli.js'), diff --git a/app/ember/src/server/options.js b/app/ember/src/server/options.js index 21bd042f009..919e0202bca 100644 --- a/app/ember/src/server/options.js +++ b/app/ember/src/server/options.js @@ -2,6 +2,5 @@ import packageJson from '../../package.json'; export default { packageJson, - defaultConfigName: 'ember-cli', frameworkPresets: [require.resolve('./framework-preset-babel-ember.js')], }; diff --git a/app/react/src/server/options.js b/app/react/src/server/options.js index a14cc3f4a67..dd787ee5878 100644 --- a/app/react/src/server/options.js +++ b/app/react/src/server/options.js @@ -2,7 +2,6 @@ import packageJson from '../../package.json'; export default { packageJson, - defaultConfigName: 'create-react-app', frameworkPresets: [ require.resolve('./framework-preset-react.js'), require.resolve('./framework-preset-cra.js'), diff --git a/examples/ember-cli/.storybook/webpack.config.js b/examples/ember-cli/.storybook/webpack.config.js index 74dbd2156cc..3df5f03cc6a 100644 --- a/examples/ember-cli/.storybook/webpack.config.js +++ b/examples/ember-cli/.storybook/webpack.config.js @@ -1,12 +1,14 @@ const path = require('path'); -module.exports = (storybookBaseConfig, configType, defaultConfig) => { - defaultConfig.module.rules.push({ - test: [/\.stories\.js$/, /index\.js$/], - loaders: [require.resolve('@storybook/addon-storysource/loader')], - include: [path.resolve(__dirname, '../')], - enforce: 'pre', - }); - - return defaultConfig; +module.exports = { + module: { + rules: [ + { + test: [/\.stories\.js$/, /index\.js$/], + loaders: [require.resolve('@storybook/addon-storysource/loader')], + include: [path.resolve(__dirname, '../')], + enforce: 'pre', + }, + ], + }, }; diff --git a/examples/html-kitchen-sink/.storybook/webpack.config.js b/examples/html-kitchen-sink/.storybook/webpack.config.js index 5d9aaf4e1da..358db1cf6ee 100644 --- a/examples/html-kitchen-sink/.storybook/webpack.config.js +++ b/examples/html-kitchen-sink/.storybook/webpack.config.js @@ -1,12 +1,14 @@ const path = require('path'); -module.exports = (storybookBaseConfig, configType, defaultConfig) => { - defaultConfig.module.rules.push({ - test: [/\.stories\.js$/, /index\.js$/], - loaders: [require.resolve('@storybook/addon-storysource/loader')], - include: [path.resolve(__dirname, '../stories')], - enforce: 'pre', - }); - - return defaultConfig; +module.exports = { + module: { + rules: [ + { + test: [/\.stories\.js$/, /index\.js$/], + loaders: [require.resolve('@storybook/addon-storysource/loader')], + include: [path.resolve(__dirname, '../stories')], + enforce: 'pre', + }, + ], + }, }; diff --git a/examples/marko-cli/.storybook/webpack.config.js b/examples/marko-cli/.storybook/webpack.config.js index 692ad69cacc..d10037b0fd0 100644 --- a/examples/marko-cli/.storybook/webpack.config.js +++ b/examples/marko-cli/.storybook/webpack.config.js @@ -1,12 +1,14 @@ const path = require('path'); -module.exports = (storybookBaseConfig, configType, defaultConfig) => { - defaultConfig.module.rules.push({ - test: [/\.stories\.js$/], - loaders: [require.resolve('@storybook/addon-storysource/loader')], - include: [path.resolve(__dirname, '../src')], - enforce: 'pre', - }); - - return defaultConfig; +module.exports = { + module: { + rules: [ + { + test: [/\.stories\.js$/], + loaders: [require.resolve('@storybook/addon-storysource/loader')], + include: [path.resolve(__dirname, '../src')], + enforce: 'pre', + }, + ], + }, }; diff --git a/examples/mithril-kitchen-sink/.storybook/webpack.config.js b/examples/mithril-kitchen-sink/.storybook/webpack.config.js index 692ad69cacc..d10037b0fd0 100644 --- a/examples/mithril-kitchen-sink/.storybook/webpack.config.js +++ b/examples/mithril-kitchen-sink/.storybook/webpack.config.js @@ -1,12 +1,14 @@ const path = require('path'); -module.exports = (storybookBaseConfig, configType, defaultConfig) => { - defaultConfig.module.rules.push({ - test: [/\.stories\.js$/], - loaders: [require.resolve('@storybook/addon-storysource/loader')], - include: [path.resolve(__dirname, '../src')], - enforce: 'pre', - }); - - return defaultConfig; +module.exports = { + module: { + rules: [ + { + test: [/\.stories\.js$/], + loaders: [require.resolve('@storybook/addon-storysource/loader')], + include: [path.resolve(__dirname, '../src')], + enforce: 'pre', + }, + ], + }, }; diff --git a/examples/polymer-cli/.storybook/webpack.config.js b/examples/polymer-cli/.storybook/webpack.config.js index e6be81a0e93..e1ed08fcf61 100644 --- a/examples/polymer-cli/.storybook/webpack.config.js +++ b/examples/polymer-cli/.storybook/webpack.config.js @@ -1,16 +1,16 @@ const path = require('path'); const webpack = require('webpack'); -module.exports = (storybookBaseConfig, configType, defaultConfig) => { - defaultConfig.module.rules.push({ - test: [/\.stories\.js$/, /index\.js$/], - loaders: [require.resolve('@storybook/addon-storysource/loader')], - include: [path.resolve(__dirname, '../src')], - enforce: 'pre', - }); - - // TEMP fix: https://github.com/plotly/plotly.js/issues/2466#issuecomment-372924684 - defaultConfig.plugins.push(new webpack.IgnorePlugin(/vertx/)); - - return defaultConfig; +module.exports = { + module: { + rules: [ + { + test: [/\.stories\.js$/, /index\.js$/], + loaders: [require.resolve('@storybook/addon-storysource/loader')], + include: [path.resolve(__dirname, '../src')], + enforce: 'pre', + }, + ], + }, + plugins: [new webpack.IgnorePlugin(/vertx/)], }; diff --git a/examples/riot-kitchen-sink/.storybook/webpack.config.js b/examples/riot-kitchen-sink/.storybook/webpack.config.js index becba8b172f..f60c4be6a3d 100644 --- a/examples/riot-kitchen-sink/.storybook/webpack.config.js +++ b/examples/riot-kitchen-sink/.storybook/webpack.config.js @@ -1,17 +1,18 @@ const path = require('path'); -module.exports = (storybookBaseConfig, configType, defaultConfig) => { - defaultConfig.module.rules.push({ - test: [/\.stories\.js$/, /index\.js$/], - loaders: [require.resolve('@storybook/addon-storysource/loader')], - include: [path.resolve(__dirname, '../src')], - enforce: 'pre', - }); - - defaultConfig.module.rules.push({ - test: /\.txt$/, - use: 'raw-loader', - }); - - return defaultConfig; +module.exports = { + module: { + rules: [ + { + test: [/\.stories\.js$/, /index\.js$/], + loaders: [require.resolve('@storybook/addon-storysource/loader')], + include: [path.resolve(__dirname, '../src')], + enforce: 'pre', + }, + { + test: /\.txt$/, + use: 'raw-loader', + }, + ], + }, }; diff --git a/examples/svelte-kitchen-sink/.storybook/webpack.config.js b/examples/svelte-kitchen-sink/.storybook/webpack.config.js index 647e02ae0d4..92d286a488c 100644 --- a/examples/svelte-kitchen-sink/.storybook/webpack.config.js +++ b/examples/svelte-kitchen-sink/.storybook/webpack.config.js @@ -1,12 +1,14 @@ const path = require('path'); -module.exports = (storybookBaseConfig, configType, defaultConfig) => { - defaultConfig.module.rules.push({ - test: [/\.stories\.js$/, /index\.js$/], - loaders: [require.resolve('@storybook/addon-storysource/loader')], - include: [path.resolve(__dirname, '../src')], - enforce: 'pre', - }); - - return defaultConfig; +module.exports = { + module: { + rules: [ + { + test: [/\.stories\.js$/, /index\.js$/], + loaders: [require.resolve('@storybook/addon-storysource/loader')], + include: [path.resolve(__dirname, '../src')], + enforce: 'pre', + }, + ], + }, }; diff --git a/examples/vue-kitchen-sink/.storybook/webpack.config.js b/examples/vue-kitchen-sink/.storybook/webpack.config.js index 647e02ae0d4..92d286a488c 100644 --- a/examples/vue-kitchen-sink/.storybook/webpack.config.js +++ b/examples/vue-kitchen-sink/.storybook/webpack.config.js @@ -1,12 +1,14 @@ const path = require('path'); -module.exports = (storybookBaseConfig, configType, defaultConfig) => { - defaultConfig.module.rules.push({ - test: [/\.stories\.js$/, /index\.js$/], - loaders: [require.resolve('@storybook/addon-storysource/loader')], - include: [path.resolve(__dirname, '../src')], - enforce: 'pre', - }); - - return defaultConfig; +module.exports = { + module: { + rules: [ + { + test: [/\.stories\.js$/, /index\.js$/], + loaders: [require.resolve('@storybook/addon-storysource/loader')], + include: [path.resolve(__dirname, '../src')], + enforce: 'pre', + }, + ], + }, }; diff --git a/lib/core/src/server/preview/custom-webpack-preset.js b/lib/core/src/server/preview/custom-webpack-preset.js index 467d268902e..bd767c326db 100644 --- a/lib/core/src/server/preview/custom-webpack-preset.js +++ b/lib/core/src/server/preview/custom-webpack-preset.js @@ -3,40 +3,31 @@ import loadCustomWebpackConfig from '../utils/load-custom-webpack-config'; import mergeConfigs from '../utils/merge-webpack-config'; import { createDefaultWebpackConfig } from './base-webpack.config'; -function logConfigName(defaultConfigName) { - if (!defaultConfigName) { - logger.info('=> Using default webpack setup.'); - } else { - logger.info(`=> Using default webpack setup based on "${defaultConfigName}".`); - } -} - async function createFinalDefaultConfig(presets, config, options) { const defaultConfig = createDefaultWebpackConfig(config); return presets.apply('webpackFinal', defaultConfig, options); } export async function webpack(config, options) { - const { configDir, configType, defaultConfigName, presets } = options; + const { configDir, configType, presets } = options; - const finalConfig = await presets.apply('webpackFinal', config, options); + const finalDefaultConfig = await createFinalDefaultConfig(presets, config, options); // Check whether user has a custom webpack config file and // return the (extended) base configuration if it's not available. const customConfig = loadCustomWebpackConfig(configDir); if (customConfig === null) { - logConfigName(defaultConfigName); - return createFinalDefaultConfig(presets, config, options); + logger.info('=> Using default webpack setup.'); + return finalDefaultConfig; } if (typeof customConfig === 'function') { logger.info('=> Loading custom webpack config (full-control mode).'); - const finalDefaultConfig = await createFinalDefaultConfig(presets, config, options); - return customConfig(finalConfig, configType, finalDefaultConfig); + return customConfig({ config: finalDefaultConfig, configType }); } logger.info('=> Loading custom webpack config (extending mode).'); - return mergeConfigs(finalConfig, customConfig); + return mergeConfigs(finalDefaultConfig, customConfig); } From 1790d3b315f319b68a67c41327da0f66b66ade70 Mon Sep 17 00:00:00 2001 From: igor-dv Date: Wed, 5 Dec 2018 12:38:47 +0200 Subject: [PATCH 2/5] Rename configType to mode --- lib/core/src/server/preview/custom-webpack-preset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/src/server/preview/custom-webpack-preset.js b/lib/core/src/server/preview/custom-webpack-preset.js index bd767c326db..bf81ce25f16 100644 --- a/lib/core/src/server/preview/custom-webpack-preset.js +++ b/lib/core/src/server/preview/custom-webpack-preset.js @@ -24,7 +24,7 @@ export async function webpack(config, options) { if (typeof customConfig === 'function') { logger.info('=> Loading custom webpack config (full-control mode).'); - return customConfig({ config: finalDefaultConfig, configType }); + return customConfig({ config: finalDefaultConfig, mode: configType }); } logger.info('=> Loading custom webpack config (extending mode).'); From 0c9837c96dcb52f04ab16eebbff89e12d96cfdd5 Mon Sep 17 00:00:00 2001 From: igor-dv Date: Wed, 5 Dec 2018 12:48:07 +0200 Subject: [PATCH 3/5] Fix "angular-cli/.storybook/webpack.config.ts" --- .../angular-cli/.storybook/webpack.config.ts | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/examples/angular-cli/.storybook/webpack.config.ts b/examples/angular-cli/.storybook/webpack.config.ts index e649449c1a5..952d18125f6 100644 --- a/examples/angular-cli/.storybook/webpack.config.ts +++ b/examples/angular-cli/.storybook/webpack.config.ts @@ -1,19 +1,21 @@ const path = require('path'); -module.exports = (baseConfig: any) => { - baseConfig.module.rules.push({ - test: [/\.stories\.tsx?$/, /index\.ts$/], - loaders: [ +module.exports = { + module: { + rules: [ { - loader: require.resolve('@storybook/addon-storysource/loader'), - options: { - parser: 'typescript', - }, + test: [/\.stories\.tsx?$/, /index\.ts$/], + loaders: [ + { + loader: require.resolve('@storybook/addon-storysource/loader'), + options: { + parser: 'typescript', + }, + }, + ], + include: [path.resolve(__dirname, '../src')], + enforce: 'pre', }, ], - include: [path.resolve(__dirname, '../src')], - enforce: 'pre', - }); - - return baseConfig; + }, }; From 69b380f79e3a7c677cc381accacfc25bf427af9c Mon Sep 17 00:00:00 2001 From: igor-dv Date: Wed, 5 Dec 2018 16:24:02 +0200 Subject: [PATCH 4/5] Fix official example's custom webpack.config --- examples/official-storybook/webpack.config.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/official-storybook/webpack.config.js b/examples/official-storybook/webpack.config.js index 8238f7a937c..d3096cc29d6 100644 --- a/examples/official-storybook/webpack.config.js +++ b/examples/official-storybook/webpack.config.js @@ -1,12 +1,12 @@ const path = require('path'); const { DefinePlugin, ContextReplacementPlugin } = require('webpack'); -module.exports = async (baseConfig, env, defaultConfig) => ({ - ...defaultConfig, +module.exports = async ({ config }) => ({ + ...config, module: { - ...defaultConfig.module, + ...config.module, rules: [ - ...defaultConfig.module.rules, + ...config.module.rules, { test: /\.stories\.jsx?$/, use: require.resolve('@storybook/addon-storysource/loader'), @@ -19,7 +19,7 @@ module.exports = async (baseConfig, env, defaultConfig) => ({ }, { test: /\.js/, - use: defaultConfig.module.rules[0].use, + use: config.module.rules[0].use, include: [ path.resolve(__dirname, '../../app/react'), path.resolve(__dirname, '../../lib/ui/src'), @@ -29,12 +29,12 @@ module.exports = async (baseConfig, env, defaultConfig) => ({ ], }, resolve: { - ...defaultConfig.resolve, + ...config.resolve, // https://github.com/graphql/graphql-js#using-in-a-browser - extensions: ['.mjs', ...defaultConfig.resolve.extensions], + extensions: ['.mjs', ...config.resolve.extensions], }, plugins: [ - ...defaultConfig.plugins, + ...config.plugins, // graphql sources check process variable new DefinePlugin({ process: JSON.stringify(true), From 76ae1d4456e98ffe4f2099b7a3b6abbe16ceded4 Mon Sep 17 00:00:00 2001 From: igor-dv Date: Wed, 5 Dec 2018 16:30:54 +0200 Subject: [PATCH 5/5] Remove mjs from custom config. It's supported by default --- examples/official-storybook/webpack.config.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/official-storybook/webpack.config.js b/examples/official-storybook/webpack.config.js index d3096cc29d6..427eaab81fe 100644 --- a/examples/official-storybook/webpack.config.js +++ b/examples/official-storybook/webpack.config.js @@ -28,11 +28,6 @@ module.exports = async ({ config }) => ({ }, ], }, - resolve: { - ...config.resolve, - // https://github.com/graphql/graphql-js#using-in-a-browser - extensions: ['.mjs', ...config.resolve.extensions], - }, plugins: [ ...config.plugins, // graphql sources check process variable