Skip to content

Commit

Permalink
Merge pull request #4027 from storybooks/core/presets
Browse files Browse the repository at this point in the history
Presets support
  • Loading branch information
pksunkara authored Sep 6, 2018
2 parents f655aa7 + e6972e7 commit b2b7359
Show file tree
Hide file tree
Showing 55 changed files with 764 additions and 353 deletions.
17 changes: 17 additions & 0 deletions app/angular/src/server/framework-preset-angular-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { logger } from '@storybook/node-logger';

import {
getAngularCliWebpackConfigOptions,
applyAngularCliWebpackConfig,
} from './angular-cli_config';

export function webpack(config) {
const cwd = process.cwd();
const cliWebpackConfigOptions = getAngularCliWebpackConfigOptions(cwd);

if (cliWebpackConfigOptions) {
logger.info('=> Loading angular-cli config.');
}

return applyAngularCliWebpackConfig(config, cliWebpackConfigOptions);
}
50 changes: 50 additions & 0 deletions app/angular/src/server/framework-preset-angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from 'path';
import { ContextReplacementPlugin } from 'webpack';
import loadTsConfig from './ts_config';

export function webpack(config, { configDir }) {
return {
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.tsx?$/,
use: [
{
loader: require.resolve('ts-loader'),
options: loadTsConfig(configDir),
},
require.resolve('angular2-template-loader'),
],
},
{
test: /[/\\]@angular[/\\]core[/\\].+\.js$/,
parser: { system: true },
},
{
test: /\.html$/,
loader: 'raw-loader',
exclude: /\.async\.html$/,
},
{
test: /\.scss$/,
use: [require.resolve('raw-loader'), require.resolve('sass-loader')],
},
],
},
resolve: {
...config.resolve,
extensions: [...config.resolve.extensions, '.ts', '.tsx'],
},
plugins: [
...config.plugins,
// See https://github.com/angular/angular/issues/11580#issuecomment-401127742
new ContextReplacementPlugin(
/@angular(\\|\/)core(\\|\/)fesm5/,
path.resolve(__dirname, '..')
),
],
};
}
22 changes: 4 additions & 18 deletions app/angular/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
import { logger } from '@storybook/node-logger';

import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

import {
getAngularCliWebpackConfigOptions,
applyAngularCliWebpackConfig,
} from './angular-cli_config';

const cliWebpackConfigOptions = getAngularCliWebpackConfigOptions(process.cwd());

if (cliWebpackConfigOptions) {
logger.info('=> Loading angular-cli config.');
}

export default {
packageJson,
defaultConfigName: 'angular-cli',
wrapInitialConfig,
wrapDefaultConfig: config => applyAngularCliWebpackConfig(config, cliWebpackConfigOptions),
wrapBasicConfig: config => applyAngularCliWebpackConfig(config, cliWebpackConfigOptions),
frameworkPresets: [
require.resolve('./framework-preset-angular.js'),
require.resolve('./framework-preset-angular-cli.js'),
],
};
45 changes: 0 additions & 45 deletions app/angular/src/server/wrapInitialConfig.js

This file was deleted.

19 changes: 19 additions & 0 deletions app/html/src/server/framework-preset-html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function webpack(config) {
return {
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.html$/,
use: [
{
loader: require.resolve('html-loader'),
},
],
},
],
},
};
}
4 changes: 1 addition & 3 deletions app/html/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

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

This file was deleted.

19 changes: 19 additions & 0 deletions app/marko/src/server/framework-preset-marko.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function webpack(config) {
return {
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.marko$/,
loader: require.resolve('marko-loader'),
},
],
},
resolve: {
...config.resolve,
extensions: [...config.resolve.extensions, '.marko'],
},
};
}
4 changes: 1 addition & 3 deletions app/marko/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

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

This file was deleted.

9 changes: 9 additions & 0 deletions app/mithril/src/server/framework-preset-mithril.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { mergeBabel } from '@storybook/core/server';

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

return mergeBabel(patch, config);
}
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.

28 changes: 28 additions & 0 deletions app/polymer/src/server/framework-preset-polymer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { IgnorePlugin } from 'webpack';

export function webpack(config) {
return {
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.html$/,
use: [
...config.module.rules[0].use,
{
loader: require.resolve('polymer-webpack-loader'),
options: { processStyleLinks: true },
},
],
},
],
},
plugins: [
...config.plugins,
// See https://github.com/webcomponents/webcomponentsjs/issues/794#issuecomment-386554298
new IgnorePlugin(/^vertx$/),
],
};
}
4 changes: 1 addition & 3 deletions app/polymer/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

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

This file was deleted.

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import wrapBabelConfig from './wrapBabelConfig';
import * as 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.', () => {
Expand All @@ -10,7 +10,7 @@ describe('babel_config', () => {
plugins: ['foo-plugin'],
};

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

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

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

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

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

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

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

return mergeBabel(patch, config);
}
9 changes: 4 additions & 5 deletions app/react/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import packageJson from '../../package.json';

import wrapBabelConfig from './wrapBabelConfig';
import wrapDefaultBabelConfig from './wrapDefaultBabelConfig';

export default {
packageJson,
defaultConfigName: 'create-react-app',
wrapDefaultBabelConfig,
wrapBabelConfig,
frameworkPresets: [
require.resolve('./framework-preset-react.js'),
require.resolve('./framework-preset-react-docgen.js'),
],
};
Loading

0 comments on commit b2b7359

Please sign in to comment.