babel-plugin-schema-util

1.0.7 • Public • Published

Babel Schema Util Build Status Codecov npm package

forked by babel-plugin-inline-import, you can apply different handler functions into the different files.

Babel plugin to add the opportunity to use import with raw/literal content
It is good e.g. for importing *.schema files into your code.

Examples

schema transform demo

Now (with Babel Schema Util):

// /some/demo.schema
Array(foo) {
  href(href),
  title(title),
  img(image url): Image,
  amount(money amout)
}
 
// /some/a.js
import demo from './demo';
// /build/a.js
var demo = {
  "type": "array",
  "description": "foo",
  "properties": {
    "href": {
      "type": "string",
      "description": "href"
    },
    "title": {
      "type": "string",
      "description": "title"
    },
    "img": {
      "type": "image",
      "description": "image url"
    },
    "amount": {
      "type": "string",
      "description": "money amout"
    }
  }
};
 

Note: both cases are equivalent and will result in similar code after Babel transpile them. Check How it works section for details.

Install

npm install babel-plugin-schema-util --save-dev

Use

Add a .babelrc file and write:

{
  "plugins": [
    "babel-plugin-schema-util"
  ]
}

or pass the plugin with the plugins-flag on CLI

babel-node myfile.js --plugins babel-plugin-schema-utilt

By default, Babel-Schema-Util is compatible with the following file extensions:

  • .raw
  • .text
  • .graphql
  • .schema

Customize

If you want to enable different file extensions, you can define them in your .babelrc file

{
  "plugins": [
    ["babel-plugin-schema-util", {
      "extensions": [
        ".json",
        ".sql",
        {
          name: ".schema2",
          loader: (content, filepath) => `~${content}~`,
        }
      ]
    }]
  ]
}

Motivate

If you like this project just give it a star :) I like stars.

Package Sidebar

Install

npm i babel-plugin-schema-util

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

22.5 kB

Total Files

12

Last publish

Collaborators

  • ycjcl868