ladrillosjs 2.0.0-beta.3.5 → 2.0.0-beta.3.6

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/README.md CHANGED
@@ -142,9 +142,83 @@ interface CopyComponentsOptions {
142
142
 
143
143
  /** Copy during development server (default: false) */
144
144
  copyOnDev?: boolean;
145
+
146
+ /** Process component module scripts (default: true) */
147
+ processScripts?: boolean;
145
148
  }
146
149
  ```
147
150
 
151
+ ### Processing Component Module Scripts
152
+
153
+ When `processScripts` is enabled (default), the plugin automatically transforms component scripts using `type="module"` to work with the window scope. This is essential when building with Vite and using ES modules in your components.
154
+
155
+ **What It Does:**
156
+
157
+ - Converts ES module imports to window references
158
+ - Wraps scripts in an async IIFE that waits for the library to load
159
+ - Handles multiple components efficiently with a shared loading promise
160
+
161
+ **Example:**
162
+
163
+ Before build (in your component):
164
+
165
+ ```html
166
+ <script type="module">
167
+ import { registerComponent } from "ladrillosjs";
168
+
169
+ let count = 0;
170
+
171
+ export const increment = () => {
172
+ count++;
173
+ };
174
+ </script>
175
+ ```
176
+
177
+ After build (automatically transformed):
178
+
179
+ ```html
180
+ <script>
181
+ (async () => {
182
+ try {
183
+ if (!window.__ladrillosPromise__) {
184
+ window.__ladrillosPromise__ = new Promise((resolve) => {
185
+ // Wait for LadrillosJS to load...
186
+ });
187
+ }
188
+
189
+ await window.__ladrillosPromise__;
190
+
191
+ (async () => {
192
+ const { registerComponent } = window.ladrillosjs;
193
+
194
+ let count = 0;
195
+
196
+ // Component code...
197
+ })();
198
+ } catch (error) {
199
+ console.error("Failed to execute component module:", error);
200
+ }
201
+ })();
202
+ </script>
203
+ ```
204
+
205
+ **Disable Processing (if needed):**
206
+
207
+ ```javascript
208
+ import { defineConfig } from "vite";
209
+ import { copyComponentsPlugin } from "ladrillosjs/vite";
210
+
211
+ export default defineConfig({
212
+ plugins: [
213
+ copyComponentsPlugin({
214
+ src: "components",
215
+ dest: "components",
216
+ processScripts: false, // Disable script processing
217
+ }),
218
+ ],
219
+ });
220
+ ```
221
+
148
222
  ### Complete Example
149
223
 
150
224
  Project structure: