@primate/svelte 0.5.1 → 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.
- package/README.md +10 -0
- package/package.json +1 -1
- package/src/module.js +17 -12
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
|
@@ -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 "
|
|
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,
|
|
@@ -37,7 +37,7 @@ const handler = path => (component, props = {}, {status = 200} = {}) =>
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
const {svelte, js} = endings;
|
|
40
|
-
export default ({directory, entryPoints}) => ({
|
|
40
|
+
export default ({directory, entryPoints} = {}) => ({
|
|
41
41
|
register(env, next) {
|
|
42
42
|
env.register("svelte", handler(directory ?? env.paths.components));
|
|
43
43
|
return next(env);
|
|
@@ -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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
87
|
+
entryPoints.forEach(entry => {
|
|
83
88
|
const name = entry.slice(0, -endings.svelte.length);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
},
|