Skip to content

Commit

Permalink
Merge pull request #45 from schalk-b/31-improve-iframe-building
Browse files Browse the repository at this point in the history
Fixes #31

Fix windows build
  • Loading branch information
IanVS authored Jun 28, 2021
2 parents d8a583b + 2544038 commit b3b075b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/storybook-builder-vite/code-generator-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { generateIframeScriptCode } = require('./codegen-iframe-script');

module.exports.codeGeneratorPlugin = function codeGeneratorPlugin(options) {
const virtualFileId = '/virtual:/@storybook/builder-vite/vite-app.js';
let iframeId
return {
name: 'storybook-vite-code-generator-plugin',
enforce: 'pre',
Expand All @@ -26,29 +27,30 @@ module.exports.codeGeneratorPlugin = function codeGeneratorPlugin(options) {
// does not support virtual files as entry points.
if (command === 'build') {
config.build.rollupOptions = {
input: {
'iframe.html': 'iframe.html'
}
input: 'iframe.html'
};
}
},
configResolved(config) {
iframeId = `${config.root}/iframe.html`
},
resolveId(source) {
if (source === virtualFileId) {
return virtualFileId;
} else if (source === 'iframe.html') {
return 'iframe.html';
return iframeId;
}
},
async load(id) {
if (id === virtualFileId) {
return generateIframeScriptCode(options);
}
if (id === 'iframe.html') {
if (id === iframeId) {
return fs.readFileSync(path.resolve(__dirname, 'input', 'iframe.html'), 'utf-8');
}
},
async transformIndexHtml(html, ctx) {
if (!ctx.path.endsWith('/iframe.html')) {
if (ctx.path === '/iframe.html') {
return;
}
return transformIframeHtml(html, options);
Expand Down

0 comments on commit b3b075b

Please sign in to comment.