ladrillosjs 2.0.0-beta.3.4 → 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 +74 -0
- package/dist/{index-COl4zCLy.mjs → index-BCmcPNOm.mjs} +220 -142
- package/dist/{index-COl4zCLy.mjs.map → index-BCmcPNOm.mjs.map} +1 -1
- package/dist/index-QzAQ6RiB.js +68 -0
- package/dist/{index-CBW3yTb-.js.map → index-QzAQ6RiB.js.map} +1 -1
- package/dist/ladrillosjs.cjs.js +1 -1
- package/dist/ladrillosjs.es.js +1 -1
- package/dist/ladrillosjs.umd.js +64 -15
- package/dist/ladrillosjs.umd.js.map +1 -1
- package/dist/vite/copyComponentsPlugin.d.ts +7 -1
- package/dist/vite.cjs +51 -0
- package/dist/vite.cjs.map +7 -0
- package/dist/vite.js +51 -0
- package/dist/vite.js.map +7 -0
- package/dist/{webcomponent-WCW6485Z.mjs → webcomponent-BbpwGH9E.mjs} +3 -2
- package/dist/{webcomponent-WCW6485Z.mjs.map → webcomponent-BbpwGH9E.mjs.map} +1 -1
- package/dist/{webcomponent-BdxW-3sK.js → webcomponent-DQzGWQsO.js} +2 -2
- package/dist/{webcomponent-BdxW-3sK.js.map → webcomponent-DQzGWQsO.js.map} +1 -1
- package/package.json +6 -2
- package/dist/index-CBW3yTb-.js +0 -19
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:
|