Skip to content

Commit

Permalink
fix: process exit after storybook build
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisVorop committed Feb 1, 2024
1 parent db64ada commit 14899e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
8 changes: 8 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { StorybookConfig } from '@storybook/react-vite';
import { defineConfig } from 'vite';
import { resolve } from 'node:path/posix';

import { exitProcessPlugin } from '../plugins/exitProcessPlugin';

const config: StorybookConfig = {
stories: [
'../src/**/*.mdx',
Expand Down Expand Up @@ -34,6 +36,12 @@ const config: StorybookConfig = {
};
}

const existingPlugins = config.build?.rollupOptions?.plugins as any[];

Check warning on line 39 in .storybook/main.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
config.build?.rollupOptions &&
(config.build.rollupOptions.plugins = existingPlugins
? [...existingPlugins, exitProcessPlugin()]
: [exitProcessPlugin()]);

return defineConfig({
...config,
assetsInclude: ['/sb-preview/runtime.js', '/dark.css', '/light.css'],
Expand Down
22 changes: 22 additions & 0 deletions plugins/exitProcessPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const exitProcessPlugin = () => {
return {
name: 'ExitProcessPlugin', // required, will show up in warnings and errors

// use this to catch errors when building
buildEnd(error) {
if(error) {
console.error('Error bundling')
console.error(error)
process.exit(1)
} else {
console.log('Build ended')
}
},

// use this to catch the end of a build without errors
closeBundle(id) {
console.log('Bundle closed')
process.exit(0)
},
}
}
27 changes: 2 additions & 25 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,7 @@ import { glob } from 'glob';
import react from '@vitejs/plugin-react';
import external from '@yelo/rollup-node-external';
import autoReExportPlugin from "unplugin-auto-re-export/vite";

const closePlugin = () => {
return {
name: 'ClosePlugin', // required, will show up in warnings and errors

// use this to catch errors when building
buildEnd(error) {
if(error) {
console.error('Error bundling')
console.error(error)
process.exit(1)
} else {
console.log('Build ended')
}
},

// use this to catch the end of a build without errors
closeBundle(id) {
console.log('Bundle closed')
process.exit(0)
},
}
}

import { exitProcessPlugin } from "./plugins/exitProcessPlugin";

const ignore = ['src/**/*.d.ts', 'src/**/*.stories.{ts,tsx}']

Expand Down Expand Up @@ -91,7 +68,7 @@ export default defineConfig({
'src/utils/stringToColor.*',
],
}),
closePlugin(),
exitProcessPlugin(),
],
},
minify: true,
Expand Down

0 comments on commit 14899e0

Please sign in to comment.