@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.
Files changed (2) hide show
  1. package/.storybook/main.js +32 -15
  2. package/package.json +1 -1
@@ -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 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
+ // 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
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.16",
4
4
  "description": "Storybook showcase for Pure Design System with live configuration",
5
5
  "type": "module",
6
6
  "private": false,