@pure-ds/storybook 0.3.14 → 0.3.16
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 +32 -15
- package/package.json +1 -1
package/.storybook/main.js
CHANGED
|
@@ -159,22 +159,39 @@ const config = {
|
|
|
159
159
|
config.resolve.alias['@user/pds-config'] = resolve(currentDirname, '../default-pds.config.js');
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
// Support absolute path imports from
|
|
163
|
-
//
|
|
162
|
+
// Support absolute path imports like: import { html } from '/assets/js/lit.js';
|
|
163
|
+
// Vite blocks direct imports from public/, so we use a plugin that serves
|
|
164
|
+
// the file contents as virtual modules, bypassing Vite's public folder restriction.
|
|
164
165
|
const userPublicPath = resolve(process.cwd(), 'public');
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
166
|
+
const isConsumerProject = process.cwd() !== resolve(currentDirname, '..');
|
|
167
|
+
|
|
168
|
+
if (isConsumerProject && fs.existsSync(userPublicPath)) {
|
|
169
|
+
config.plugins = config.plugins || [];
|
|
170
|
+
// Insert at the beginning to run before other plugins
|
|
171
|
+
config.plugins.unshift({
|
|
172
|
+
name: 'pds-public-esm-loader',
|
|
173
|
+
enforce: 'pre', // Run before Vite's built-in plugins
|
|
174
|
+
resolveId(id, importer) {
|
|
175
|
+
// Handle absolute paths starting with /assets/ or other paths in public
|
|
176
|
+
if (id.startsWith('/') && !id.startsWith('/@') && !id.startsWith('/node_modules')) {
|
|
177
|
+
const filePath = resolve(userPublicPath, id.slice(1)); // Remove leading /
|
|
178
|
+
if (fs.existsSync(filePath) && (filePath.endsWith('.js') || filePath.endsWith('.mjs'))) {
|
|
179
|
+
// Return a virtual module ID to bypass Vite's public folder check
|
|
180
|
+
return `\0virtual:public-esm:${id}`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
load(id) {
|
|
185
|
+
if (id.startsWith('\0virtual:public-esm:')) {
|
|
186
|
+
const originalPath = id.replace('\0virtual:public-esm:', '');
|
|
187
|
+
const filePath = resolve(userPublicPath, originalPath.slice(1));
|
|
188
|
+
if (fs.existsSync(filePath)) {
|
|
189
|
+
// Read and return the actual file contents
|
|
190
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
178
195
|
}
|
|
179
196
|
|
|
180
197
|
// Set base path for production builds
|