Why SvelteKit basic example build output use the very modern import keyword? - rollupjs

In the description of Svelte, Rich explained why it's important to use the import keyword for development, and I'm totally agree. He continues and says that in the production build it's using the traditional JavaScript packaging:
That's not to say we're abandoning bundlers altogether. It's still essential to optimise your app for production, and SvelteKit uses Rollup to make your apps as fast and lean as they possibly can be (which includes things like extracting styles into static .css files).
But when I'm building the famous example from npm init svelte#next with adapter set to node, I see that the output JavaScript still use the import keyword in the pages JS, and also use <link rel="modulepreload" ...> which is super modern for browsers, as mentioned. For example, here is the output HTML of the built for production index.html page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Home</title>
<link rel="modulepreload" href="/_app/start-331a94d4.js">
<link rel="modulepreload" href="/_app/chunks/vendor-a4e104ac.js">
<link rel="modulepreload" href="/_app/pages/__layout.svelte-ad0878a7.js">
<link rel="modulepreload" href="/_app/pages/index.svelte-49c07d7e.js">
<link rel="stylesheet" href="/_app/assets/start-61d1577b.css">
<link rel="stylesheet" href="/_app/assets/pages/__layout.svelte-a06e2686.css">
<link rel="stylesheet" href="/_app/assets/pages/index.svelte-1ae03b51.css">
<script type="module">
import { start } from "/_app/start-331a94d4.js";
start({
target: document.querySelector("#svelte"),
paths: {"base":"","assets":""},
session: {},
host: "127.0.0.1:3000",
route: true,
spa: false,
trailing_slash: "never",
hydrate: {
status: 200,
error: null,
nodes: [
import("/_app/pages/__layout.svelte-ad0878a7.js"),
import("/_app/pages/index.svelte-49c07d7e.js")
],
page: {
host: "127.0.0.1:3000", // TODO this is redundant
path: "/",
query: new URLSearchParams(""),
params: {}
}
}
});
</script>
</head>
<body>
<div id="svelte">
<header class="svelte-1twf6mk"><div class="corner svelte-1twf6mk"><img src="/_app/assets/svelte-logo-87df40b8.svg" alt="SvelteKit" class="svelte-1twf6mk"></div>
<nav class="svelte-1twf6mk"><svg viewBox="0 0 2 3" aria-hidden="true" class="svelte-1twf6mk"><path d="M0,0 L1,2 C1.5,3 1.5,3 2,3 L2,0 Z" class="svelte-1twf6mk"></path></svg>
<ul class="svelte-1twf6mk"><li class="svelte-1twf6mk active"><a sveltekit:prefetch href="/" class="svelte-1twf6mk">Home</a></li>
<li class="svelte-1twf6mk"><a sveltekit:prefetch href="/about" class="svelte-1twf6mk">About</a></li>
<li class="svelte-1twf6mk"><a sveltekit:prefetch href="/todos" class="svelte-1twf6mk">Todos</a></li></ul>
<svg viewBox="0 0 2 3" aria-hidden="true" class="svelte-1twf6mk"><path d="M0,0 L0,3 C0.5,3 0.5,3 1,2 L2,0 Z" class="svelte-1twf6mk"></path></svg></nav>
<div class="corner svelte-1twf6mk"></div>
</header>
<main class="svelte-1izrdc8">
<section class="svelte-mjk9ig"><h1 class="svelte-mjk9ig"><div class="welcome svelte-mjk9ig"><picture><source srcset="svelte-welcome.webp" type="image/webp">
<img src="svelte-welcome.png" alt="Welcome" class="svelte-mjk9ig"></picture></div>
to your new<br>SvelteKit app
</h1>
<h2>try editing <strong>src/routes/index.svelte</strong></h2>
<div class="counter svelte-ltn89m"><button aria-label="Decrease the counter by one" class="svelte-ltn89m"><svg aria-hidden="true" viewBox="0 0 1 1" class="svelte-ltn89m"><path d="M0,0.5 L1,0.5" class="svelte-ltn89m"></path></svg></button>
<div class="counter-viewport svelte-ltn89m"><div class="counter-digits svelte-ltn89m" style="transform: translate(0, 0%)"><strong style="top: -100%" aria-hidden="true" class="svelte-ltn89m">1</strong>
<strong class="svelte-ltn89m">0</strong></div></div>
<button aria-label="Increase the counter by one" class="svelte-ltn89m"><svg aria-hidden="true" viewBox="0 0 1 1" class="svelte-ltn89m"><path d="M0,0.5 L1,0.5 M0.5,0 L0.5,1" class="svelte-ltn89m"></path></svg></button>
</div>
</section></main>
<footer class="svelte-1izrdc8"><p>visit kit.svelte.dev to learn SvelteKit</p>
</footer>
</div>
</body>
</html>
How can I build SvelteKit with the node adapter, with the traditional JavaScript rollupjs output in the client code, e.g. without the import keyword?

It turns out that my question is a feature request for SvelteKit.
This will be done after releasing version 1.0 of SvelteKit.
Credit for dummdidumm for pointing me out for this while I opened a duplicated issue.

Related

style tag is ignored by uiwebview

I'm trying to give my html an css inline style. But this style gets ignored.
This is the HTML string that I'm using for webView.loadHTMLString(htmlBelow, baseURL: Bundle.main.bundleURL)
let fontsize = 16 //This is an dynamic variable
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<meta http-equiv=\"X-UA-Compatible\"content=\"ie=edge\">
<title>Document</title>
<style>
​html {
font-size:\(fontsize)px; */THIS DOESN'T WORK/*
}
</style>
<link rel=\"stylesheet\" href=\"\style.css\">
<script src=\"jquery-3.4.1.min.js\"></script>
<script src=\"script.js\"></script>
</head>
<body>
<div class=\ "sqr-tree-level\"> \(restOfHtml) </div>
</body>
</html>
I'm trying to set the fontsize dynamically.
When I change the font-size in my css file it works, but I want to set it dynamically. That's why I wanna do it like this.
This is how my document.head.innerHTML looks like
For future reference the fix here was to put the styling in to the <body> tag instead of in the head <style> tag.
<body style=\"font-size:\(fontsize)px;\">

What's adding <style type="text/css">body { display: none !important }</style>

I followed these instructions for my app:
https://github.com/yeoman/generator-angular#readme
My Index (before build)
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css(.) styles/vendor.css -->
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
<!-- endbower -->
<!-- endbuild -->
<!-- build:css(.tmp) styles/app.css -->
<link href="app.less" type="text/css" rel="stylesheet/less">
<!-- endbuild -->
My dist Index (in text-editor)
<html ng-app="myApp"> <head> <meta charset="utf-8"> <title>Datavalidering</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" href="styles/vendor.2ac5f564.css"> <link rel="stylesheet" href="styles/app.d41d8cd9.css"> </head> <body>
Dist index (browser)
<head>
<style type="text/css">#charset "UTF-8";[ng\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide:not(.ng-hide-animate){display:none !important;}ng\:form{display:block;}.ng-animate-shim{visibility:hidden;}.ng-anchor{position:absolute;}</style>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="styles/vendor.2ac5f564.css"> <link rel="stylesheet" href="styles/app.d41d8cd9.css">
<style type="text/css">body { display: none !important }</style></head>
<body>
The problem may be in gruntfile.js
http://plnkr.co/edit/r2hdhWY7olIw0pBHJ4VF?p=preview
Thank you in advance for your answers!
This happens because of (less.js):
// Simulate synchronous stylesheet loading by blocking page rendering
if (!options.async)
{
css = 'body { display: none !important }';
head = document.head || document.getElementsByTagName('head')[0];
style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
}
so, all you need to do is add this before less.js
<script>
less = {
async: true
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/less.js/2.6.1/less.min.js"></script>
I'm not using Angular, but had a similar problem where this <style type="text/css">body { display: none !important }</style> suddenly appears at the end of head tag, effectively renders the whole page to not displaying anything.
I found out that the culprit was less.js. Simply commenting the line fixes it.
I have found a solution and the culprit.
It comes from the "Jetpack".
This image shows the location of the code in WordPress Directory:

GSP variables set in layout not visible in pages

I have some GSP variables set in the "main" layout file of my Grails application (included below). The values of these variables don't appear to be accessible in the GSP pages that are rendered by the sitemesh. Also, they are not visible in any templates that are rendered by the tag. I have tried setting the scope="request" (see code) below, but that doesn't appear to make any difference. I'm clearly not understanding the scoping rules for GSP variables.
Can anyone clarify how GSP variables are scoped and make a recommendation on how I can communicate them from the layout all the way down to templates (if I can at all).
<!DOCTYPE html>
<%-- <html lang="${org.springframework.web.servlet.support.RequestContextUtils.getLocale(request).toString().replace('_', '-')}"> --%>
<html lang="${session.'org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE'}">
<head>
<title><g:layoutTitle default="${meta(name:'app.name')}" /></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<asset:javascript src="bootstrap.js" />
<theme:load />
<asset:javascript src="application.js" />
<asset:stylesheet src="application.css" />
<asset:link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<g:layoutHead />
<%-- Defineform body layout column dimensions. These values are used by Bootstrap based forms to
layout using configured column widths and offsets. --%>
<g:set var="labelWidth" value="${grailsApplication.config.ark.layout.labelWidth ?: 'col-sm-3'}" scope="request" />
<g:set var="controlWidth" value="${grailsApplication.config.ark.layout.controlWidth ?: 'col-sm-4'}" scope="request" />
<g:set var="controlOffset" value="${grailsApplication.config.ark.layout.controlWidth ?: 'col-sm-offset-3'}" scope="request" />
<%-- For Javascript see end of body --%>
</head>
<body>
<g:render plugin="arkUi" template="/layouts/menu/navbar"/>
<g:render plugin="arkUi" template="/layouts/content"/>
<g:render plugin="arkUi" template="/layouts/footer"/>
<!-- Include deferred Javascript files and other resources -->
<asset:deferredScripts/>
</body>
</html>
The issue here is that Grails first parses the target GSP page to (among other things) determine which layout to use, then parses the layout GSP and combines them. So the layout can see variables you set in the page but not vice-versa.

How to modify the default mapping location of the resources that a Grails plugin uses

I have installed:
compile ":jquery-ui:1.8.24"
compile ":jqgrid:3.8.0.1"
I got the next error:
| Error 2013-06-03 15:20:33,892 [http-bio-8080-exec-7] ERROR resource.ResourceMeta - While processing /plugins/jqgrid-3.8.0.1/css/jqgrid/ui.jqgrid.css, a resource was required but not found: /plugins/jqgrid-3.8.0.1/css/jqgrid/ellipsis-xbl.xml
I opened the file C:\Users\user\.grails\ivy-cache\org.grails.plugins\jqgrid\zips\jqgrid-3.8.0.1.zip. There is not any: css/jqgrid/ellipsis-xbl.xml
The latest version of JQGrid (4.5.2) has the file ellipsis-xbl.xml included. But I'm using the latest Grails plugin which uses that older version.
How could I tell Grails to look for ellipsis-xbl.xml in another location (let's say web-app/css/jqgrid-additions/ellipsis-xbl.xml).
I did a research on Google and it is what could be related:
taglib: <jqgrid:resources /> (according with the documentation, it
includes the required javascript and css for the plugin)
Add a configurationmapping in BuildConfig.groovy (I didn't find any
Grails documentation about that!)
I added to the GSP the next code to check if it looked at a different
location (and it check in the same location, at /plugins...):
<style>
.ui-jqgrid tr.jqgrow td {text-overflow:ellipsis; -moz-binding:url('ellipsis-xbl.xml#ellipsis');}
</style>
I end up by removing all css/js plugins except for jQuery (which is built-in). Just extract css/js files in /web-app directory. Then include them in /grails-app/conf/ApplicationResources.groovy like this:
modules = {
ui {
dependsOn 'jquery'
resource url: 'css/default.css'
resource url: 'css/print.css', attrs:[media:'print']
}
bootstrap {
dependsOn 'jquery'
resource url: 'css/bootstrap.css'
resource url: 'css/bootstrap-responsive.css'
resource url: 'js/bootstrap.js'
}
choice {
resource url: 'js/choice.js'
}
application {
dependsOn 'jquery,choice'
resource url: 'js/application.js'
}
}
Choice and application are application specific. Include here as an example. Then, call them in layout:
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><g:layoutTitle default="My Application" /></title>
<g:layoutHead />
<r:require modules="jquery,ui,bootstrap,choice,application" />
<r:layoutResources />
</head>
<body>
<div id="wrapper">
<div id="main" class="container-fluid">
<div class="row-fluid">
<div class="span12">
<g:layoutBody/>
</div>
</div>
</div>
</div>
<r:layoutResources />
</body>
</html>
This way, I can manage css/js library myself.

grails 2.0 including resources the simple way?

I've been battling various resource inclusion issues in my migration from Grails 1.3.7 from Grails 2.0, probably not understanding a few things to begin with.
Firstly, what does
<g:javascript library="application" />
do? (this was in the default main.gsp provided in Grails 1.3.7).
Secondly, for including jquery across my application, can I just do
<r:require module='jquery' />
<r:layoutResources />
in the top of my main sitemesh page that does the
<g:layoutHead />
...
<g:layoutBody />
and "be done with it", using the
<r:layoutResources />
a second time after the
<g:layoutBody />
Thanks
Yes I struggled a little with this at first too.
So firstly the <g:javascript library="application" /> refers to a module defined in a config/*.Resources.groovy file (default is config/ApplicationResources.groovy), inside that you have named modules, eg:
modules = {
application {
resource url: 'js/jquery/jquery-ui-1.8.15.custom.min.js', disposition: 'head'
}
}
Secondly by example a Grails2 main.gsp (cutdown a lot here):
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><g:layoutTitle default="Grails"/></title>
<link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}" type="text/css">
<link rel="stylesheet" href="${resource(dir: 'css', file: 'mobile.css')}" type="text/css">
<link rel="stylesheet" href="${resource(dir: 'css/redmond', file: 'jquery-ui-1.8.15.custom.css')}" type="text/css">
<g:layoutHead/>
<g:javascript library="jquery"/>
<r:require module="application"/>
<r:layoutResources/>
</head>
<body>
<g:layoutBody/>
<r:layoutResources/>
</body>
</html>
Hope that sets you in the right direction

Resources