Skip to content

Instantly share code, notes, and snippets.

@shedali
Last active August 24, 2020 15:56
Show Gist options
  • Save shedali/3f07e0e2f3b5d597739b450ec6330726 to your computer and use it in GitHub Desktop.
Save shedali/3f07e0e2f3b5d597739b450ec6330726 to your computer and use it in GitHub Desktop.
svelte compile for php include
const fs = require('fs');
require('svelte/register');
const Component = require('./Widget.html').default;
const { head, html, css } = Component.render({
answer: "cms-string-content"// pass in cms values as props
});
fs.writeFileSync("output/styles.css", css.code);
//write out for content editor
fs.writeFileSync("output/index.html", html)
<?php echo "hello world" ?>
<style>
<?php include 'output/styles.css';?>
</style>
<?php include 'output/index.html';?>
{
"name": "svelte-compile",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "node compile; echo see output dir",
"serve":"php -S 127.0.0.1:8080"
},
"keywords": [],
"author": "Franz",
"license": "ISC",
"devDependencies": {
"svelte": "^3.24.1"
}
}
<script>
export let answer=""
</script>
<style>
.encapsulated-style-here {
color: red;
}
</style>
<div class="encapsulated-style-here">
{answer}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment