Remove "defaultConfigName" prop and use "defaultConfig" as a single config to be extended

This commit is contained in:
igor-dv 2018-12-05 12:32:54 +02:00
parent 3a06253e01
commit cb15153810
12 changed files with 99 additions and 98 deletions

View File

@ -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'),

View File

@ -2,6 +2,5 @@ import packageJson from '../../package.json';
export default {
packageJson,
defaultConfigName: 'ember-cli',
frameworkPresets: [require.resolve('./framework-preset-babel-ember.js')],
};

View File

@ -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'),

View File

@ -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',
},
],
},
};

View File

@ -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',
},
],
},
};

View File

@ -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',
},
],
},
};

View File

@ -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',
},
],
},
};

View File

@ -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/)],
};

View File

@ -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',
},
],
},
};

View File

@ -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',
},
],
},
};

View File

@ -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',
},
],
},
};

View File

@ -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);
}