Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

element-loader

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

element-loader

web component loader.

  • 0.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by16.67%
Maintainers
1
Weekly downloads
 
Created
Source

element-loader

A webpack loader converts markup to react component(compatible with all react systems. eg. rax、react、react-native、preact)

Install

npm install --save-dev element-loader

Usage

Config loader in webpack.config.js:

// webpack.config.js

module.export = {
  module: {
    loaders: [
      {
        test: /\.html/,
        loader: 'element-loader',
        query: {
          // React & Component is required
          banner: `import React, { Component } from 'react';`
        }
      }
    ]
  }
};

Write in .babelrc:

{
  "presets": ["es2015", "react"]
}

Input Container.html:

<link rel="import" href="./Hello.html" />

<template>
  <div>
    <span class="text" :if="{{show}}">{{text}}</span>
    <div class="item" :for="{{item in items}}">
      <span class="name">{{item}}</span>
    </div>
    <Hello message="world"></Hello>
  </div>
</template>

<script>
  export default class extends Component {
    constructor(props) {
      super(props);
      console.log(props);
    }
    componentWillMount() {
      this.customMethod();
      console.log('will mount', this);
    }
    componentDidMount() {
      console.log('did mount', this);
    }
    customMethod() {
      console.log('custom');
    }
  }
</script>

<style>
  .text {
    font-size: 25rem;
    color: gray;
  }
  .name {
    color: red;
    font-size: 40rem;
  }
  .item {
    width: 200rem;
    height: 60rem;
    background-color: blue;
  }
</style>

Input Hello.html:

<link rel="stylesheet" href="./hello.css" />

<template>
 <span class="textMessage">{{message}}</span>
</template>

Input hello.css:

.textMessage {
 color: red;
}

Use react in index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import Container from './Container.html';

ReactDOM.render(
  <Container text="hello world" show={true} items={[1, 2, 3]}/>,
  document.getElementById('body')
);

Rax

Of cource, You also can use rax with es6.

Use rax in index.js:

import { createElement, Component, render } from 'rax';
import Container from './Container.html';

class App extends Component {
  render() {
    return <Container text="hello world" show={true} items={[1, 2, 3]}/>;
  }
}

render(<App />);

Config webpack.config.js:

module.export = {
  module: {
    loaders: [
      {
        test: /\.html/,
        loader: 'element-loader',
        query: {
          banner: `import { createElement, Component } from 'rax';`
        }
      }
    ]
  }
};

In .babelrc:

{ 
  "presets": ["es2015", "rax"]
}

Options

banner

Code inserted into each element. You can use it in any framework(eg. rax、react、react-native...) by configuring this option.

For example:

// webpack.config.js
banner: `
  import { createElement, Component } from 'rax';
  import { View, Text, Link } from 'rax-components';
`
babel

option babel readed by default, If there is no written in query, We'll get data from the .babelrc file.

query: {
  babel: {
    presets: ['es2015', 'rax']
  }
}
engine

template engine option you can see list.

Config in webpack.config.js:

query: {
  engine: 'jade'
}

Write in html:

<template>
div.header
  span hello world
</template>

Directives

  • :for: repeat a array eg. "{{item in items}}"
  • :if: show or hide eg. "{{x < 5}}"

TODO

  • compile script
  • [] support else、elif directive

FAQs

Package last updated on 12 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc