Skip to content

Commit f39d60e

Browse files
Fixed conflicts
2 parents 5958827 + c1d07fd commit f39d60e

File tree

4 files changed

+72
-21
lines changed

4 files changed

+72
-21
lines changed

.storybook/build-static.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { readdirSync, writeFileSync, mkdirSync, existsSync, rmSync, cpSync } from 'fs';
2+
import path from 'path';
3+
4+
// Paths
5+
const distPath = path.resolve('dist/web-components');
6+
const staticPath = path.resolve('storybook-static');
7+
const iframePath = path.join(staticPath, 'iframe.html');
8+
9+
// 1️⃣ Clear previous static folder
10+
if (existsSync(staticPath)) rmSync(staticPath, { recursive: true });
11+
mkdirSync(staticPath, { recursive: true });
12+
13+
// 2️⃣ Copy web-components folder
14+
cpSync(distPath, path.join(staticPath, 'web-components'), { recursive: true });
15+
16+
// 3️⃣ Get all JS/CSS files in dist/web-components
17+
const files = readdirSync(distPath);
18+
const jsFiles = files.filter(f => f.endsWith('.js'));
19+
const cssFiles = files.filter(f => f.endsWith('.css'));
20+
21+
// 4️⃣ Generate iframe.html dynamically
22+
let iframeContent = `<!DOCTYPE html>
23+
<html lang="en">
24+
<head>
25+
<meta charset="UTF-8">
26+
<title>Stencil Storybook</title>
27+
`;
28+
29+
// Include CSS files
30+
cssFiles.forEach(file => {
31+
iframeContent += `<link rel="stylesheet" href="/web-components/${file}" />\n`;
32+
});
33+
34+
// Include JS files
35+
jsFiles.forEach(file => {
36+
iframeContent += `<script type="module" src="/web-components/${file}"></script>\n`;
37+
});
38+
39+
iframeContent += `</head>
40+
<body>
41+
<storybook-root></storybook-root>
42+
</body>
43+
</html>`;
44+
45+
// 5️⃣ Write iframe.html
46+
writeFileSync(iframePath, iframeContent, 'utf-8');
47+
48+
console.log('✅ Generated iframe.html with all JS/CSS files dynamically!');

.storybook/iframe.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Stencil Storybook</title>
6+
<!-- Include your compiled components -->
7+
<script type="module" src="/web-components/your-component.js"></script>
8+
<link rel="stylesheet" href="/web-components/your-component.css" />
9+
</head>
10+
<body>
11+
<storybook-root></storybook-root>
12+
</body>
13+
</html>

.storybook/main.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1+
import path from 'path';
2+
13
const config = {
24
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
35
addons: ['@storybook/addon-links', '@storybook/addon-docs'],
46
framework: {
5-
name: '@storybook/web-components-vite',
7+
name: '@stencil/storybook-plugin',
68
options: {},
79
},
8-
managerHead: (head: string) => `
9-
${head}
10-
<base href="./" />
11-
`,
12-
previewHead: (head: string) => `
13-
${head}
14-
<base href="./" />
15-
<script type="module">
16-
import { defineCustomElements } from '../dist/web-components/index.js';
17-
defineCustomElements();
18-
</script>
19-
`,
20-
typescript: {
21-
check: false,
22-
reactDocgen: 'react-docgen-typescript',
23-
reactDocgenTypescriptOptions: {
24-
shouldExtractLiteralValuesFromEnum: true,
25-
propFilter: (prop: any) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
26-
},
10+
staticDirs: ['../dist/web-components'], // <-- important
11+
webpackFinal: async config => {
12+
config.resolve.alias = {
13+
...config.resolve.alias,
14+
'@dist': path.resolve(__dirname, '../dist'),
15+
};
16+
return config;
2717
},
2818
};
2919

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"start": "yarn run build:dev --watch --serve",
8787
"storybook-build-tailwind": "npx ts-node .storybook/generate-safelist.ts && npx @tailwindcss/cli -i src/global/tailwind.css -o .storybook/tailwind.css --content '.storybook/tailwind-safelist.html' && rm -f .storybook/tailwind-safelist.html",
8888
"storybook-dev": "yarn run build && yarn run storybook-build-tailwind && storybook dev -p 6006 --no-open",
89-
"storybook-build": "yarn run build && yarn run storybook-build-tailwind && storybook build"
89+
"storybook-build": "NODE_ENV=production yarn build && yarn storybook-build-tailwind && storybook build && node .storybook/build-static.js"
9090
},
9191
"dependencies": {
9292
"@stencil/core": "^4.36.2",

0 commit comments

Comments
 (0)