Skip to content

Commit

Permalink
feat: support vue plugin in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Oct 30, 2022
1 parent 75188bf commit d4f1b18
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
13 changes: 0 additions & 13 deletions patches/@storybook__builder-vite@0.2.3.patch
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,3 @@ index 6a87782c2c4d88d0e7fa39c904b2eff78d591d1e..10b91b2b24d9c71300f6288eed697509
const storySourcePattern = /var __STORY__ = "(.*)"/;
const storySourceReplacement = '--STORY_SOURCE_REPLACEMENT--';
const mockClassLoader = (id) => ({ emitWarning: (message) => console.warn(message), resourcePath: id });
diff --git a/dist/vite-config.js b/dist/vite-config.js
index 37735b8e79b6c62f0ce66e53e48273e7ca175f49..bbf539d14a831019a6395a9b2ba3d830176d722e 100644
--- a/dist/vite-config.js
+++ b/dist/vite-config.js
@@ -132,7 +132,7 @@ async function pluginConfig(options, _type) {
if (framework === 'vue3') {
try {
const vuePlugin = require('@vitejs/plugin-vue');
- plugins.push(vuePlugin());
+ plugins.push(vuePlugin({exclude: [/\.stories\.vue$/]}));
}
catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
26 changes: 25 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@ import { createUnplugin } from 'unplugin'
import { transform as transformVue } from './core/transform'
import type { Options } from './types'

// We a custom type so that the vue plugin is ignoring the "main" import
const STORIES_INTERNAL_SUFFIX = '?vue&type=stories'
const STORIES_PUBLIC_SUFFIX = '.stories.vue'

export default createUnplugin<Options>(_options => ({
name: 'unplugin-starter',
enforce: 'pre',
async resolveId(source, importer, options) {
if (source.endsWith(STORIES_PUBLIC_SUFFIX)) {
// Determine what the actual entry would have been. We need "skipSelf"
// to avoid an infinite loop.
const resolution = await this.resolve(source, importer, { skipSelf: true, ...options })

// If it cannot be resolved or is external, just return it so that
// Rollup can display an error
if (!resolution || resolution.external)
return resolution

console.log('resolveIdStory', resolution)
return {
...resolution,
id: resolution.id + STORIES_INTERNAL_SUFFIX,
}
}
},
transformInclude(id) {
return id.endsWith('.stories.vue')
console.log('transformInclude', id)
return id.endsWith(STORIES_INTERNAL_SUFFIX)
},
transform(code) {
console.log('transform', code)
return transformVue(code)
},
}))

0 comments on commit d4f1b18

Please sign in to comment.