GithubHelp home page GithubHelp logo

r00t3g / melte Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zodern/melte

2.0 1.0 0.0 195 KB

Svelte compiler for Meteor with built in tracker integration and HMR

License: MIT License

JavaScript 100.00%

melte's Introduction

r00t3g:melte

Build cybernetically enhanced web apps with Meteor and Svelte.

Based on meteor-svelte with these added features:

  • Support for hot module replacement (HMR) to update modified components without requiring a full page reload. Requires your app to use Meteor 2 and the hot-module-replacement package.
  • Handles syntax errors without crashing
  • Supports Typescript preprocessing for script blocks
  • Supports SCSS preprocessing and global attribute for style blocks

Tested ONLY with Meteor 2.1

Important information

WARNING!
Since 2022-01-14 v. 1.4.10 this plugin no longer supports $m reactive statements and PostCSS since they are not needed in the maintainer's projects! However, this increases the overall build performance and in case you do not use Meteor reactivity in Svelte components, you may benefit from using this version

NOTE:
This plugin is based on zodern:melte, implements Typescript and SCSS preprocessing for Svelte components, and exists only until the changes are stabilized and accepted by @zodern. For now this package is made for use within one certain project and yet is not production tested and is to be used at own risk. Please read through this README thoroughly to be aware of certain limitations and drawbacks introduced by this plugin! It is highly recommended to use the original plugin from https://github.com/zodern/melte for, now unless you are 100% sure what you are doing

Changelog

  • 2022-01-14: 1.4.10 [BREAKING] Properly handle css compiler option, $m and PostCSS support dropped
  • 2021-10-13: 1.4.9 Add options hash for babel cache suffix, add support for dev and cssHash compilerOptions
  • 2021-09-26: 1.4.8 Properly handle babel compilation errors
  • 2021-06-25: v.1.4.7 Multiple improvements:
    • Fix relative import paths in SCSS
    • Allow multiple <style global /> tags in Svelte components
  • 2021-04-16: v.1.4.6 Meteor-compatible paths support in SCSS imports
  • 2021-04-02: v.1.4.5 Upstream sync, reactive labels imports fix (#1)
  • 2021-03-16: v.1.4.4 Basic TS and CSS preprocessing support added

Installation

To use r00t3g:melte, run the following commands:

$ meteor add r00t3g:melte
$ meteor npm install svelte svelte-preprocess 

Options

Compiler options can be specified with a "svelte:compiler" property in package.json. For example:

{
  ...
  "svelte:compiler": {
    "extensions": [
      "svelte",
      "html"
    ],
    "hydratable": true,
    "css": false
  }
}

extensions (default: ["svelte"])

An array of file extensions to be recognized by the package. Note that HTML files are not compiled with the Svelte compiler if they contain top-level <head> or <body> elements. Instead, the contents of the elements are added to the respective sections in the HTML output generated by Meteor (similar to what the static-html package does).

hydratable (default: false)

By default, Svelte removes server-rendered static HTML when the application is loaded on the client and replaces it with a client-rendered version. If you want to reuse (hydrate) server-rendered HTML, set the hydratable option to true ( which generates additional code for client components) and use the hydrate option when instantiating your root component.

css (default: true)

Svelte can extract styles for server-side rendering. If you want to render CSS on the server, you might want to set the css option to false so that client-rendered components don't insert CSS into the DOM.

Preprocessing

Scripts

Currently, only Typescript preprocessing is supported for script blocks with lang="ts" attribute set. In order to get preprocessing working, additional NPM-packages need to be installed:

$ meteor npm i --save-dev svelte-preprocess typescript

It is highly recommended to use TS version, supported by the Meteor release you are using.

Styles

SCSS preprocessing is available for style blocks and is enabled for components by adding lang="scss" attribute. Just as with scripts, an installation of the toolkit is required to use SCSS reprocessing:

$ meteor npm i --save-dev svelte-preprocess node-sass

It is highly recommended to use node-sass (libsass) version of the SCSS compiler, however, Dart version should also work well.

Style limitations:

  • In accordance with svlete-preprocess documentation, global styles are also supported, but ONLY by adding the global attribute and NOT by the :global rule.

  • SCSS transformer does not use Meteor resolver which makes it impossible to imports styles from Atmosphere packages.

  • For the same reason, all imports paths must be specified relatively to application root, e.g.:

@import '/client/style/theme.scss';

or

@import '/imports/style/variables.scss';
  • To import files from node_modules, the import path must be prefixed with a tilde (~), e.g.:
@import '~/my-awesome-library/lib/scss/library.scss';

or

@import '~/material-design-icons/iconfont/material-icons.css';

Server-Side Rendering

meteor-svelte supports server-side rendering with minimal configuration. If you import Svelte components on the server, they are automatically built for server-side rendering. See the Svelte API docs, the example app, and the hydratable and css options above for more details.

Examples

melte's People

Contributors

elidoran avatar faburem avatar klaussner avatar r00t3g avatar zimme avatar zodern avatar

Stargazers

 avatar  avatar

Watchers

 avatar

melte's Issues

Cannot find module 'meteor/zodern:melte/tracker'

Hello all,

I'm experiencing the following error when integrating melte/tracker. I'm very interested in the TS support with the reactive $m tracker. I'm running on Meteor 2.1, Ubuntu 18.04LTS. Thank you!

modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:232 Uncaught Error: Cannot find module 'meteor/zodern:melte/tracker'

Package.json

{
  "name": "qr-code",
  "private": true,
  "scripts": {
    "start": "meteor",
    "test": "meteor test --once --driver-package meteortesting:mocha",
    "test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
    "visualize": "meteor --production --extra-packages bundle-visualizer",
    "deploy": "cd .deploy && mup deploy && cd ..",
    "ngrok": "cd ./ngrok && ./ngrok http 3000"
  },
  "svelte:compiler": {
    "extensions": [
      "svelte",
      "html"
    ],
    "hydratable": true,
    "css": false
  },
  "dependencies": {
    "@babel/runtime": "^7.8.3",
    "@tailwindcss/forms": "^0.2.1",
    "@tailwindcss/ui": "^0.7.2",
    "array-move": "^3.0.1",
    "bcrypt": "^5.0.0",
    "date-fns": "^2.17.0",
    "dotenv": "^8.2.0",
    "jquery": "^3.4.1",
    "meteor-node-stubs": "^1.0.0",
    "plaid": "^8.1.4",
    "qr-code-scanner": "^1.0.8",
    "qr-scanner": "^1.2.0",
    "qrcode": "^1.4.4",
    "svelte": "^3.37.0",
    "svelte-preprocess": "^4.7.0",
    "svelte-routing": "^1.5.0"
  },
  "meteor": {
    "mainModule": {
      "client": "client/main.js",
      "server": "server/main.js"
    },
    "testModule": "tests/main.js"
  },
  "devDependencies": {
    "@tailwindcss/jit": "^0.1.3",
    "autoprefixer": "^10.2.3",
    "babel-eslint": "^10.1.0",
    "eslint": "^7.19.0",
    "eslint-plugin-svelte3": "^3.0.0",
    "postcss": "^8.2.8",
    "postcss-import": "^14.0.0",
    "postcss-load-config": "^3.0.0",
    "prettier": "^2.2.1",
    "prettier-plugin-svelte": "^2.1.4",
    "tailwindcss": "^2.0.4"
  }
}

.meteor/packages

{
  "name": "qr-code",
  "private": true,
  "scripts": {
    "start": "meteor",
    "test": "meteor test --once --driver-package meteortesting:mocha",
    "test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
    "visualize": "meteor --production --extra-packages bundle-visualizer",
    "deploy": "cd .deploy && mup deploy && cd ..",
    "ngrok": "cd ./ngrok && ./ngrok http 3000"
  },
  "svelte:compiler": {
    "extensions": [
      "svelte",
      "html"
    ],
    "hydratable": true,
    "css": false
  },
  "dependencies": {
    "@babel/runtime": "^7.8.3",
    "@tailwindcss/forms": "^0.2.1",
    "@tailwindcss/ui": "^0.7.2",
    "array-move": "^3.0.1",
    "bcrypt": "^5.0.0",
    "date-fns": "^2.17.0",
    "dotenv": "^8.2.0",
    "jquery": "^3.4.1",
    "meteor-node-stubs": "^1.0.0",
    "plaid": "^8.1.4",
    "qr-code-scanner": "^1.0.8",
    "qr-scanner": "^1.2.0",
    "qrcode": "^1.4.4",
    "svelte": "^3.37.0",
    "svelte-preprocess": "^4.7.0",
    "svelte-routing": "^1.5.0"
  },
  "meteor": {
    "mainModule": {
      "client": "client/main.js",
      "server": "server/main.js"
    },
    "testModule": "tests/main.js"
  },
  "devDependencies": {
    "@tailwindcss/jit": "^0.1.3",
    "autoprefixer": "^10.2.3",
    "babel-eslint": "^10.1.0",
    "eslint": "^7.19.0",
    "eslint-plugin-svelte3": "^3.0.0",
    "postcss": "^8.2.8",
    "postcss-import": "^14.0.0",
    "postcss-load-config": "^3.0.0",
    "prettier": "^2.2.1",
    "prettier-plugin-svelte": "^2.1.4",
    "tailwindcss": "^2.0.4"
  }
}

Dependency to SCSS files is not properly tracked for files with errors

When a compilation occurs in SCSS code, the dependency between .svelte and .scss file is not tracked properly. This leads to the necessity to change the .svelte file after the SCSS code is fixed to trigger the rebuild.

To fix it a call to file.readAndWatchFile is required inside the try/catch block wrapping the await processCode call for scss preprocessing routine.

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.