Coder Social home page Coder Social logo

reactml / loader Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 95 KB

The webpack loader for Reactive Markup Language(RML).

Home Page: https://github.com/ReactML/ReactML

JavaScript 97.22% HTML 2.54% CSS 0.13% SCSS 0.11%
react dsl markup-language loader webpack-loader css-modules rml react-markup-language

loader's Introduction

@reactml/loader

The @reactml/loader impl the webpack loader for React Markup Language(RML).

Usage

To begin, you'll need to install @reactml/loader:

npm install --save-dev @reactml/loader

Then add the plugin to your webpack config.

For example:

file.js

import Module from './module.rml';

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.rml$/i,
        loader: '@reactml/loader',
        options: {
          renderer: 'react',
        },
      },
    ],
  },
};

Options

  • renderer {String} Determin react replacement renderer. (default to 'react')

And run webpack via your preferred method.

CSS PreProcessor Support

For example, to compile our <style> tag with Scss:

Tips: Default lang iscss.

In your webpack config:

module.exports = {
  module: {
    rules: [
      // this will apply to both plain `.scss` files
      // AND `<style lang="scss">` blocks in `.rml` files
      {
        test: /\.scss$/,
        use: [
          'style-loader',
          'css-loader',
          'sass-loader'
        ]
      }
    ]
  },
}

Any content inside the style block with lang="scss" will be processed by webpack as if it's inside a *.scss file.

<style lang="scss">
/* Write SCSS here */
</style>

CSS Modules

First, CSS Modules must be enabled by passing modules: true to css-loader:

// webpack.config.js
{
  module: {
    rules: [
      // ... other rules omitted
      {
        test: /\.css$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              // enable CSS Modules
              modules: true,
            }
          }
        ]
      }
    ]
  }
}

Then, add the module attribute to your <style>,and use className as is:

<style module>
.red {
  color: red;
}
.bold {
  font-weight: bold;
}
</style>

<div className="red bold">Hello RML</div>

Use global scope in CSS Modules:

Only works when CSS Moudles is enabled.

You can add suffix : to your class declaration to tag which to be gloabl,

For example:

<style lang="scss" module>
  .container {
    color: green;
  }

  :global {
    .global-container {
      background: grey;
    }
  }
</style>
<div className="container :global-container" />

After compiled, global scope className will not be invoved:

<style>
  ._2zQP9LGGLck7rMhc9zNHw_ {
    color: green;
  }

  .global-container {
     background: grey;
   }
</style>
<div class="_2zQP9LGGLck7rMhc9zNHw_ global-container" />

loader's People

Contributors

alvinhui avatar wssgcg1213 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

danielxuuuuu

loader's Issues

Variable scope of template

By design, the variable scope of the template should come from the return value of the function:

<script>
export default function(props) {
  return {
    value: '123'
  };
}
</script>

<div>
  {value}
</div>

The actual implementation is:

<script>
export default function() {
  return {
    text: 123
  };
}
</script>

<div>
  <span>变量:</span>
  <span>{text}</span> {/* 123 */}
  <span>{props.text}</span> {/* 123 */}
</div>

I never defined props and props is not returned in return value.

If I use props as the return value:

<script>
export default function(props) {
  return {
    props
  };
}
</script>

 <div>
  <span>变量:</span>
  <span>{props.text}</span> {/* undefined */}
  <span>{props.props.text}</span> {/* text value */}
</div>

This implementation is inconsistent with the design.

Template Syntax for annotations

By design RML Template Syntax is follow XML Template Syntax, Annotations in XML should be:

<div>Hi</div>
<!-- <span>Alvin</span> -->

But now the syntax of the Loader implementation is JSX:

<div>Hi</div>
{/* <span>Alvin</span> */}

Support inline expression

Object:

<script>
  export default function () {
   return {
     color: 'yellow',
   };
 }
 </script>
<span style={{color: color}}>
  object
</span>

Function:

<Button type="primary" onClick={function() {
  alert(1);
}}>
  click
</Button>

CSS Modules Problem

Code:

<style lang="scss" module>
  .container {
    .strong {
      font-weight: bold;
    }
  }
</style>
<div className="container">
  <span className="strong">Class 样式</span>
</div>

Render result:

image

No strong style appears to be generated.

Support import RML file without suffix

Now I have to add the suffix manually when import the RML file:

  1. In generic files: import Home from '@/pages/Home/index.rml';
  2. In RML files: <import default="Guide" from="@/components/Guide.rml" />

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.