Coder Social home page Coder Social logo

lesx-example's Introduction

lesx-example

lesx dsl webpack loader example.

What

The loader can transform the following DSL:

<style>
    a {
        color: red;
    }
</style>

<template>
    <div>
        <a onClick={() => {
            alert(1);
        }}>点我</a>

        {console.log(this.props)}

        <If condition={ this.props.valid }>
            <div>{this.state.name}</div>
        </If>

        <Button type="primary" onClick={() => {
            alert('I am a button!');
        }}>antd button</Button>
    </div>
</template>

<script>
    module.exports = {
        props: {
            valid: true
        },

        state: {
            name: 'xiangzhong.wxz'
        },
    };
</script>

into a React Component!

特性

  • 0、没有任何新语法,全部是JSX基础语法;
  • 1、style/template/script三元素分离,方便代码维护;
  • 2、script中注入的方法及变量在DSL中可以通过this.xxx的方式使用;
  • 3、script中注入的方法会被自动绑定到this作用域;
  • 4、DSL中自动支持jsx-control-statements控制流标签(If/Choose/When/Otherwise/For/With);
  • 5、DSL默认自带antd组件(可以配置为其他UI组件库),无需引入,可以直接在DSL中使用antd所有的组件;
  • 6、智能解析DSL所使用到的UI library组件,并按需打包,而不会把整个组件库全部打包进去,最小化打包后的代码体积;
  • 7、DSL transform后的组件支持components属性,可以引入组件库没有的其他组件(自定义或者第三方的);
  • 8、style支持自定义语言(css/sass/less),默认sass

loader setting

{
    test: /\.lesx$/,
    loader: 'lesx-loader',
    query: {
        loaders: {
            js: 'babel',
            css: 'style!css',
            sass: 'style!css!sass'
        },
        uiLib: {
            libName: 'antd',
            libDirectory: 'lib'
        }
    }
}

lesx-example's People

Watchers

 avatar

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.