@primate/svelte 0.5.0 → 0.5.1

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/package.json +1 -1
  2. package/src/module.js +12 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/svelte",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "bugs": "https://github.com/primatejs/svelte/issues",
5
5
  "repository": "https://github.com/primatejs/svelte",
6
6
  "description": "Primate Svelte module",
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 "./${component}.js";
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
  });