Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Refactor core and frameworks to work with presets #4043

Merged
merged 19 commits into from
Sep 3, 2018
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Get rid of wrapDefaultBabelConfig
igor-dv committed Aug 24, 2018
commit 12426fad9ec010a4caa298ba6a26db69b63eb26d
13 changes: 13 additions & 0 deletions app/mithril/src/server/framework-preset-mithril.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mergeBabel } from '@storybook/core/server';

function extendBabel(config) {
const patch = {
plugins: [require.resolve('@babel/plugin-transform-react-jsx')],
};

return mergeBabel(patch, config);
}

export default {
extendBabel,
};
4 changes: 1 addition & 3 deletions app/mithril/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapDefaultBabelConfig from './wrapDefaultBabelConfig';

export default {
packageJson,
wrapDefaultBabelConfig,
frameworkPresets: [require.resolve('./framework-preset-mithril.js')],
};
4 changes: 0 additions & 4 deletions app/mithril/src/server/wrapDefaultBabelConfig.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function(config) {
function extendBabel(config) {
// Ensure plugins are defined or fallback to an array to avoid empty values.
const babelConfigPlugins = config.plugins || [];

@@ -18,3 +18,7 @@ export default function(config) {
plugins: [].concat(babelConfigPlugins, extraPlugins),
};
}

export default {
extendBabel,
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import wrapBabelConfig from './wrapBabelConfig';
import preset from './framework-preset-react-docgen';

describe('babel_config', () => {
describe('framework-preset-react-docgen', () => {
const babelPluginReactDocgenPath = require.resolve('babel-plugin-react-docgen');

it('should return the config with the extra plugins when `plugins` is an array.', () => {
@@ -10,7 +10,7 @@ describe('babel_config', () => {
plugins: ['foo-plugin'],
};

const config = wrapBabelConfig(babelConfig);
const config = preset.extendBabel(babelConfig);

expect(config).toEqual({
babelrc: false,
@@ -34,7 +34,7 @@ describe('babel_config', () => {
plugins: 'bar-plugin',
};

const config = wrapBabelConfig(babelConfig);
const config = preset.extendBabel(babelConfig);

expect(config).toEqual({
babelrc: false,
@@ -57,7 +57,7 @@ describe('babel_config', () => {
presets: ['env', 'foo-preset'],
};

const config = wrapBabelConfig(babelConfig);
const config = preset.extendBabel(babelConfig);

expect(config).toEqual({
babelrc: false,
8 changes: 6 additions & 2 deletions app/react/src/server/framework-preset-react.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import wrapBabelConfig from './wrapBabelConfig';
import { mergeBabel } from '@storybook/core/server';

function extendBabel(config) {
return wrapBabelConfig(config);
const patch = {
presets: [require.resolve('@babel/preset-react'), require.resolve('@babel/preset-flow')],
};

return mergeBabel(patch, config);
}

export default {
8 changes: 4 additions & 4 deletions app/react/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import packageJson from '../../package.json';

import wrapDefaultBabelConfig from './wrapDefaultBabelConfig';

export default {
packageJson,
defaultConfigName: 'create-react-app',
frameworkPresets: [require.resolve('./framework-preset-react.js')],
wrapDefaultBabelConfig,
frameworkPresets: [
require.resolve('./framework-preset-react.js'),
require.resolve('./framework-preset-react-docgen.js'),
],
};
8 changes: 0 additions & 8 deletions app/react/src/server/wrapDefaultBabelConfig.js

This file was deleted.

56 changes: 34 additions & 22 deletions app/vue/src/server/framework-preset-vue.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
const VueLoaderPlugin = require('vue-loader/lib/plugin');
import VueLoaderPlugin from 'vue-loader/lib/plugin';
import { mergeBabel } from '@storybook/core/server';

const extendWebpack = config => ({
...config,
plugins: [...config.plugins, new VueLoaderPlugin()],
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.vue$/,
loader: require.resolve('vue-loader'),
options: {},
function extendWebpack(config) {
return {
...config,
plugins: [...config.plugins, new VueLoaderPlugin()],
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.vue$/,
loader: require.resolve('vue-loader'),
options: {},
},
],
},
resolve: {
...config.resolve,
extensions: [...config.resolve.extensions, '.vue'],
alias: {
...config.resolve.alias,
vue$: require.resolve('vue/dist/vue.esm.js'),
},
],
},
resolve: {
...config.resolve,
extensions: [...config.resolve.extensions, '.vue'],
alias: {
...config.resolve.alias,
vue$: require.resolve('vue/dist/vue.esm.js'),
},
},
});
};
}

function extendBabel(config) {
const patch = {
presets: [require.resolve('babel-preset-vue')],
};

return mergeBabel(patch, config);
}

export default {
extendWebpack,
extendBabel,
};
2 changes: 0 additions & 2 deletions app/vue/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';
import wrapDefaultBabelConfig from './wrapDefaultBabelConfig';

export default {
packageJson,
wrapDefaultBabelConfig,
frameworkPresets: [require.resolve('./framework-preset-vue.js')],
};
4 changes: 0 additions & 4 deletions app/vue/src/server/wrapDefaultBabelConfig.js

This file was deleted.

6 changes: 1 addition & 5 deletions lib/core/src/server/config.js
Original file line number Diff line number Diff line change
@@ -2,16 +2,12 @@ import path from 'path';
import loadPresets from './presets';
import serverRequire from './serverRequire';

const noopWrapper = config => config;

function customPreset({ configDir }) {
return serverRequire(path.resolve(configDir, 'presets')) || [];
}

function getWebpackConfig(options, presets) {
const { configDir, wrapDefaultBabelConfig = noopWrapper } = options;

const babelOptions = presets.extendBabel({}, { configDir, wrapDefaultBabelConfig });
const babelOptions = presets.extendBabel({}, options);

const entries = {
iframe: presets.extendPreview([], options),
4 changes: 2 additions & 2 deletions lib/core/src/server/core-preset-dev.js
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ function extendWebpack(_, options) {
return createDevConfig(options);
}

function extendBabel(_, { configDir, wrapDefaultBabelConfig }) {
return loadCustomBabelConfig(configDir) || wrapDefaultBabelConfig(defaultBabelConfig);
function extendBabel(_, { configDir }) {
return loadCustomBabelConfig(configDir) || defaultBabelConfig;
}

function extendManager(_, options) {
4 changes: 2 additions & 2 deletions lib/core/src/server/core-preset-prod.js
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ function extendWebpack(_, options) {
return createProdConfig(options);
}

function extendBabel(_, { configDir, wrapDefaultBabelConfig }) {
return loadCustomBabelConfig(configDir) || wrapDefaultBabelConfig(defaultBabelConfig);
function extendBabel(_, { configDir }) {
return loadCustomBabelConfig(configDir) || defaultBabelConfig;
}

function extendManager(_, options) {