Skip to content

Commit

Permalink
feat: bundle dependencies (vue, etc.), closes #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jul 19, 2022
1 parent 5fff544 commit c019c9d
Show file tree
Hide file tree
Showing 54 changed files with 989 additions and 475 deletions.
2 changes: 1 addition & 1 deletion docs/guide/plugins/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Create a new npm package. Example `package.json`:
"devDependencies": {
"histoire": "^0.3.3",
"rimraf": "^3.0.0",
"typescript": "^4.6.3"
"typescript": "^4.7.4"
},
"peerDependencies": {
"histoire": "^0.3.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/vue3/cypress/integration/codegen-vue3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ describe('Codegen (Vue 3)', () => {
cy.get('[data-test-id="story-source-code"]').should('have.text', `<h1>Title</h1>
<hr>
<pre>{
"$data": {},
"object": {
"foo": "bar"
},
"$data": {},
"_hPropDefs": [],
"_hPropState": {}
}</pre>
<div data-test-id="object">
{
"$data": {},
"object": {
"foo": "bar"
},
"$data": {},
"_hPropDefs": [],
"_hPropState": {}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"postcss": "^8.4.12",
"rimraf": "^3.0.2",
"tailwindcss": "^3.0.23",
"typescript": "^4.6.3",
"typescript": "^4.7.4",
"vitepress": "^1.0.0-alpha.1"
},
"pnpm": {
Expand Down
6 changes: 2 additions & 4 deletions packages/histoire-controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
"story:preview": "histoire preview"
},
"dependencies": {
"@iconify/vue": "^3.2.1",
"@vueuse/core": "^8.2.5",
"floating-vue": "^2.0.0-beta.16"
"@histoire/vendors": "^0.7.9"
},
"devDependencies": {
"@peeky/test": "^0.13.5",
Expand All @@ -60,7 +58,7 @@
"postcss": "^8.4.12",
"postcss-import": "^14.1.0",
"tailwindcss": "^3.0.23",
"typescript": "^4.6.3",
"typescript": "^4.7.4",
"vite": "^2.9.1",
"vue": "^3.2.31",
"vue-tsc": "^0.35.2"
Expand Down
25 changes: 13 additions & 12 deletions packages/histoire-controls/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { App } from 'vue'
import HstCheckboxVue from './components/checkbox/HstCheckbox.vue'
import HstTextVue from './components/text/HstText.vue'
import HstNumberVue from './components/number/HstNumber.vue'
Expand All @@ -16,21 +15,23 @@ export const HstText = HstTextVue
export const HstNumber = HstNumberVue
export const HstSlider = HstSliderVue
export const HstTextarea = HstTextareaVue
export const HstSelect = HstSelectVue
export const HstColorShades = HstColorShadesVue
export const HstTokenList = HstTokenListVue
export const HstTokenGrid = HstTokenGridVue
export const HstCopyIcon = HstCopyIconVue
export const HstRadio = HstRadioVue

export function registerVueComponents (app: App) {
app.component('HstCheckbox', HstCheckboxVue)
app.component('HstText', HstTextVue)
app.component('HstNumber', HstNumberVue)
app.component('HstSlider', HstSliderVue)
app.component('HstSelect', HstSelectVue)
app.component('HstTextarea', HstTextareaVue)
app.component('HstColorShades', HstColorShadesVue)
app.component('HstTokenList', HstTokenListVue)
app.component('HstTokenGrid', HstTokenGridVue)
app.component('HstRadio', HstRadioVue)
export const components = {
HstCheckbox,
HstText,
HstNumber,
HstSlider,
HstTextarea,
HstSelect,
HstColorShades,
HstTokenList,
HstTokenGrid,
HstCopyIcon,
HstRadio,
}
11 changes: 11 additions & 0 deletions packages/histoire-controls/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
"strictFunctionTypes": true,
// Volar
"jsx": "preserve",
// Alias
"paths": {
"floating-vue": ["./node_modules/@histoire/vendors/dist/client/floating-vue"],
"@iconify/vue": ["./node_modules/@histoire/vendors/dist/client/iconify"],
"pinia": ["./node_modules/@histoire/vendors/dist/client/pinia"],
"scroll-into-view-if-needed": ["./node_modules/@histoire/vendors/dist/client/scroll"],
"shiki": ["./node_modules/@histoire/vendors/dist/client/shiki"],
"vue-router": ["./node_modules/@histoire/vendors/dist/client/vue-router"],
"@vueuse/core": ["./node_modules/@histoire/vendors/dist/client/vue-use"],
"vue": ["./node_modules/@histoire/vendors/dist/client/vue"]
}
},
"include": [
"src"
Expand Down
14 changes: 13 additions & 1 deletion packages/histoire-controls/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ export default defineConfig({
vue(),
],

resolve: {
alias: {
'floating-vue': '@histoire/vendors/dist/client/floating-vue.js',
'@iconify/vue': '@histoire/vendors/dist/client/iconify.js',
pinia: '@histoire/vendors/dist/client/pinia.js',
'scroll-into-view-if-needed': '@histoire/vendors/dist/client/scroll.js',
shiki: '@histoire/vendors/dist/client/shiki.js',
'vue-router': '@histoire/vendors/dist/client/vue-router.js',
'@vueuse/core': '@histoire/vendors/dist/client/vue-use.js',
vue: '@histoire/vendors/dist/client/vue.js',
},
},

build: {
emptyOutDir: false,

Expand All @@ -23,7 +36,6 @@ export default defineConfig({
rollupOptions: {
external: [
/@histoire/,
'vue',
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/histoire-plugin-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@nuxt/schema": "^3.0.0-rc.3",
"histoire": "workspace:*",
"typescript": "^4.6.3",
"typescript": "^4.7.4",
"vite": "^2.9.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/histoire-plugin-percy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"devDependencies": {
"histoire": "workspace:*",
"typescript": "^4.6.3"
"typescript": "^4.7.4"
},
"peerDependencies": {
"histoire": "^0.7.9"
Expand Down
2 changes: 1 addition & 1 deletion packages/histoire-plugin-screenshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"devDependencies": {
"histoire": "workspace:*",
"typescript": "^4.6.3"
"typescript": "^4.7.4"
},
"peerDependencies": {
"histoire": "^0.7.9"
Expand Down
11 changes: 5 additions & 6 deletions packages/histoire-plugin-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@
},
"scripts": {
"build": "rimraf dist && vite build && pnpm run build:types",
"build:types": "vue-tsc --declaration --emitDeclarationOnly",
"build:types": "tsc --declaration --emitDeclarationOnly",
"watch": "concurrently \"vite build --watch\" \"pnpm run build:types --watch\""
},
"dependencies": {
"@histoire/controls": "^0.7.9",
"@histoire/shared": "^0.7.9"
"@histoire/shared": "^0.7.9",
"@histoire/vendors": "^0.7.9"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.3.1",
"typescript": "^4.6.3",
"typescript": "^4.7.4",
"vite": "^2.9.1",
"vue": "^3.2.31",
"vue-tsc": "^0.35.2"
"vue": "^3.2.31"
},
"peerDependencies": {
"histoire": "^0.7.9",
Expand Down
81 changes: 81 additions & 0 deletions packages/histoire-plugin-vue/src/client/app/MountStoryVue3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* eslint-disable vue/one-component-per-file */

import { App, createApp, h, Suspense } from 'vue'
import {
defineComponent as _defineComponent,
PropType as _PropType,
onMounted as _onMounted,
onUnmounted as _onUnmounted,
ref as _ref,
watch as _watch,
h as _h,
} from '@histoire/vendors/dist/client/vue'
import type { Story } from '@histoire/shared'
import { registerGlobalComponents } from './global-components.js'
import { RouterLinkStub } from './RouterLinkStub'

export default _defineComponent({
name: 'MountStoryVue3',

props: {
story: {
type: Object as _PropType<Story>,
required: true,
},
},

setup (props) {
const el = _ref<HTMLDivElement>()
let app: App

async function mountStory () {
app = createApp({
name: 'MountStoryVue3',

render: () => {
return h(Suspense, [
h(props.story.file.component, {
story: props.story,
}),
])
},
})

registerGlobalComponents(app)

// Stubs
app.component('RouterLink', RouterLinkStub)

const target = document.createElement('div')
el.value.appendChild(target)
app.mount(target)
}

function unmountStory () {
app?.unmount()
}

_watch(() => props.story.id, async () => {
unmountStory()
await mountStory()
})

_onMounted(async () => {
await mountStory()
})

_onUnmounted(() => {
unmountStory()
})

return {
el,
}
},

render () {
return _h('div', {
ref: 'el',
})
},
})
46 changes: 0 additions & 46 deletions packages/histoire-plugin-vue/src/client/app/MountStoryVue3.vue

This file was deleted.

Loading

0 comments on commit c019c9d

Please sign in to comment.