@primate/svelte 0.5.2 → 0.6.0

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 +16 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/svelte",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
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
@@ -15,7 +15,7 @@ const handler = path => (component, props = {}, {status = 200} = {}) =>
15
15
 
16
16
  const name = component.slice(0, -endings.svelte.length);
17
17
  // create an entry point
18
- const entry = `import {${name} as Component} from "./dist.js";
18
+ const entry = `import {${name} as Component} from "./${env.dist}.js";
19
19
  const props = JSON.parse(${JSON.stringify(JSON.stringify(props))});
20
20
  new Component({
21
21
  target: document.body,
@@ -60,30 +60,35 @@ export default ({directory, entryPoints} = {}) => ({
60
60
  const options = {
61
61
  generate: "dom",
62
62
  hydratable: true,
63
- css: false,
64
63
  sveltePath: "./svelte",
65
64
  };
66
65
  const components = await path.list(filename => filename.endsWith(svelte));
67
66
  const scriptPath = ["node_modules", "svelte", "internal", "index.mjs"];
68
- // publish svelte itself
69
- const code = await Path.resolve().join(...scriptPath).file.read();
70
- await env.publish({src: "svelte/internal.js", code, type});
67
+ {
68
+ // publish svelte itself
69
+ const code = await Path.resolve().join(...scriptPath).file.read();
70
+ await env.publish({src: "svelte/internal.js", code, type});
71
+ }
71
72
  await Promise.all(components.map(async component => {
72
73
  const file = await component.file.read();
73
74
  const client = compiler.compile(file, options);
75
+ const css = client.css.code;
74
76
  const compiled = client.js.code
75
77
  .replaceAll(svelte, js)
76
78
  .replace("./svelte/internal", "./svelte/internal.js");
77
79
  await env.publish({src: `${component.name}.js`, code: compiled, type});
80
+ if (css !== null) {
81
+ const name = `${component.name}.css`;
82
+ await env.publish({src: name, code: css, type: "style"});
83
+ env.bootstrap({type: "style", code: `import "./${name}";`});
84
+ }
78
85
  }));
79
- // create a pseudo entry to allow bundlers to bundle relevant code until
80
- // proper path-splitting has been implemented
81
86
  if (entryPoints !== undefined) {
82
- const code = entryPoints.map(entry => {
87
+ entryPoints.forEach(entry => {
83
88
  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});
89
+ const code = `export {default as ${name}} from "./${entry}.js";`;
90
+ env.bootstrap({type: "script", code});
91
+ });
87
92
  }
88
93
  return next(env);
89
94
  },