Addon-docs: cleanup dead preset code

This commit is contained in:
Michael Shilman 2019-08-02 23:40:32 +08:00
parent 690b490227
commit a9ff392cf9
2 changed files with 1 additions and 100 deletions

View File

@ -1,20 +0,0 @@
const fs = require('fs');
const common = require('./preset');
module.exports = framework => {
const frameworkConfig = `${__dirname}/../${framework}/config.js`;
const preConfig = fs.existsSync(frameworkConfig) ? [frameworkConfig] : [];
function config(entry = []) {
return [...preConfig, ...entry];
}
const configureJSX = framework !== 'react';
const webpack = (webpackConfig, options) =>
common.webpack(webpackConfig, { configureJSX, ...options });
return {
...common,
webpack,
config,
};
};

View File

@ -1,80 +1 @@
const createCompiler = require('../mdx-compiler-plugin');
function createBabelOptions({ babelOptions, configureJSX }) {
if (!configureJSX) {
return babelOptions;
}
const babelPlugins = (babelOptions && babelOptions.plugins) || [];
return {
...babelOptions,
// for frameworks that are not working with react, we need to configure
// the jsx to transpile mdx, for now there will be a flag for that
// for more complex solutions we can find alone that we need to add '@babel/plugin-transform-react-jsx'
plugins: [...babelPlugins, '@babel/plugin-transform-react-jsx'],
};
}
function webpack(webpackConfig = {}, options = {}) {
const { module = {} } = webpackConfig;
// it will reuse babel options that are already in use in storybook
// also, these babel options are chained with other presets.
const { babelOptions, configureJSX, sourceLoaderOptions = {} } = options;
// set `sourceLoaderOptions` to `null` to disable for manual configuration
const sourceLoader = sourceLoaderOptions
? [
{
test: /\.(stories|story)\.[tj]sx?$/,
loader: require.resolve('@storybook/source-loader'),
options: sourceLoaderOptions,
enforce: 'pre',
},
]
: [];
return {
...webpackConfig,
module: {
...module,
rules: [
...(module.rules || []),
{
test: /\.(stories|story).mdx$/,
use: [
{
loader: 'babel-loader',
options: createBabelOptions({ babelOptions, configureJSX }),
},
{
loader: '@mdx-js/loader',
options: {
compilers: [createCompiler(options)],
},
},
],
},
{
test: /\.mdx$/,
exclude: /\.(stories|story).mdx$/,
use: [
{
loader: 'babel-loader',
options: createBabelOptions({ babelOptions, configureJSX }),
},
{
loader: '@mdx-js/loader',
},
],
},
...sourceLoader,
],
},
};
}
function addons(entry = []) {
return [...entry, require.resolve('../register')];
}
module.exports = { webpack, addons };
module.exports = require('../dist/frameworks/common/preset');