Commit a47fac72 by Dominik Prokop Committed by GitHub

grafana/ui: Fix storybook dev (#25928)

* Minimize css and js only for storybook build

* Update CodeEditor story, make it internal

* Update storybook webpack config
parent 3651a8e9
...@@ -2,6 +2,7 @@ const path = require('path'); ...@@ -2,6 +2,7 @@ const path = require('path');
const TerserPlugin = require('terser-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = ({ config, mode }) => { module.exports = ({ config, mode }) => {
const isProductionBuild = mode === 'PRODUCTION';
config.module.rules = [ config.module.rules = [
...(config.module.rules || []), ...(config.module.rules || []),
{ {
...@@ -84,12 +85,6 @@ module.exports = ({ config, mode }) => { ...@@ -84,12 +85,6 @@ module.exports = ({ config, mode }) => {
chunks: 'all', chunks: 'all',
minChunks: 1, minChunks: 1,
cacheGroups: { cacheGroups: {
monaco: {
test: /[\\/]node_modules[\\/](monaco-editor)[\\/].*[jt]sx?$/,
chunks: 'initial',
priority: 20,
enforce: true,
},
vendors: { vendors: {
test: /[\\/]node_modules[\\/].*[jt]sx?$/, test: /[\\/]node_modules[\\/].*[jt]sx?$/,
chunks: 'initial', chunks: 'initial',
...@@ -105,11 +100,13 @@ module.exports = ({ config, mode }) => { ...@@ -105,11 +100,13 @@ module.exports = ({ config, mode }) => {
}, },
}, },
}, },
minimize: true, minimize: isProductionBuild,
minimizer: [ minimizer: isProductionBuild
new TerserPlugin({ cache: false, parallel: false, sourceMap: false, exclude: /monaco/ }), ? [
new OptimizeCSSAssetsPlugin({}), new TerserPlugin({ cache: false, parallel: false, sourceMap: false, exclude: /monaco/ }),
], new OptimizeCSSAssetsPlugin({}),
]
: [],
}; };
config.resolve.extensions.push('.ts', '.tsx', '.mdx'); config.resolve.extensions.push('.ts', '.tsx', '.mdx');
......
import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks'; import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
import { CodeEditor } from './CodeEditor'; import { CodeEditor } from './CodeEditorLazy';
<Meta title="MDX|CodeEditor" component={CodeEditor} /> <Meta title="MDX|CodeEditor" component={CodeEditor} />
# CodeEditor # CodeEditor
Monaco Code editor Monaco Code editor
\ No newline at end of file
import React from 'react'; import React from 'react';
import { text } from '@storybook/addon-knobs'; import { number, text } from '@storybook/addon-knobs';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
import mdx from './CodeEditor.mdx'; import mdx from './CodeEditor.mdx';
import CodeEditor from './CodeEditor'; import { CodeEditor } from './CodeEditorLazy';
const getKnobs = () => { const getKnobs = () => {
const CONTAINER_GROUP = 'Container options';
// ---
const containerWidth = number(
'Container width',
300,
{
range: true,
min: 100,
max: 500,
step: 10,
},
CONTAINER_GROUP
);
return { return {
containerWidth,
text: text('Body', 'SELECT * FROM table LIMIT 10'), text: text('Body', 'SELECT * FROM table LIMIT 10'),
language: text('Language', 'sql'), language: text('Language', 'sql'),
}; };
...@@ -24,17 +39,17 @@ export default { ...@@ -24,17 +39,17 @@ export default {
}; };
export const basic = () => { export const basic = () => {
const { text, language } = getKnobs(); const { containerWidth, text, language } = getKnobs();
return ( return (
<CodeEditor <CodeEditor
width={containerWidth}
height={400}
value={text} value={text}
language={language} language={language}
onBlur={(text: string) => { onBlur={(text: string) => {
console.log('Blur: ', text);
action('code blur')(text); action('code blur')(text);
}} }}
onSave={(text: string) => { onSave={(text: string) => {
console.log('Save: ', text);
action('code saved')(text); action('code saved')(text);
}} }}
/> />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment