All Projects โ†’ jakedeichert โ†’ Svelvet

jakedeichert / Svelvet

Licence: mit
๐Ÿงต An experimental svelte compiler & watcher that works with snowpack

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Svelvet

Pundle
๐Ÿ‘พ peaceful bundles - js bundler, built from the ground up for speed and extensibility
Stars: โœญ 354 (+14.19%)
Mutual labels:  bundler, cli
Wago
Automate the actions you do after saving code.
Stars: โœญ 60 (-80.65%)
Mutual labels:  cli, watcher
Nexe
๐ŸŽ‰ create a single executable out of your node.js apps
Stars: โœญ 10,565 (+3308.06%)
Mutual labels:  bundler, cli
Baelte
CLI tool for svelte to help you be productive
Stars: โœญ 85 (-72.58%)
Mutual labels:  cli, svelte
Carton
๐Ÿ“ฆ Watcher, bundler, and test runner for your SwiftWasm apps
Stars: โœญ 171 (-44.84%)
Mutual labels:  bundler, watcher
Notebook As Pdf
Save Jupyter Notebooks as PDF
Stars: โœญ 290 (-6.45%)
Mutual labels:  bundler
Create Node Cli
๐Ÿ“Ÿ CLI to create new Node.js CLI applications in minutes not hours.
Stars: โœญ 304 (-1.94%)
Mutual labels:  cli
Torrentflix
Nodejs cli app to search torrent sites and stream using peerflix
Stars: โœญ 298 (-3.87%)
Mutual labels:  cli
Define
A command-line dictionary (thesaurus) app, with access to multiple sources, written in Go.
Stars: โœญ 298 (-3.87%)
Mutual labels:  cli
Rawkit
๐ŸฆŠ Immediately Open Chrome DevTools when debugging Node.js apps
Stars: โœญ 306 (-1.29%)
Mutual labels:  cli
Singlefile
Web Extension for Firefox/Chrome/MS Edge and CLI tool to save a faithful copy of an entire web page in a single HTML file
Stars: โœญ 4,417 (+1324.84%)
Mutual labels:  cli
To lang
Translate Ruby strings and arrays with Google Translate.
Stars: โœญ 303 (-2.26%)
Mutual labels:  cli
Mnamer
media file renamer and organizion tool
Stars: โœญ 299 (-3.55%)
Mutual labels:  cli
Frankenstein
Correct README Redirects
Stars: โœญ 305 (-1.61%)
Mutual labels:  cli
Scmpuff
๐Ÿ”ข Numeric file shortcuts for common git commands
Stars: โœญ 299 (-3.55%)
Mutual labels:  cli
Ludusavi
Backup tool for PC game saves
Stars: โœญ 301 (-2.9%)
Mutual labels:  cli
Gkill
Interactice process killer for Linux and macOS
Stars: โœญ 297 (-4.19%)
Mutual labels:  cli
Git Archive All
A python script wrapper for git-archive that archives a git superproject and its submodules, if it has any. Takes into account .gitattributes
Stars: โœญ 302 (-2.58%)
Mutual labels:  cli
Bullet
๐Ÿš… Interactive prompts made simple. Build a prompt like stacking blocks.
Stars: โœญ 3,257 (+950.65%)
Mutual labels:  cli
Jinja2 Cli
CLI for Jinja2
Stars: โœญ 302 (-2.58%)
Mutual labels:  cli

svelvet

build status npm version

An experimental svelte compiler & watcher that works with snowpack.

Alternatives

Svelvet was built on top of snowpack v1. At the time, there was no easy way to get svelte and snowpack playing nicely together. That has changed however as snowpack v2 now has built-in support for svelte!

Due to this and production performance issues with esm, I don't plan on continuing to support svelvet.

If you're looking for a fast bundler for dev and production, check out snowpack v2. Another alternative is to migrate to rollup by following this guide.

Goals

  • No bundler required
  • No config required
  • Integrate directly with snowpack for an optimal experience
  • Instant dev watch & rebuild cycle
  • Fast production builds that are optimized & tree-shaken
  • Keep your node_modules super light
  • Only support browsers that work with esm
  • Only support standard esm imports (no css/image/custom-loader-like imports)

How it works

The goal of svelvet is to make svelte play nicely with snowpack and web_modules.

As of today, svelte depends on a loader for webpack or rollup which compiles your svelte components into individual js files. Since snowpack's goal is to avoid the need for a bundler, we can't use those loaders, but we can use svelte's internal compiler api to do 95% of the work for us. On top of that, svelvet adds automatic file watching to recompile your svelte files just like a loader would, but much faster!

To do this, svelvet finds all your src/**/*.svelte files and compiles them to public/dist/**/*.js. On the initial build, we run snowpack (only once) to find all imported third-party dependencies and generate esm versions of them in public/dist/web_modules/. After the initial build, svelvet just watches for new or changed files and recompiles them instantly!

Getting started

Create a new project and add the required dependencies. An example project is set up here.

# svelte is a peer dep required by svelvet. You get to choose which
# version to use and when to upgrade!
npm install svelte

# Install the svelvet cli (requires node v10 or higher)
npm install svelvet --save-dev

Add a few simple scripts as seen here:

"scripts": {
    // This starts svelvet in watch mode and runs snowpack once to generate public/dist/web_modules.
    // It also starts a live reloading dev server to serve the public directory on localhost:8080.
    "dev": "svelvet",

    // This builds the public/dist directory optimized for production with snowpack
    "build": "NODE_ENV=production svelvet"
},

And finally, add some svelte components to the src directory!

All svelte and js files must be stored inside the src directory so svelvet can compile them into the public/dist directory.

All static assets must be stored inside the public directory which is what you'll deploy.

Use npm run dev to compile in dev mode. This watches for file changes, compiles to dist and starts a live reloading dev server on localhost:8080.

To optimize a build for production, use npm run build.

You also must have a public/index.html file that loads your entrypoint or root svelte component.

<!-- Example: public/index.html -->
<!DOCTYPE html>
<html lang="en">
    <body>
        <div id="app"></div>

        <script type="module">
            // If you have a component named src/App.svelte, it will get
            // compiled to public/dist/App.js
            import App from '/dist/App.js';

            new App({
                target: document.querySelector('#app'),
            });
        </script>
    </body>
</html>

Known issues

Automatically support importing 3rd party svelte files (Issue #49)

Support for referencing svelte components from other packages is not built-in yet. For now, you must run npm i -D rollup-plugin-svelte and then create a snowpack.config.js file like this:

const rollupPluginSvelte = require('rollup-plugin-svelte');

module.exports = {
    rollup: {
        plugins: [
            rollupPluginSvelte({
                dev: process.env.NODE_ENV !== 'production',
            }),
        ],
    },
};

A full example can be found here.

FAQ

Why not just use webpack or rollup?

I don't need to support non-esm browsers for most projects and I really like the idea of a super light build process. By removing the complexity of configuration and the overhead of bundling, svelvet makes the development process an optimal experience for myself and hopefully others :)

Many of you will not be able to use this if you depend on custom import types or other fancy loaders. This project is just not for you!

But seriously, give snowpack a read to understand the benefits of leaning on standard esm imports, allowing you to avoid a bundling process entirely.

Can I override the babel config?

Yes! Just create a babel.config.js file in the root of your project, and that should be properly picked up by svelvet and snowpack. You must copy this example config as a starting point to ensure you have the required plugin set up properly.

Can I use the hydratable or immutable svelte options?

Yeah, just run svelvet with the --hydratable or --immutable args to enable those options!

Can I preprocess my svelte components?

Yupp! You can configure one or more preprocessors that will run before your code gets compiled by svelte. This means you can use typescript, pug, sass, postcss or whatever else your chosen preprocessor is capable of handling.

When running svelvet, you can now pass a --preprocess my-preprocess.js option. The script that you specify just needs to return an array of preprocessors.

Here's an example using svelte-preprocess:

// my-preprocess.js
const autoPreprocess = require('svelte-preprocess');

module.exports = [
    autoPreprocess({
        typescript: {
            compilerOptions: {
                target: 'es2020',
                module: 'es2020',
                baseUrl: './src',
            },
            transpileOnly: true,
        },
    }),
];

Check out the full example here.

Why don't imports automatically resolve index.svelte or index.js?

If you have a structure like src/components/Footer/index.svelte, you cannot rely on index.svelte being auto resolved. Standard esm doesn't auto resolve index.js files, so when you import this component, you must use a full path to the index.

โŒ Bad: import Footer from './components/Footer';

โœ… Good: import Footer from './components/Footer/index';

Notably, you should leave off the extension. This is automatically added during the transform phase.

What happens to the component css?

By default, svelte compiles your component css and inserts style tags into the DOM at runtime. More advanced css bundling techniques are not supported yet.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].