@pure-ds/storybook 0.3.15 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/main.js +11 -5
- package/package.json +1 -1
package/.storybook/main.js
CHANGED
|
@@ -160,21 +160,27 @@ const config = {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
// Support absolute path imports like: import { html } from '/assets/js/lit.js';
|
|
163
|
-
// Vite blocks direct imports from public/, so we
|
|
164
|
-
//
|
|
163
|
+
// Vite blocks direct imports from public/, so we disable Vite's public directory
|
|
164
|
+
// handling (Storybook uses staticDirs instead) and resolve these imports ourselves.
|
|
165
165
|
const userPublicPath = resolve(process.cwd(), 'public');
|
|
166
166
|
const isConsumerProject = process.cwd() !== resolve(currentDirname, '..');
|
|
167
167
|
|
|
168
168
|
if (isConsumerProject && fs.existsSync(userPublicPath)) {
|
|
169
|
+
// Disable Vite's public directory to prevent "Cannot import non-asset file" errors
|
|
170
|
+
// Storybook's staticDirs handles serving public files at runtime
|
|
171
|
+
config.publicDir = false;
|
|
172
|
+
|
|
169
173
|
config.plugins = config.plugins || [];
|
|
170
|
-
|
|
174
|
+
// Insert at the beginning to run before other plugins
|
|
175
|
+
config.plugins.unshift({
|
|
171
176
|
name: 'pds-public-esm-loader',
|
|
172
|
-
|
|
177
|
+
enforce: 'pre', // Run before Vite's built-in plugins
|
|
178
|
+
resolveId(id, importer) {
|
|
173
179
|
// Handle absolute paths starting with /assets/ or other paths in public
|
|
174
180
|
if (id.startsWith('/') && !id.startsWith('/@') && !id.startsWith('/node_modules')) {
|
|
175
181
|
const filePath = resolve(userPublicPath, id.slice(1)); // Remove leading /
|
|
176
182
|
if (fs.existsSync(filePath) && (filePath.endsWith('.js') || filePath.endsWith('.mjs'))) {
|
|
177
|
-
// Return a virtual module ID
|
|
183
|
+
// Return a virtual module ID to bypass Vite's public folder check
|
|
178
184
|
return `\0virtual:public-esm:${id}`;
|
|
179
185
|
}
|
|
180
186
|
}
|