omi-template-loader

1.1.2 • Public • Published

Install

Webpack loader for Omi Single-File Components

You can use npm install or git clone it.

npm install eno-loader --save-dev

Configuration webpack file like this:

module: {
    rules: [{
        test: /\.omi|eno$/,
        use: ['eno-loader']
    }]
}

Loader Demo

Why Eno Loader?

eno-loader is a loader for webpack that allows you to author Omi components in a format called Single-File Components

Usage

A *.omi file is a custom file format that uses HTML-like syntax to describe a Omi component. Each *.omi file consists of three types of top-level language blocks: <template>, <script>, and <style>, and optionally additional custom blocks:

<template lang="html">
  <!-- replace render function -->
  <header onClick="${this.test}">${this.data.title}</header>
</template>
<script>
import style from './_oHeader.css'
export default {
  css() {
    return style // it will combine scoped css
  }
  test(){
    console.log('Hello Eno!')
  }
  install() {
    this.data = {
      title: 'Omi'
    }
  }
}
</script>
<style>
/* scoped css */
header {
  height: 50px;
  background-color: #07c160;
  color: white;
  text-align: center;
  line-height: 50px;
  width: 100%;
}
</style>

Single-File Components Demo

It also supports JSX, if you want to do that, you only write <template> without lang="html" attribute in your component like this:

<template>
  <header onClick={this.test}>{this.data.title}</header>
</template>

JSX Demo

eno-loader supports using non-default languages, such as CSS pre-processors and compile-to-HTML template languages, by specifying the lang attribute for a language block. For example, you install node-sass after you can use Sass for the style of your component like this:

<style lang="scss">
$height: 50px;
$color: #07c160;
header {
  height: $height;
  background-color: $color;
}
</style>

Sass Demo

There are many cool features provided by eno-loader:

  • Allows using other webpack loaders for each part of a Omi component, for example Sass for <style lang="scss"> and JSX/HTML for <template lang="html">;
  • Allows custom blocks in a .omi or .eno file that can have custom loader chains applied to them Here Online Demo;
  • Treat static assets referenced in <style> and <template> as module dependencies and handle them with webpack loaders (Such as htm, to-string-loader);
  • Simulate scoped CSS for each component (Use Shadow DOM);
  • State-preserving hot-reloading during development.

In a nutshell, the combination of webpack and eno-loader gives you a modern, flexible and extremely powerful front-end workflow for authoring Omi.js applications.

Thanks

License

MIT

Package Sidebar

Install

npm i omi-template-loader

Weekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

162 kB

Total Files

29

Last publish

Collaborators

  • autumnswind