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

Build: tsup to build vite-builder #19895

Merged
merged 8 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
49 changes: 45 additions & 4 deletions code/lib/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,42 @@
"version": "7.0.0-alpha.51",
"description": "A plugin to run and build Storybooks with Vite",
"homepage": "https://github.com/storybookjs/storybook/tree/main/code/lib/builder-vite/#readme",
"bugs": {
"url": "https://github.com/storybookjs/storybook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/storybookjs/storybook.git",
"directory": "code/lib/builder-vite"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"author": "Eirik Sletteberg",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./input/iframe.html": "./input/iframe.html",
"./input/react-dom-client-placeholder.js": "./input/react-dom-client-placeholder.js",
"./package.json": "./package.json"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"input/**/*",
"*.js",
"*.d.ts"
],
"scripts": {
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@joshwooding/vite-plugin-react-docgen-typescript": "0.0.5",
Expand All @@ -42,8 +65,26 @@
"typescript": "^4.9.3",
"vite": "^3.1.3"
},
"peerDependencies": {
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
"@preact/preset-vite": "*",
"vite-plugin-glimmerx": "*"
},
"peerDependenciesMeta": {
"@preact/preset-vite": {
"optional": true
},
"vite-plugin-glimmerx": {
"optional": true
}
},
"publishConfig": {
"access": "public"
},
"bundler": {
"entries": [
"./src/index.ts"
],
"platform": "node"
},
"gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded"
}
3 changes: 1 addition & 2 deletions code/lib/builder-vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// noinspection JSUnusedGlobalSymbols

import * as fs from 'fs';
import * as path from 'path';
import type { Builder, StorybookConfig as StorybookBaseConfig, Options } from '@storybook/types';
import type { RequestHandler, Request, Response } from 'express';
import type { InlineConfig, UserConfig, ViteDevServer } from 'vite';
Expand Down Expand Up @@ -46,7 +45,7 @@ function iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): Requ
}

const indexHtml = fs.readFileSync(
path.resolve(__dirname, '../..', 'input', 'iframe.html'),
require.resolve('@storybook/builder-vite/input/iframe.html'),
'utf-8'
);
const generated = await transformIframeHtml(indexHtml, options);
Expand Down
14 changes: 5 additions & 9 deletions code/lib/builder-vite/src/plugins/code-generator-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-param-reassign */

import * as fs from 'fs';
import * as path from 'path';
import { mergeConfig } from 'vite';
import type { Plugin } from 'vite';
import { transformIframeHtml } from '../transform-iframe-html';
Expand All @@ -21,7 +20,7 @@ import {
} from '../virtual-file-names';

export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {
const iframePath = path.resolve(__dirname, '../../..', 'input', 'iframe.html');
const iframePath = require.resolve('@storybook/builder-vite/input/iframe.html');
let iframeId: string;

// noinspection JSUnusedGlobalSymbols
Expand All @@ -44,7 +43,7 @@ export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {

// Adding new story files is not covered by the change event above. So we need to detect this and trigger
// HMR to update the importFn.
// eslint-disable-next-line @typescript-eslint/no-shadow

server.watcher.on('add', (path) => {
// TODO maybe use the stories declaration in main
if (/\.stories\.([tj])sx?$/.test(path) || /\.(story|stories).mdx$/.test(path)) {
Expand Down Expand Up @@ -75,11 +74,8 @@ export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {
if (isNodeError(e) && e.code === 'MODULE_NOT_FOUND') {
config.resolve = mergeConfig(config.resolve ?? {}, {
alias: {
'react-dom/client': path.resolve(
__dirname,
'../../..',
'input',
'react-dom-client-placeholder.js'
'react-dom/client': require.resolve(
'@storybook/builder-vite/input/react-dom-client-placeholder.js'
),
},
});
Expand Down Expand Up @@ -133,7 +129,7 @@ export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {

if (id === iframeId) {
return fs.readFileSync(
path.resolve(__dirname, '../../..', 'input', 'iframe.html'),
require.resolve('@storybook/builder-vite/input/iframe.html'),
'utf-8'
);
}
Expand Down
8 changes: 8 additions & 0 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5887,6 +5887,14 @@ __metadata:
slash: ^3.0.0
typescript: ^4.9.3
vite: ^3.1.3
peerDependencies:
"@preact/preset-vite": "*"
vite-plugin-glimmerx: "*"
peerDependenciesMeta:
"@preact/preset-vite":
optional: true
vite-plugin-glimmerx:
optional: true
languageName: unknown
linkType: soft

Expand Down