Giter VIP home page Giter VIP logo

sapper-template's Introduction

sapper-template

The default template for setting up a Sapper project. Can use either Rollup or webpack as bundler.

Please note

Sapper is no longer being actively developed. You may be interested in using Sapper's succesor, SvelteKit for new projects.

Getting started

Using degit

To create a new Sapper project based on Rollup locally, run

npx degit "sveltejs/sapper-template#rollup" my-app

For a webpack-based project, instead run

npx degit "sveltejs/sapper-template#webpack" my-app

degit is a scaffolding tool that lets you create a directory from a branch in a repository.

Replace my-app with the path where you wish to create the project.

Using GitHub templates

Alternatively, you can create the new project as a GitHub repository using GitHub's template feature.

Go to either sapper-template-rollup or sapper-template-webpack and click on "Use this template" to create a new project repository initialized by the template.

Running the project

Once you have created the project, install dependencies and run the project in development mode:

cd my-app
npm install # or yarn
npm run dev

This will start the development server on localhost:3000. Open it and click around.

You now have a fully functional Sapper project! To get started developing, consult sapper.svelte.dev.

Using TypeScript

By default, the template uses plain JavaScript. If you wish to use TypeScript instead, you need some changes to the project:

  • Add typescript as well as typings as dependences in package.json
  • Configure the bundler to use svelte-preprocess and transpile the TypeScript code.
  • Add a tsconfig.json file
  • Update the project code to TypeScript

The template comes with a script that will perform these changes for you by running

node scripts/setupTypeScript.js

@sapper dependencies are resolved through src/node_modules/@sapper, which is created during the build. You therefore need to run or build the project once to avoid warnings about missing dependencies.

The script does not support webpack at the moment.

Directory structure

Sapper expects to find two directories in the root of your project — src and static.

src

The src directory contains the entry points for your app — client.js, server.js and (optionally) a service-worker.js — along with a template.html file and a routes directory.

src/routes

This is the heart of your Sapper app. There are two kinds of routes — pages, and server routes.

Pages are Svelte components written in .svelte files. When a user first visits the application, they will be served a server-rendered version of the route in question, plus some JavaScript that 'hydrates' the page and initialises a client-side router. From that point forward, navigating to other pages is handled entirely on the client for a fast, app-like feel. (Sapper will preload and cache the code for these subsequent pages, so that navigation is instantaneous.)

Server routes are modules written in .js files, that export functions corresponding to HTTP methods. Each function receives Express request and response objects as arguments, plus a next function. This is useful for creating a JSON API, for example.

There are three simple rules for naming the files that define your routes:

  • A file called src/routes/about.svelte corresponds to the /about route. A file called src/routes/blog/[slug].svelte corresponds to the /blog/:slug route, in which case params.slug is available to the route
  • The file src/routes/index.svelte (or src/routes/index.js) corresponds to the root of your app. src/routes/about/index.svelte is treated the same as src/routes/about.svelte.
  • Files and directories with a leading underscore do not create routes. This allows you to colocate helper modules and components with the routes that depend on them — for example you could have a file called src/routes/_helpers/datetime.js and it would not create a /_helpers/datetime route.

src/node_modules/images

Images added to src/node_modules/images can be imported into your code using import 'images/<filename>'. They will be given a dynamically generated filename containing a hash, allowing for efficient caching and serving the images on a CDN.

See index.svelte for an example.

src/node_modules/@sapper

This directory is managed by Sapper and generated when building. It contains all the code you import from @sapper modules.

static

The static directory contains static assets that should be served publicly. Files in this directory will be available directly under the root URL, e.g. an image.jpg will be available as /image.jpg.

The default service-worker.js will preload and cache these files, by retrieving a list of files from the generated manifest:

import { files } from '@sapper/service-worker';

If you have static files you do not want to cache, you should exclude them from this list after importing it (and before passing it to cache.addAll).

Static files are served using sirv.

Bundler configuration

Sapper uses Rollup or webpack to provide code-splitting and dynamic imports, as well as compiling your Svelte components. With webpack, it also provides hot module reloading. As long as you don't do anything daft, you can edit the configuration files to add whatever plugins you'd like.

Production mode and deployment

To start a production version of your app, run npm run build && npm start. This will disable live reloading, and activate the appropriate bundler plugins.

You can deploy your application to any environment that supports Node 10 or above. As an example, to deploy to Vercel Now when using sapper export, run these commands:

npm install -g vercel
vercel

If your app can't be exported to a static site, you can use the vercel-sapper builder. You can find instructions on how to do so in its README.

Using external components

When using Svelte components installed from npm, such as @sveltejs/svelte-virtual-list, Svelte needs the original component source (rather than any precompiled JavaScript that ships with the component). This allows the component to be rendered server-side, and also keeps your client-side app smaller.

Because of that, it's essential that the bundler doesn't treat the package as an external dependency. You can either modify the external option under server in rollup.config.js or the externals option in webpack.config.js, or simply install the package to devDependencies rather than dependencies, which will cause it to get bundled (and therefore compiled) with your app:

npm install -D @sveltejs/svelte-virtual-list

Troubleshooting

Using Windows and WSL2?

If your project lives outside the WSL root directory, this limitation is known to cause live-reloading to fail. See this issue for details.

Bugs and feedback

Sapper is in early development, and may have the odd rough edge here and there. Please be vocal over on the Sapper issue tracker.

sapper-template's People

Contributors

adamduncan avatar alireza-mh avatar antony avatar arxpoetica avatar benmccann avatar conduitry avatar cristianl avatar ehrencrona avatar eps1lon avatar kimihito avatar lukeed avatar mathiasbynens avatar mattpilott avatar milahu avatar muhajirdev avatar necrodome avatar nolanlawson avatar qstearns avatar ratson avatar rdela avatar rich-harris avatar seanlail avatar shvargon avatar srinivasrk avatar stolinski avatar thgh avatar twmbx avatar woochanleee avatar ykomatsu avatar ysshah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sapper-template's Issues

dev server sometimes requires restart after editing route.html files

I'll get an error like this on the client:

process-update.js:136 [HMR] Update check failed: Error: Manifest request to /client/7f71269cd30032b87e4f.hot-update.json timed out.
    at XMLHttpRequest.request.onreadystatechange (http://localhost:3000/client/main.7f71269cd30032b87e4f.js:64:22)
handleError @ process-update.js:136
cb @ process-update.js:47
Promise rejected (async)
check @ process-update.js:84
module.exports @ process-update.js:42
processMessage @ client.js:251
handleMessage @ client.js:131
handleMessage @ client.js:94
bootstrap 7f71269cd30032b87e4f:63 Uncaught (in promise) Error: Manifest request to /client/7f71269cd30032b87e4f.hot-update.json timed out.
    at XMLHttpRequest.request.onreadystatechange (bootstrap 7f71269cd30032b87e4f:63)
request.onreadystatechange @ bootstrap 7f71269cd30032b87e4f:63
Promise rejected (async)
check @ process-update.js:81
module.exports @ process-update.js:42
processMessage @ client.js:251
handleMessage @ client.js:131
handleMessage @ client.js:94

And then everything hangs. API routes don't start processing requests (no console.log printing in the terminal) until the process is killed and then requests finish.

Don't know enough about this stack of tools to debug, but might have something to do with lack of error handling here?

preload({ params, query }) {
  return fetch(`/api/feed`).then(r => r.json()).then(posts => {
    return {posts} 
  })
}

Handling CSS with webpack

Currently CSS processing is rather rudimentary; static global CSS in the assets dir and svelte component CSS included in JS bundles. That's all well and good for a demo or PoC but the reality is production sites need more flexibility, repeatability, and automation.

Since we're using webpack for bundling, it should also be set up to handle generating CSS file/s. A link to the file/s should also be injected into the page template.

Using css-loader + style-loader/mini-css-extract-plugin is probably all we need for most projects to get started. This is easy to set up but now we also need to add a <link rel=stylesheet> to the head which doesn't automatically happen. In other webpack projects I would use html-webpack-plugin but that seems like overkill when sapper is already handling template.html.

So, what we need for this is:

  1. Change webpack client config: sevelte to pass CSS to webpack + handle CSS via webpack loaders.
  2. Provide a way to inject CSS file/s via a <link>.

For reference, here's what I'm using in one of my new projects, which covers 1. It also uses postcss but that's not necessary for sapper-template.

Dev-mode dynamic imports fail in prod mode

This code in templates/main.js...

if (__dev__) {
	// Enable hot-module reloading
	import('sapper/webpack/hmr');
	if (module.hot) module.hot.accept();
}

...causes problems. Because webpack isn't quite smart enough to remove the dead code (__dev__ is rewritten as false), we're left with the import statement when webpack tries to concatenate the modules, and Acorn fails to parse.

One possible solution would be to replace the whole lot with an injected __hmr__ block. That's a bit mysterious though, and I'd prefer something less so, though I can't quite figure out what.

How to deploy production to ...

@Rich-Harris I am absolutely loving svelte and sapper... But am having trouble understanding how to deploy say to Heroku or AWS. I have built, run, and deployed to "now"(obviously you made that ridiculously simple, thanks..).
Once built is everything I would need in the "app" or "build" dir?
Any advice or pointers would be truly appreciated.
Thanks!!

koa support

are there any plans to support koa?

thanks either way

edit: realized this doesn't belong in the template repo

Custom elements inserts duplicate element at top of document

When enabling custom elements and adding a component to the page creates a duplicate of the components contents at the top of the document (although not as a custom element).

Below is a screenshot where you can see <nav> and <main> are inserted inside <div id="sapper"> which come from the route _layout.html and the component Nav.html.

image

image

Upgrade pain points

I mentioned a while ago I would provide these for the sake of conversation, but never got around to it. Since I just upgraded again, I documented things.

--

It's difficult to spot version diffs and/or conflict resolve difference between my updates and sapper-template. Example: in the package.json file, I've added a bunch of new dependencies and scripts. Because of that it's hard to spot when you delete or add some from the template, especially in the cases where I'm actually still using a dependency that you've deleted, i.e., node-fetch. The only mechanism I can think of to spot check the differences is to do something like this: f1c9e0a...ab69886

Other examples include changes to app/template.html (I reference different favicon links that the template, for example), and various routes files changes. Also, changes in the app/server.js file can be really hard to trace, for example, the differences between Polka use and Express.

Finally, I use yarn for package managing, but the .gitignore file has the yarn.lock and yarn-error.log files commented out.

I'm wondering if I'm doing things the hard way? I basically have to back up my whole project before copying this template over my git committed local version and then run through the whole diff. Would be nice if there was a much more convenient way to diff things between your changes and mine. I can't imagine how though.

Uncaught TypeError: Cannot read property 'call' of undefined

Using d93604d and following the steps from the "getting started" guide:

degit sveltejs/sapper-template my-app
cd my-app
npm install
npm run build
npm start

Then navigate to http://localhost:3000/blog/what-is-sapper.

Result: the page loads fine, but there's an error in the console because one of the modules apparently can't be loaded by webpack:

Stacktrace (with minification turned off):

Uncaught (in promise) TypeError: Cannot read property 'call' of undefined
    at __webpack_require__ (bootstrap b018e58b911432dbd00b:49)
    at Object.11 (svelte-2284459081.css:1)
    at __webpack_require__ (bootstrap b018e58b911432dbd00b:49)
    at Object.10 (svelte-2284459081.css?b9c7:4)
    at __webpack_require__ (bootstrap b018e58b911432dbd00b:49)
    at Object.15 ([slug].html:9)
    at __webpack_require__ (bootstrap b018e58b911432dbd00b:49)
    at <anonymous>

Seems it can be traced back to a require() in a generated svelte-***.css file:

exports = module.exports = require("../../../../../tmp/workspace/my-app/node_modules/css-loader/lib/css-base.js")(true);

This can be repro'd in both Firefox and Chrome. I'm using macOS, Node v8.9.3.

Loading svelte components from node_modules

Few issues making it difficult to load svelte components from the node_modules folder out of the box.

  • Firstly, mainFields is not specified with 'svelte' in it.

  • Secondly node_modules is being excluded in the rule to load .html files.

  • And lastly, on the server side, this line is preventing webpack from bundling the svelte component and makes it load it as an external module which fails.

    externals: Object.keys(pkg.dependencies),

Failed build script should not return exit code 0

When running the webpack build running npm run build in CI it should be possible to check for failure on the returned exit code.

Expected behaviour:

npm run build
# -> some build error happens
Error: Encountered errors while building app
    at /.../node_modules/sapper/cli.js:80:24
echo $?
127

What currently happens:

npm run build
# -> some build error happens
Error: Encountered errors while building app
    at /.../node_modules/sapper/cli.js:80:24
echo $?
0

This would allow detection of broken builds.

Generate blog posts from Markdown files

See

// Ordinarily, you'd generate this data from markdown files in your
// repo, or fetch them from a database of some kind. But in order to
// avoid unnecessary dependencies in the starter template, and in the
// service of obviousness, we're just going to leave it here.

Generating blog post HTML from Markdown is common enough that IMHO it makes sense to have this be part of the template. Or maybe there could be a separate sapper-blog-template that does this.

Directly visiting the blog pages hangs the response

If I open localhost:3000/ and then click the blog link, it works fine. I suppose it is just refreshing the DOM on the client side.

However, opening localhost:3000/blog directly, by entering the URL in the browser (or by reloading the page), results in no response from the server.

Similar behaviour for the individual blog pages, such as localhost:3000/blog/what-is-sapper.

And same behavior on both the webpack and the rollup branches.

Suggestion: non-precached assets folder

While it's trivial to create a new folder for static assets and the service worker tells us all files in assets are precached, this might not be obvious to newcomers (especially if they are not familiar with service workers).

Perhaps explicitly having two asset folders would ease their way into sapper.

Enabling custom elements prevents hot reloading

I have noticed that enabling custom elements when using webpack (not sure about rollup) prevents hot reloading from working.

I tested this with a fresh install of this template and adding tag names to all routes, pages and components and enabling customElement: true in both client.config.js and server.config.js.

Template for client-only PWAs ?

Hi,

A small open question : I plan to use sapper-template to experiment with client-side only PWAs. First for myself and small projects, but it also could be interesting to other people.

What would be the best way ?

  • maintaining a boilerplate as a subset of this template
    • in this case, is a shell script modifying this template a good idea ? (trimming the serverside/SSR part)
  • starting from scratch

It could be saw as a dumb question :) but I find the neat build configuration and tooling packed with the sapper template very useful and well done.

Rollup branch seems broken for windows paths

The rollup branch is at the very least outputting some unfortunate-looking paths and acting very broken. webpack version works fine however.

PS C:\Users\Patrick\Desktop\sapper-rollup> npx sapper dev
✔ server (669ms)
• client
outesindex.css' is imported by routes\index.html, but could not be resolved – treating it as an external dependency
outes_layout.css' is imported by routes\_layout.html, but could not be resolved – treating it as an external dependency
outes_error.css' is imported by routes\_error.html, but could not be resolved – treating it as an external dependency
'C:UsersPatrickDesktopsapper-rollupcomponentsNav.css' is imported by components\Nav.html, but could not be resolved – treating it as an external dependency
outelogindex.css' is imported by routes\blog\index.html, but could not be resolved – treating it as an external dependency
outelog[slug].css' is imported by routes\blog\[slug].html, but could not be resolved – treating it as an external dependency
✗ client
Could not find chunk that owns blog/index.html

I also tried building the client directly using rollup in case that was more illuminating.

PS C:\Users\Patrick\Desktop\sapper-rollup> npx rollup --config .\rollup\client.config.js

C:\Users\Patrick\Desktop\sapper-rollup\app/client.js → .sapper\dev\client...
  1 | import { a as append, b as assign, c as children, d as claimElement, e as claimText, f as createElement, g as createText, h as detachNode, i as init, j as insert, k as proto, l as flush, m as getSpreadUpdate, n as setData } from './chunk.1dd3859c.js';
  2 | import 'C:UsersPatrickDesktopsapper-rollupcomponentsNav.css';
> 3 | import 'C:UsersPatrickDesktopsapper-rollup
    |       ^ Unterminated string constant
  4 | outes_layout.css';
  5 | import 'C:UsersPatrickDesktopsapper-rollup
  6 | outes_error.css';
  1 | import { a as append, b as assign, c as children, d as claimElement, e as claimText, f as createElement, g as createText, h as detachNode, i as init, j as insert, o as noop, k as proto } from './chunk.1dd3859c.js';
> 2 | import 'C:UsersPatrickDesktopsapper-rollup
    |       ^ Unterminated string constant
  3 | outesindex.css';
  4 |
  5 | /* routes\index.html generated by Svelte v2.13.2 */
  1 | import { a as append, b as assign, c as children, d as claimElement, e as claimText, f as createElement, g as createText, p as destroyEach, h as detachNode, i as init, j as insert, k as proto, n as setData } from './chunk.1dd3859c.js';
> 2 | import 'C:UsersPatrickDesktopsapper-rollup
    |       ^ Unterminated string constant
  3 | outelogindex.css';
  4 |
  5 | /* routes\blog\index.html generated by Svelte v2.13.2 */
  1 | import { a as append, b as assign, c as children, d as claimElement, e as claimText, f as createElement, g as createText, h as detachNode, i as init, j as insert, k as proto, n as setData } from './chunk.1dd3859c.js';
> 2 | import 'C:UsersPatrickDesktopsapper-rollup
    |       ^ Unterminated string constant
  3 | outelog[slug].css';
  4 |
  5 | /* routes\blog\[slug].html generated by Svelte v2.13.2 */
(!) Unresolved dependencies
https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency
outes_error.css (imported by routes\_error.html)
outes_layout.css (imported by routes\_layout.html)
outesindex.css (imported by routes\index.html)
C:UsersPatrickDesktopsapper-rollupcomponentsNav.css (imported by components\Nav.html)
outelog[slug].css (imported by routes\blog\[slug].html)
outelogindex.css (imported by routes\blog\index.html)
[!] (terser plugin) SyntaxError: Error transforming bundle with 'terser' plugin: Unterminated string constant
SyntaxError: Error transforming bundle with 'terser' plugin: Unterminated string constant
    at JS_Parse_Error.get (eval at <anonymous> (C:\Users\Patrick\Desktop\sapper-rollup\node_modules\terser\tools\node.js:21:1), <anonymous>:75:23)
    at handleError (C:\Users\Patrick\Desktop\sapper-rollup\node_modules\rollup\bin\rollup:738:35)
    at C:\Users\Patrick\Desktop\sapper-rollup\node_modules\rollup\bin\rollup:1193:9
    at <anonymous>

Here's my environment info:

PS C:\Users\Patrick\Desktop\sapper-rollup> npm --versions
{ TODO: '0.0.1',
  npm: '6.4.1',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.29.0',
  node: '8.11.2',
  openssl: '1.0.2o',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.54',
  zlib: '1.2.11' }
PS C:\Users\Patrick\Desktop\sapper-rollup> node -p process.platform
win32

Rollup template npm run build not producing index.js

I've migrated from webpack to rollup and despite a few minor minor issues I got it to a point where I could push it live to replace my webpack build. However upon pushing to the server, clearing node_modules, running npm i, then npm run build and finally npm start, i'm seeing a failure.

Here's the log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/runcloud/webapps/docs/frontend/node_modules/.bin:/home/runcloud/.local/bin:/RunCloud/Packages/httpd-rc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle [email protected]~start: CWD: /home/runcloud/webapps/docs/frontend
10 silly lifecycle [email protected]~start: Args: [ '-c', 'node __sapper__/build' ]
11 silly lifecycle [email protected]~start: Returned: code: 1  signal: null
12 info lifecycle [email protected]~start: Failed to exec start script
13 verbose stack Error: [email protected] start: `node __sapper__/build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:915:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid [email protected]
15 verbose cwd /home/runcloud/webapps/docs/frontend
16 verbose Linux 4.15.0-36-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
18 verbose node v8.12.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] start: `node __sapper__/build`
22 error Exit status 1
23 error Failed at the [email protected] start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Looks like maybe sapper/build is missing the index.js perhaps?

Closure compiler support

Moving this issue by @maxmilton from sapper-template-rollup, since I'm about to delete it in favour of the rollup branch on this repo:


After an epic debugging session this morning trying to get Closure Compiler working with this project I ran into some showstoppers.

The service worker will compile with only small changes, however, compiling the other JS bundles is another story. Due to the use of dynamic import, import(), the compiler ran into issues.

@ampproject/rollup-plugin-closure-compiler can't parse import() because it's using acorn which doesn't support it out of the box. I've created an issue over there suggesting they use acorn-dynamic-import to add support: ampproject/rollup-plugin-closure-compiler#48.

Even after I was able to implement a workaround with @ampproject/rollup-plugin-closure-compiler locally, I discovered Closure Compiler itself can't parse import() at all and throws an error preventing the build. Opened an issue for that too: google/closure-compiler#2770.

So as it stands, both of these are blockers preventing us from using Closure Compiler right now.


FYI the progress I made is in https://github.com/MaxMilton/sapper-template-rollup/tree/feat/use-closure-compiler.

npm run dev is fine, but npm run build fails on windows (7)

ERROR in ./routes/index.html
Module not found: Error: Can't resolve 'C:Users c7AppDataLocalTemp/svelte-1190322880.css' in 'C:\Apps\Testarea\svelte\sapper\my-app\routes'
@ ./routes/index.html 158:0-64
@ ./templates/.main.rendered.js

.....
.....

Module not found: Can't resolve ....

I was testing the tutorial to install sapper-template. and when I run npm run dev. I found Module not found: can not solve 'E: proyectossveltemy-app'. The platform that I am using Windows 10.

Missing dependency `tslib`

Hi - ran the setup instructions (on Windows 10) and after npm install tried running npm run dev - server fails to startup; Cannot find module 'tslib'. Adding tslib to the root package.json dependencies seems to fix it.

Here's the output:

C:\Users\Me\sapper\my-app>npm run dev

> [email protected] dev C:\Users\Me\sapper\my-app
> sapper dev

module.js:557
    throw err;
    ^

Error: Cannot find module 'tslib'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Me\sapper\my-app\node_modules\sapper\dist\cli.ts.js:5:15)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `sapper dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Me\AppData\Roaming\npm-cache\_logs\2018-03-12T01_38_01_754Z-debug.log

Don't include source map files in service worker output

When generating the service worker manifest file (app/manifest/service-worker.js) it currently also includes source map files (e.g. "client/fbd4e5d87f8d7dec1966/main.0.js.map"). These files don't belong here and should be excluded. Perhaps there could be some way for the developer to exclude arbitrary files here?

Once this is implemented, it would be worth considering enabling source map generation in production builds.

preload doesn't work in root page (src/routes/index.html) after visiting a 404

Issue description

Navigating on root page (source at src/routes/index.html), which loads data on preload, doesn't load data (warning <Index> was created without expected data property) only after visiting a 404 page.

How to reproduce

  • Clone repo
  • npm install
  • npm run dev
  • Navigate to about route (which return 404) and click on Home to see that data is not loaded.
    Try instead to navigate to about and then blog: data is loaded there even if blog and /index.html have the same logic.

Testing

Have wrestled a bit with the question of how to adequately test something like Sapper. I think the easiest thing to do is test a sample application instead, and this one is an obvious candidate.

At the same time, the apps themselves need to have a good, obvious way to test them.

Makes sense therefore to do the initial work here, then add tests in the Sapper repo that basically just run the tests for this app.

Gleb Bahmutov was kind enough to write up his experience of using Cypress to test a Svelte app, and I think Cypress is probably the right go-to choice for testing Sapper apps.

hangs on windows currently

error at handle_route()

Module not found: Error: Can't resolve 'c:AppsTestareasvelte_sappermyappoutes/about.html' in 'c:\Apps\Testarea\svelte_sapper\myapp.sapper'

Also error messages suggest a typo:
outes rather than routes

"./.sapper/server-routes.js
Module not found: Error: Can't resolve 'c:AppsTestareasvelte_sappermyappoutes/about.html' in 'c:\Apps\Testarea\svelte_sapper\myapp.sapper'
resolve 'c:AppsTestareasvelte_sappermyapp
outes/about.html' in 'c:\Apps\Testarea\svelte_sapper\myapp.sapper'
Parsed request is a module
using description file: c:\Apps\Testarea\svelte_sapper\myapp\package.json (relative path: ./.sapper)
after using description file: c:\Apps\Testarea\svelte_sapper\myapp\package.json (relative path: ./.sapper)
resolve as module
c:\Apps\Testarea\svelte_sapper\myapp.sapper\node_modules doesn't exist or is not a directory
c:\Apps\Testarea\svelte_sapper\node_modules doesn't exist or is not a directory
c:\Apps\Testarea\svelte\node_modules doesn't exist or is not a directory
c:\Apps\Testarea\node_modules doesn't exist or is not a directory
c:\Apps\node_modules doesn't exist or is not a directory
c:\node_modules doesn't exist or is not a directory
looking for modules in c:\Apps\Testarea\svelte_sapper\myapp\node_modules
using description file: c:\Apps\Testarea\svelte_sapper\myapp\package.json (relative path: ./node_modules)
after using description file: c:\Apps\Testarea\svelte_sapper\myapp\package.json (relative path: ./node_modules)
using description file: c:\Apps\Testarea\svelte_sapper\myapp\package.json (relative path: ./node_modules/c:AppsTestareasvelte_sappermyappoutes/about.html)
no extension
c:\Apps\Testarea\svelte_sapper\myapp\node_modules\c:AppsTestareasvelte_sappermyappoutes\about.html doesn't exist
.js
c:\Apps\Testarea\svelte_sapper\myapp\node_modules\c:AppsTestareasvelte_sappermyappoutes\about.html.js doesn't exist
.html
c:\Apps\Testarea\svelte_sapper\myapp\node_modules\c:AppsTestareasvelte_sappermyappoutes\about.html.html doesn't exist
as directory
c:\Apps\Testarea\svelte_sapper\myapp\node_modules\c:AppsTestareasvelte_sappermyappoutes\about.html doesn't exist
[c:\Apps\Testarea\svelte_sapper\myapp.sapper\node_modules]
[c:\Apps\Testarea\svelte_sapper\node_modules]
[c:\Apps\Testarea\svelte\node_modules]
[c:\Apps\Testarea\node_modules]
[c:\Apps\node_modules]
[c:\node_modules]
[c:\Apps\Testarea\svelte_sapper\myapp\node_modules\c:AppsTestareasvelte_sappermyappoutes\about.html]
[c:\Apps\Testarea\svelte_sapper\myapp\node_modules\c:AppsTestareasvelte_sappermyappoutes\about.html.js]
[c:\Apps\Testarea\svelte_sapper\myapp\node_modules\c:AppsTestareasvelte_sappermyappoutes\about.html.html]
[c:\Apps\Testarea\svelte_sapper\myapp\node_modules\c:AppsTestareasvelte_sappermyappoutes\about.html]
@ ./.sapper/server-routes.js 1:0-76"

HMR not working

Changing any file generates following error:

Uncaught (in promise) Error: Manifest request to client/4b956183ae495052a330.hot-update.json timed out.
    at XMLHttpRequest.request.onreadystatechange

I added a timeout according to this comment, but I'm still getting the error. Changes are not appearing.

Don't tie `mode` to `NODE_ENV` in Webpack config

Was getting the following bug when NODE_ENV was set to staging:

$ sapper build
> Building...
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.mode should be one of these:
   "development" | "production" | "none"

In other words, mode is not vis-a-vis the same as NODE_ENV in Webpack land. So this won't fly:

const mode = process.env.NODE_ENV;

Gosh. 🙃

We could in theory do something like the following:

const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';

But that's pretty limiting. CLI option? ENV var? https://webpack.js.org/concepts/mode/ mentions passing as config:

webpack --mode=production

Now Deployment

When I attempt to deploy to the Now 2.0 nerveless, it does not produce a working app, just shows the file system of the app in web browser,

Nicer maintenance of Rollup and Webpack branches

See conversation on this commit.

I've thrown together a possible initial implementation of this here. Running _template/build.sh creates and force-pushes two branches rollup and webpack from the current master - each with appropriate package.json customization and removes the other bundler's config file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.