Skip to content

Commit

Permalink
Import svelte compiler in JS.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Jul 8, 2020
1 parent e2db4ef commit 78fa011
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
19 changes: 8 additions & 11 deletions cmd/build/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ func Client(buildPath string, bundledContent []byte) string {
bundledContent = bytes.Replace(bundledContent, []byte("})();"), []byte(""), 1) // TODO: Only replace the last instance of this string.
fmt.Println(string(bundledContent))
ctx, _ := v8go.NewContext(nil)
val, err := ctx.RunScript(string(bundledContent), "ejected/bundle.js")
if err != nil {
fmt.Printf("V8go could not execute: %v", err)
}
ctx.RunScript(string(bundledContent), "ejected/bundle.js")
val, _ := ctx.RunScript("var component='';", "ejected/bundle.js")
fmt.Println(val)

// Go through all file paths in the "/layout" folder.
Expand All @@ -59,13 +57,12 @@ func Client(buildPath string, bundledContent []byte) string {
// Replace .svelte file extension with .js.
destFile = strings.TrimSuffix(destFile, filepath.Ext(destFile)) + ".js"

/*
val, err := ctx.RunScript("require_build_client()", "ejected/bundle.js")
if err != nil {
fmt.Printf("V8go could not execute: %v", err)
}
fmt.Println(val)
*/
val, err := ctx.RunScript("component='"+layoutPath+"'", "ejected/bundle.js")
if err != nil {
fmt.Printf("V8go could not execute: %v", err)
}
fmt.Println(val)
//fmt.Println(string(bundledContent))

// Create string representing array of objects to be passed to nodejs.
//clientBuildStr = clientBuildStr + "{ \"layoutPath\": \"" + layoutPath + "\", \"destPath\": \"" + destFile + "\", \"stylePath\": \"" + stylePath + "\"},"
Expand Down
11 changes: 6 additions & 5 deletions ejected/build_client.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//import svelte from 'svelte/compiler.js';
import svelte from 'svelte/compiler.js';
//const svelte = require('svelte/compiler.js');

// The "component" variable gets injected by client.go.
//let component;

// Create component JS that can run in the browser.
//export let { js, css } = svelte.compile('/home/jimafisk/Desktop/aaa/layout/content/pages.svelte', {
// css: false
//});
export let { js, css } = svelte.compile('/home/jimafisk/Desktop/aaa/layout/content/pages.svelte', {
css: false
});

// Return the JS and CSS object.
//(() => { js, css })();
//(() => js)();
(() => "test")();
//(() => component)();
(() => js)();
//return "test";
11 changes: 6 additions & 5 deletions generated/ejected.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,22 @@ staticBuildStr.forEach(arg => {
fs.promises.writeFile(destPath, html);
});`),
"/build_client.js": []byte(`//import svelte from 'svelte/compiler.js';
"/build_client.js": []byte(`import svelte from 'svelte/compiler.js';
//const svelte = require('svelte/compiler.js');
// The "component" variable gets injected by client.go.
//let component;
// Create component JS that can run in the browser.
//export let { js, css } = svelte.compile('/home/jimafisk/Desktop/aaa/layout/content/pages.svelte', {
// css: false
//});
export let { js, css } = svelte.compile('/home/jimafisk/Desktop/aaa/layout/content/pages.svelte', {
css: false
});
// Return the JS and CSS object.
//(() => { js, css })();
//(() => js)();
(() => "test")();
//(() => component)();
(() => js)();
//return "test";`),
"/main.js": []byte(`import Router from './router.svelte';
Expand Down

0 comments on commit 78fa011

Please sign in to comment.