Skip to content

Commit 1e20df1

Browse files
Builder-Vite: Fix missing source map warning
1 parent 1ebcb33 commit 1e20df1

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

code/builders/builder-vite/src/codegen-modern-iframe-script.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function generateModernIframeScriptCode(options: Options, projectRo
4545

4646
return `
4747
if (import.meta.hot) {
48-
import.meta.hot.accept('${virtualStoriesFile}', (newModule) => {
48+
import.meta.hot.accept('\0${virtualStoriesFile}', (newModule) => {
4949
// importFn has changed so we need to patch the new one in
5050
window.__STORYBOOK_PREVIEW__.onStoriesChanged({ importFn: newModule.importFn });
5151
});

code/builders/builder-vite/src/plugins/code-generator-plugin.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export function codeGeneratorPlugin(options: Options): Plugin {
2828
// invalidate the whole vite-app.js script on every file change.
2929
// (this might be a little too aggressive?)
3030
server.watcher.on('change', () => {
31-
const appModule = server.moduleGraph.getModuleById(virtualFileId);
31+
const appModule = server.moduleGraph.getModuleById(`\0${virtualFileId}`);
3232
if (appModule) {
3333
server.moduleGraph.invalidateModule(appModule);
3434
}
35-
const storiesModule = server.moduleGraph.getModuleById(virtualStoriesFile);
35+
const storiesModule = server.moduleGraph.getModuleById(`\0${virtualStoriesFile}`);
3636
if (storiesModule) {
3737
server.moduleGraph.invalidateModule(storiesModule);
3838
}
@@ -70,33 +70,34 @@ export function codeGeneratorPlugin(options: Options): Plugin {
7070
},
7171
resolveId(source) {
7272
if (source === virtualFileId) {
73-
return `${virtualFileId}`;
73+
return `\0${virtualFileId}`;
7474
}
7575
if (source === iframePath) {
7676
return iframeId;
7777
}
7878
if (source === virtualStoriesFile) {
79-
return `${virtualStoriesFile}`;
79+
return `\0${virtualStoriesFile}`;
8080
}
8181
if (source === virtualPreviewFile) {
82-
return virtualPreviewFile;
82+
return `\0${virtualPreviewFile}`;
8383
}
8484
if (source === virtualAddonSetupFile) {
85-
return `${virtualAddonSetupFile}`;
85+
return `\0${virtualAddonSetupFile}`;
8686
}
8787

8888
return undefined;
8989
},
9090
async load(id, config) {
91-
if (id === `${virtualStoriesFile}`) {
91+
if (id === `\0${virtualStoriesFile}`) {
9292
return generateImportFnScriptCode(options);
9393
}
9494

95-
if (id === `${virtualAddonSetupFile}`) {
95+
if (id === `\0${virtualAddonSetupFile}`) {
9696
return generateAddonSetupCode();
9797
}
9898

99-
if (id === `${virtualFileId}`) {
99+
if (id === `\0${virtualFileId}`) {
100+
console.log('loaded', id);
100101
return generateModernIframeScriptCode(options, projectRoot);
101102
}
102103

code/builders/builder-vite/src/plugins/webpack-stats-plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function pluginWebpackStats({ workingDir }: WebpackStatsPluginOptions): W
5050
/** Convert an absolute path name to a path relative to the vite root, with a starting `./` */
5151
function normalize(filename: string) {
5252
// Do not try to resolve virtual files
53-
if (filename.startsWith('/virtual:')) {
53+
if (filename.startsWith('/virtual:') || filename.startsWith('\0/virtual:')) {
5454
return filename;
5555
}
5656
// Otherwise, we need them in the format `./path/to/file.js`.

code/frameworks/vue3-vite/src/plugins/vue-component-meta.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function vueComponentMeta(tsconfigPath = 'tsconfig.json'): Promise<
2626

2727
// exclude stories, virtual modules and storybook internals
2828
const exclude =
29-
/\.stories\.(ts|tsx|js|jsx)$|^\/virtual:|^\/sb-preview\/|\.storybook\/.*\.(ts|js)$/;
29+
/\.stories\.(ts|tsx|js|jsx)$|^\0\/virtual:|^\/virtual:|^\/sb-preview\/|\.storybook\/.*\.(ts|js)$/;
3030
const include = /\.(vue|ts|js|tsx|jsx)$/;
3131
const filter = createFilter(include, exclude);
3232

0 commit comments

Comments
 (0)