npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

element-loader

v0.6.5

Published

web component loader.

Downloads

161

Readme

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.exports = {
  // Webpack 3+
  module: {
    rules: [
      {
        test: /\.html/,
        use: 'element-loader',
        options: {
          // React & Component is required
          banner: `import React, { Component } from 'react';`
        }
      }
    ]
  },
  // Webpack 2
  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.exports = {
  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

  • [x] compile script
  • [] support else、elif directive