Skip to content

Commit

Permalink
feat: introucing svelte package and sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroerta committed May 20, 2021
1 parent 02d3234 commit 0e8e9e2
Show file tree
Hide file tree
Showing 38 changed files with 740 additions and 43 deletions.
3 changes: 3 additions & 0 deletions apps/benchmarks/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
12 changes: 8 additions & 4 deletions apps/benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
"email": "[email protected]"
},
"scripts": {
"morfeo-vs": "node src/morfeo-vs/index.js",
"core": "node src/core/index.js",
"jss": "node src/jss/index.js",
"all": "npm run core && npm run jss && npm run morfeo-vs"
"build": "rimraf build && babel ./src/ --out-dir build/ --ignore ./node_modules",
"morfeo-vs": "node build/morfeo-vs/index.js",
"core": "node build/core/index.js",
"jss": "node build/jss/index.js",
"all": "npm run build && npm run core && npm run jss && npm run morfeo-vs"
},
"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"benchmark": "^2.1.4"
},
"dependencies": {
Expand Down
16 changes: 8 additions & 8 deletions apps/benchmarks/results/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
}
```

**regular parsing** 1,560,270 ops/sec ±2.01% (84 runs sampled)
**regular parsing** 1,763,585 ops/sec ±0.77% (91 runs sampled)

**with cache enabled** 2,950,728 ops/sec ±0.88% (89 runs sampled)
**with cache enabled** 3,327,487 ops/sec ±1.13% (95 runs sampled)

Fastest is **with cache enabled**

Expand All @@ -23,9 +23,9 @@ Fastest is **with cache enabled**
}
```

**regular parsing** 822,836 ops/sec ±0.63% (93 runs sampled)
**regular parsing** 822,458 ops/sec ±2.70% (90 runs sampled)

**with cache enabled** 1,763,224 ops/sec ±1.10% (85 runs sampled)
**with cache enabled** 1,703,082 ops/sec ±1.05% (88 runs sampled)

Fastest is **with cache enabled**

Expand All @@ -38,9 +38,9 @@ Fastest is **with cache enabled**
}
```

**regular parsing** 136,781 ops/sec ±1.19% (92 runs sampled)
**regular parsing** 134,212 ops/sec ±1.09% (89 runs sampled)

**with cache enabled** 245,730 ops/sec ±0.96% (92 runs sampled)
**with cache enabled** 238,007 ops/sec ±1.02% (90 runs sampled)

Fastest is **with cache enabled**

Expand All @@ -58,8 +58,8 @@ Fastest is **with cache enabled**
}
```

**regular parsing** 58,332 ops/sec ±1.22% (85 runs sampled)
**regular parsing** 58,249 ops/sec ±1.07% (89 runs sampled)

**with cache enabled** 96,209 ops/sec ±0.86% (91 runs sampled)
**with cache enabled** 94,102 ops/sec ±0.66% (94 runs sampled)

Fastest is **with cache enabled**
4 changes: 2 additions & 2 deletions apps/benchmarks/results/jss.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
```

**regular parsing** 2,964,522 ops/sec ±0.74% (91 runs sampled)
**regular parsing** 549,704 ops/sec ±1.01% (92 runs sampled)

**jss** 196,230 ops/sec ±2.66% (87 runs sampled)
**jss** 206,599 ops/sec ±2.35% (92 runs sampled)

Fastest is **regular parsing**
4 changes: 2 additions & 2 deletions apps/benchmarks/results/morfeo-vs-styled-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
}
```

**morfeo** 415,502 ops/sec ±0.98% (94 runs sampled)
**morfeo** 411,153 ops/sec ±1.25% (93 runs sampled)

**styled system** 331,424 ops/sec ±1.17% (89 runs sampled)
**styled system** 279,202 ops/sec ±0.84% (91 runs sampled)

Fastest is **morfeo**
2 changes: 1 addition & 1 deletion apps/benchmarks/src/core/completeStyle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Benchmark = require('benchmark');
const { parsers } = require('@morfeo/core');
const { onCycle, onComplete, onStart, appendInMd } = require('./utils');
const { onCycle, onComplete, onStart } = require('./utils');

const suite = new Benchmark.Suite();

Expand Down
4 changes: 4 additions & 0 deletions apps/svelte-sandbox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/
/public/build/

.DS_Store
105 changes: 105 additions & 0 deletions apps/svelte-sandbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
*Looking for a shareable component template? Go here --> [sveltejs/component-template](https://github.com/sveltejs/component-template)*

---

# svelte app

This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template.

To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):

```bash
npx degit sveltejs/template svelte-app
cd svelte-app
```

*Note that you will need to have [Node.js](https://nodejs.org) installed.*


## Get started

Install the dependencies...

```bash
cd svelte-app
npm install
```

...then start [Rollup](https://rollupjs.org):

```bash
npm run dev
```

Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes.

By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`.

If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense.

## Building and running in production mode

To create an optimised version of the app:

```bash
npm run build
```

You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com).


## Single-page app mode

By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere.

If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json:

```js
"start": "sirv public --single"
```

## Using TypeScript

This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with:

```bash
node scripts/setupTypeScript.js
```

Or remove the script via:

```bash
rm scripts/setupTypeScript.js
```

## Deploying to the web

### With [Vercel](https://vercel.com)

Install `vercel` if you haven't already:

```bash
npm install -g vercel
```

Then, from within your project folder:

```bash
cd public
vercel deploy --name my-project
```

### With [surge](https://surge.sh/)

Install `surge` if you haven't already:

```bash
npm install -g surge
```

Then, from within your project folder:

```bash
npm run build
surge public my-project.surge.sh
```
27 changes: 27 additions & 0 deletions apps/svelte-sandbox/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "svelte-app",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public --no-clear"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"rollup": "^2.3.4",
"tslib": "^2.2.0",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^7.0.0",
"svelte": "^3.0.0"
},
"dependencies": {
"@morfeo/web": "^0.1.0",
"@morfeo/svelte": "^0.1.0",
"rollup-plugin-replace": "^2.2.0",
"sirv-cli": "^1.0.0"
}
}
Binary file added apps/svelte-sandbox/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions apps/svelte-sandbox/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width,initial-scale=1'>

<title>Svelte app</title>

<link rel='icon' type='image/png' href='/favicon.png'>
<link rel='stylesheet' href='/global.css'>
<link rel='stylesheet' href='/build/bundle.css'>

<script defer src='/build/bundle.js'></script>
</head>

<body>
</body>
</html>
82 changes: 82 additions & 0 deletions apps/svelte-sandbox/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import svelte from 'rollup-plugin-svelte';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import css from 'rollup-plugin-css-only';

const production = !process.env.ROLLUP_WATCH;

function serve() {
let server;

function toExit() {
if (server) server.kill(0);
}

return {
writeBundle() {
if (server) return;
server = require('child_process').spawn(
'npm',
['run', 'start', '--', '--dev'],
{
stdio: ['ignore', 'inherit', 'inherit'],
shell: true,
},
);

process.on('SIGTERM', toExit);
process.on('exit', toExit);
},
};
}

export default {
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: 'public/build/bundle.js',
},
plugins: [
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
svelte({
compilerOptions: {
// enable run-time checks when not in production
dev: !production,
},
}),
// we'll extract any component CSS out into
// a separate file - better for performance
css({ output: 'bundle.css' }),

// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ['svelte'],
}),
commonjs(),

// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),

// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),

// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser(),
],
watch: {
clearScreen: false,
},
};
Loading

0 comments on commit 0e8e9e2

Please sign in to comment.