# omi-snippets
**Repository Path**: wscats/omi-snippets
## Basic Information
- **Project Name**: omi-snippets
- **Description**: 剑走偏锋!实现React单文件组件和Webpack局部编译的IDE插件,可能是最好的React SFCs方案 - Visual Studio Code Syntax highlighting for single-file React and Omi components
- **Primary Language**: JavaScript
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: https://github.com/Wscats/omi-docs
- **GVP Project**: No
## Statistics
- **Stars**: 12
- **Forks**: 2
- **Created**: 2019-08-10
- **Last Updated**: 2025-06-03
## Categories & Tags
**Categories**: vsc-plugins
**Tags**: omi, React, snippets, VSCode
## README
# Eno and Omi Snippets
[Try it Now!](https://marketplace.visualstudio.com/items?itemName=Wscats.omi-snippets) Visual Studio Code syntax highlighting for single-file Omi.js components (enabled by omil). Or [Download Vsix!](https://github.com/Wscats/omi-snippets/releases/download/2.03/eno-2.0.3.vsix) to install in Visual Studio Code
> 下载地址 & Download: https://marketplace.visualstudio.com/items?itemName=Wscats.eno
> 项目地址 & Source Code : https://github.com/Wscats/omi-snippets
# Detailed Documentation
> 详细文档 & Document: https://github.com/Wscats/omi-docs
* [介绍 && Introduce](https://wscats.github.io/omi-docs/public/home)
* [安装 && Install](https://wscats.github.io/omi-docs/public/install/)
* [配合Omi Snippets插件 && Cooperative plugin with Omi Snippets](https://wscats.github.io/omi-docs/public/plugin)
* [配合React开发 && Cooperative with React](https://wscats.github.io/omi-docs/public/react)
* [语言块规范 && Language Block Specification](https://wscats.github.io/omi-docs/public/spec)
* [JSX](https://wscats.github.io/omi-docs/public/jsx)
* [Props](https://wscats.github.io/omi-docs/public/props)
* [事件处理 && Event](https://wscats.github.io/omi-docs/public/event)
* [生命周期 && Lifecycle](https://wscats.github.io/omi-docs/public/lifecycle)
* [更新方法 && Update](https://wscats.github.io/omi-docs/public/update)
* [Ref](https://wscats.github.io/omi-docs/public/ref)
* [Store](https://wscats.github.io/omi-docs/public/store)
* [CSS](https://wscats.github.io/omi-docs/public/css)
* [高阶组件 && HOC](https://wscats.github.io/omi-docs/public/hoc)
# Contributors
| [
Eno Yao](https://github.com/Wscats)| [
Aaron Xie](https://github.com/aaron-xie)| [
DK Lan](https://github.com/dk-lan)| [
Yong](https://github.com/flowerField)| [
Li Ting](https://github.com/Liting1)| 
Xin| [
Lemon](https://github.com/lemonyyye) | [
Jing](https://github.com/vickySC) | [
Lin](https://github.com/shirley3790) | [
Tian Fly](https://github.com/tiantengfly)|
| - | - | - | - | - | - | - | - | - | - |
# Quick Start
- Install [Omi Snippets](https://marketplace.visualstudio.com/items?itemName=Wscats.omi-snippets).
- Try it with [omil](https://github.com/Wscats/omil), a Omi.js components loader based on webpack.
- Via Marketplace Control: search for `Omi Snippets` and click install.
- Manual: clone this repo and install `omi-snippets.vsix` into your Visual Studio Code.
> In addition, if you want to build and install the extension from source, you need to install [vsce](https://code.visualstudio.com/api/working-with-extensions/publishing-extension), like this.
```bash
# Then, clone the repository and compile it.
git clone https://github.com/Wscats/omi-snippets
cd omi-snippets
yarn
vsce package
```

This will setup a basic `webpack` + [omil](https://github.com/Wscats/omil) project for you, with `*.omi` or `*.eno` files and hot-reloading working out of the box!
For example, you can create `test.omi` in Visual Studio Code before install [Omi Snippets](https://marketplace.visualstudio.com/items?itemName=Wscats.omi-snippets)
```html
{this.data.name}
```
After you save the code in editor`(Ctrl+S)`, it will be converted into `test.js`
```jsx
// test.js
import { WeElement, define, h } from "omi";
import style from "./style.css";
const componentName = class extends WeElement {
render() { return h("div", null, this.data.name); }
static css =
`div{color:red;}` + style;
install() {
this.data = { name: "Eno Yao" };
}
};
define("component-name", componentName);
```
## Usage In Omi
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: `,
```
> [Single-File Components Demo](https://github.com/Wscats/omil/blob/master/src/components/oHeader.omi)
It also supports [JSX](https://github.com/facebook/jsx), if you want to do that, you only write `` without `lang="html"` attribute in your component like this:
```html
```
> [JSX Demo](https://github.com/Wscats/omil/blob/master/src/components/oPanel.omi)
`omil` 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](https://www.npmjs.com/package/node-sass) after you can use [Sass](https://sass-lang.com/) for the style of your component like this:
```html
```
> [Sass Demo](https://github.com/Wscats/omil/blob/master/src/components/oGallery.omi)
## Support React
```bash
npm install styled-components --save
```
You can also use an ES6 class to define a class component by omil.
```html
{this.state.title}
```
> [React Demo](https://github.com/Wscats/omil/blob/master/src/components/React/Eno.eno)
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API. Here's a concrete example.
```html
```
# Cooperate With TypeScript
A static type system can help prevent many potential runtime errors, especially as applications grow. You can use `Single File Components(SFC)` cooperate with `Higher Order Components(HOC)` to get support with `TypeScript`
```html
```
Now, you can create `EnoType.tsx` in editor which provides TypeScript inference inside SFCs and many other great features.
```ts
// EnoType.ts
import React from 'react';
interface EnoTypeProps { }
interface EnoTypeState { name: string }
export default (Component: React.ComponentType) => {
return class EnoType extends React.Component {
constructor(props: EnoTypeProps) {
super(props)
this.state = { name: 'Eno Yao' }
}
render() { return }
}
}
```
> [React Demo](https://github.com/Wscats/omil/blob/master/src/components/React/Eno.eno)
> [Typescript Demo](https://github.com/Wscats/omil/blob/master/src/components/React/EnoType.tsx)
There are many cool features provided by `omil`:
- Allows using other webpack loaders for each part of a Omi component, for example Sass for ``|
|styleLang|``|
|scaffold/t|`