@pure-ds/storybook 0.3.14 → 0.3.15

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.
Files changed (2) hide show
  1. package/.storybook/main.js +30 -15
  2. package/package.json +1 -1
@@ -159,22 +159,37 @@ 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 user's public folder
163
- // This allows stories to use imports like: import { html } from '/assets/js/lit.js';
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
- if (process.cwd() !== resolve(currentDirname, '..') && fs.existsSync(userPublicPath)) {
166
- const userAssetsPath = resolve(userPublicPath, 'assets');
167
- if (fs.existsSync(userAssetsPath)) {
168
- config.resolve.alias['/assets'] = userAssetsPath;
169
- }
170
-
171
- // Allow Vite to serve files from user's public folder
172
- config.server = config.server || {};
173
- config.server.fs = config.server.fs || {};
174
- config.server.fs.allow = [
175
- ...(config.server.fs.allow || []),
176
- userPublicPath
177
- ];
166
+ const isConsumerProject = process.cwd() !== resolve(currentDirname, '..');
167
+
168
+ if (isConsumerProject && fs.existsSync(userPublicPath)) {
169
+ config.plugins = config.plugins || [];
170
+ config.plugins.push({
171
+ name: 'pds-public-esm-loader',
172
+ resolveId(id) {
173
+ // Handle absolute paths starting with /assets/ or other paths in public
174
+ if (id.startsWith('/') && !id.startsWith('/@') && !id.startsWith('/node_modules')) {
175
+ const filePath = resolve(userPublicPath, id.slice(1)); // Remove leading /
176
+ if (fs.existsSync(filePath) && (filePath.endsWith('.js') || filePath.endsWith('.mjs'))) {
177
+ // Return a virtual module ID
178
+ return `\0virtual:public-esm:${id}`;
179
+ }
180
+ }
181
+ },
182
+ load(id) {
183
+ if (id.startsWith('\0virtual:public-esm:')) {
184
+ const originalPath = id.replace('\0virtual:public-esm:', '');
185
+ const filePath = resolve(userPublicPath, originalPath.slice(1));
186
+ if (fs.existsSync(filePath)) {
187
+ // Read and return the actual file contents
188
+ return fs.readFileSync(filePath, 'utf-8');
189
+ }
190
+ }
191
+ }
192
+ });
178
193
  }
179
194
 
180
195
  // Set base path for production builds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pure-ds/storybook",
3
- "version": "0.3.14",
3
+ "version": "0.3.15",
4
4
  "description": "Storybook showcase for Pure Design System with live configuration",
5
5
  "type": "module",
6
6
  "private": false,