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

Vite: Add vue-vite framework for Vue2 #19230

Merged
merged 17 commits into from
Oct 3, 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
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 8
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -497,7 +497,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 8
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -513,7 +513,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 8
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -533,7 +533,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 8
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -549,7 +549,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 8
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -565,7 +565,7 @@ jobs:
executor:
class: medium+
name: sb_playwright
parallelism: 8
parallelism: 9
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand Down
4 changes: 2 additions & 2 deletions code/frameworks/react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
"ast-types": "^0.14.2",
"magic-string": "^0.26.1",
"react-docgen": "^6.0.0-alpha.3",
"vite": "3"
"vite": "^3.1.3"
},
"devDependencies": {
"@types/node": "^14.14.20 || ^16.0.0",
"typescript": "~4.6.3",
"vite": "^3.1.0"
"vite": "^3.1.3"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/react-vite/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const core: StorybookConfig['core'] = {
builder: '@storybook/builder-vite',
};

export function readPackageJson(): Record<string, any> | false {
function readPackageJson(): Record<string, any> | false {
const packageJsonPath = path.resolve('package.json');
if (!fs.existsSync(packageJsonPath)) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions code/frameworks/svelte-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
"magic-string": "^0.26.1",
"svelte": "^3.0.0",
"sveltedoc-parser": "^4.2.1",
"vite": "3"
"vite": "^3.1.3"
},
"devDependencies": {
"@types/node": "^14.14.20 || ^16.0.0",
"typescript": "~4.6.3",
"vite": "^3.1.0"
"vite": "^3.1.3"
},
"engines": {
"node": "^14.18 || >=16"
Expand Down
12 changes: 0 additions & 12 deletions code/frameworks/svelte-vite/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import path from 'path';
import fs from 'fs';
import type { StorybookConfig } from '@storybook/builder-vite';
import { svelteDocgen } from './plugins/svelte-docgen';

Expand All @@ -9,16 +7,6 @@ export const core: StorybookConfig['core'] = {
builder: '@storybook/builder-vite',
};

export function readPackageJson(): Record<string, any> | false {
const packageJsonPath = path.resolve('package.json');
if (!fs.existsSync(packageJsonPath)) {
return false;
}

const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');
return JSON.parse(jsonContent);
}

export const viteFinal: StorybookConfig['viteFinal'] = async (config, { presets }) => {
const { plugins = [] } = config;

Expand Down
48 changes: 48 additions & 0 deletions code/frameworks/vue-vite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Storybook for Vue and Vite

Storybook for Vue is a UI development environment for your Vue components.
With it, you can visualize different states of your UI components and develop them interactively.

![Storybook Screenshot](https://github.com/storybookjs/storybook/blob/main/media/storybook-intro.gif)

Storybook runs outside of your app.
So you can develop UI components in isolation without worrying about app specific dependencies and requirements.

## Getting Started

```sh
cd my-vue-app
npx storybook init
```

For more information visit: [storybook.js.org](https://storybook.js.org)

## Starter Storybook-for-Vue Boilerplate project with [Vuetify](https://github.com/vuetifyjs/vuetify) Material Component Framework

<https://github.com/white-rabbit-japan/vue-vuetify-storybook>

---

Storybook also comes with a lot of [addons](https://storybook.js.org/addons) and a great API to customize as you wish.
You can also build a [static version](https://storybook.js.org/docs/vue/sharing/publish-storybook) of your Storybook and deploy it anywhere you want.

## Vue Notes

- When using global custom components or extensions (e.g., `Vue.use`). You will need to declare those in the `./storybook/preview.js`.

## Known Limitations

In Storybook story and decorator components, you can not access the Vue instance
in factory functions for default prop values:

```js
{
props: {
foo: {
default() {
return this.bar; // does not work!
}
}
}
}
```
82 changes: 82 additions & 0 deletions code/frameworks/vue-vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@storybook/vue-vite",
"version": "7.0.0-alpha.33",
"description": "Storybook for Vue2 and Vite: Develop Vue2 Components in isolation with Hot Reloading.",
"keywords": [
"storybook"
],
"homepage": "https://github.com/storybookjs/storybook/tree/main/frameworks/vue-vite",
"bugs": {
"url": "https://github.com/storybookjs/storybook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/storybookjs/storybook.git",
"directory": "frameworks/vue-vite"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": {
"require": "./package.json",
"import": "./package.json",
"types": "./package.json"
}
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"README.md",
"*.js",
"*.d.ts"
],
"scripts": {
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/builder-vite": "7.0.0-alpha.33",
"@storybook/core-common": "7.0.0-alpha.33",
"@storybook/core-server": "7.0.0-alpha.33",
"@storybook/vue": "7.0.0-alpha.33",
"magic-string": "^0.26.1",
"vite": "^3.1.3",
"vue-docgen-api": "^4.40.0"
},
"devDependencies": {
"typescript": "~4.6.3",
"vue": "^2.7.10"
},
"peerDependencies": {
"vue": "^2.7.0"
},
"engines": {
"node": ">=10.13.0"
},
"publishConfig": {
"access": "public"
},
"bundler": {
"entries": [
"./src/index.ts",
"./src/preset.ts"
],
"platform": "node"
},
"gitHead": "5da5b0fabd04cc5cd5771e8242a960f05d03234a"
}
1 change: 1 addition & 0 deletions code/frameworks/vue-vite/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/preset');
2 changes: 2 additions & 0 deletions code/frameworks/vue-vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '@storybook/vue';
export type { StorybookConfig } from '@storybook/builder-vite';
27 changes: 27 additions & 0 deletions code/frameworks/vue-vite/src/plugins/vue-docgen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { parse } from 'vue-docgen-api';
import type { PluginOption } from 'vite';
import { createFilter } from 'vite';
import MagicString from 'magic-string';

export function vueDocgen(): PluginOption {
const include = /\.(vue)$/;
const filter = createFilter(include);

return {
name: 'storybook:vue-docgen-plugin',

async transform(src: string, id: string) {
if (!filter(id)) return undefined;

const metaData = await parse(id);
const metaSource = JSON.stringify(metaData);
const s = new MagicString(src);
s.append(`;_sfc_main.__docgenInfo = ${metaSource}`);

return {
code: s.toString(),
map: s.generateMap({ hires: true, source: id }),
};
},
};
}
44 changes: 44 additions & 0 deletions code/frameworks/vue-vite/src/preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import path from 'path';
import type { PresetProperty } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/builder-vite';
import { vueDocgen } from './plugins/vue-docgen';

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
const framework = await options.presets.apply<StorybookConfig['framework']>('framework');

return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-vite', 'package.json'))
) as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework?.options.builder || {},
},
};
};

export const addons: StorybookConfig['addons'] = ['@storybook/vue'];

export const typescript: PresetProperty<'typescript', StorybookConfig> = async (config) => ({
...config,
skipBabel: true,
});

export const viteFinal: StorybookConfig['viteFinal'] = async (config, { presets }) => {
const { plugins = [] } = config;

plugins.push(vueDocgen());

const updated = {
...config,
plugins,
resolve: {
...config.resolve,
alias: {
...config.resolve?.alias,
vue: 'vue/dist/vue.esm.js',
},
},
};
return updated;
};
9 changes: 9 additions & 0 deletions code/frameworks/vue-vite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
"exclude": ["src/**/*.test.*"]
}
4 changes: 2 additions & 2 deletions code/frameworks/vue3-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
"@storybook/vue3": "7.0.0-alpha.33",
"@vitejs/plugin-vue": "^3.0.3",
"magic-string": "^0.26.1",
"vite": "3",
"vite": "^3.1.3",
"vue-docgen-api": "^4.40.0"
},
"devDependencies": {
"@types/node": "^14.14.20 || ^16.0.0",
"typescript": "~4.6.3",
"vite": "^3.1.0"
"vite": "^3.1.3"
},
"engines": {
"node": "^14.18 || >=16"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/vue3-vite/preset.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
console.log('vue3-vite preset!');
module.exports = require('./dist/preset');
4 changes: 2 additions & 2 deletions code/lib/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
"glob-promise": "^4.2.0",
"magic-string": "^0.26.1",
"slash": "^3.0.0",
"vite": "3"
"vite": "^3.1.3"
},
"devDependencies": {
"@storybook/mdx2-csf": "^0.0.3",
"@types/express": "^4.17.13",
"@types/node": "^17.0.23",
"typescript": "~4.6.3",
"vite": "^3.1.0"
"vite": "^3.1.3"
},
"peerDependencies": {
"@storybook/mdx2-csf": "^0.0.3"
Expand Down
11 changes: 0 additions & 11 deletions code/lib/builder-vite/src/vite-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as path from 'path';
import fs from 'fs';
import { loadConfigFromFile, mergeConfig } from 'vite';
import type {
ConfigEnv,
Expand All @@ -20,16 +19,6 @@ import type { ExtendedOptions, EnvsRaw } from './types';

export type PluginConfigType = 'build' | 'development';

export function readPackageJson(): Record<string, any> | false {
const packageJsonPath = path.resolve('package.json');
if (!fs.existsSync(packageJsonPath)) {
return false;
}

const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');
return JSON.parse(jsonContent);
}

const configEnvServe: ConfigEnv = {
mode: 'development',
command: 'serve',
Expand Down
Loading