@primate/svelte 0.5.0 → 0.5.2
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 +10 -0
- package/package.json +1 -1
- package/src/module.js +12 -2
package/README.md
CHANGED
|
@@ -15,3 +15,13 @@ export default {
|
|
|
15
15
|
modules: [svelte()],
|
|
16
16
|
};
|
|
17
17
|
```
|
|
18
|
+
|
|
19
|
+
If you use a bundler, specify an array of entry points:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import svelte from "@primate/svelte";
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
modules: [svelte({entryPoints: ["EntryPage.svelte"]})],
|
|
26
|
+
};
|
|
27
|
+
```
|
package/package.json
CHANGED
package/src/module.js
CHANGED
|
@@ -13,8 +13,9 @@ const handler = path => (component, props = {}, {status = 200} = {}) =>
|
|
|
13
13
|
const {html: body} = (await import(`${path.join(`${component}.js`)}`))
|
|
14
14
|
.default.render(props);
|
|
15
15
|
|
|
16
|
+
const name = component.slice(0, -endings.svelte.length);
|
|
16
17
|
// create an entry point
|
|
17
|
-
const entry = `import Component from "
|
|
18
|
+
const entry = `import {${name} as Component} from "./dist.js";
|
|
18
19
|
const props = JSON.parse(${JSON.stringify(JSON.stringify(props))});
|
|
19
20
|
new Component({
|
|
20
21
|
target: document.body,
|
|
@@ -36,7 +37,7 @@ const handler = path => (component, props = {}, {status = 200} = {}) =>
|
|
|
36
37
|
};
|
|
37
38
|
|
|
38
39
|
const {svelte, js} = endings;
|
|
39
|
-
export default directory => ({
|
|
40
|
+
export default ({directory, entryPoints} = {}) => ({
|
|
40
41
|
register(env, next) {
|
|
41
42
|
env.register("svelte", handler(directory ?? env.paths.components));
|
|
42
43
|
return next(env);
|
|
@@ -75,6 +76,15 @@ export default directory => ({
|
|
|
75
76
|
.replace("./svelte/internal", "./svelte/internal.js");
|
|
76
77
|
await env.publish({src: `${component.name}.js`, code: compiled, type});
|
|
77
78
|
}));
|
|
79
|
+
// create a pseudo entry to allow bundlers to bundle relevant code until
|
|
80
|
+
// proper path-splitting has been implemented
|
|
81
|
+
if (entryPoints !== undefined) {
|
|
82
|
+
const code = entryPoints.map(entry => {
|
|
83
|
+
const name = entry.slice(0, -endings.svelte.length);
|
|
84
|
+
return `export {default as ${name}} from "./${entry}.js";`
|
|
85
|
+
}).join("");
|
|
86
|
+
await env.publish({src: "dist.js", code, type, main: true});
|
|
87
|
+
}
|
|
78
88
|
return next(env);
|
|
79
89
|
},
|
|
80
90
|
});
|