babel-plugin-inline-app-json
v0.0.4
Published
transver the app.json in miniapp to js module
Downloads
9
Maintainers
Readme
babel-plugin-inline-app-json
Only used in miniapp
Transform your app.json module to js value.
For example:
Input:
{
"tabBar": {
"backgroundColor": "red",
"borderStyle": "white",
"color": "blue",
"selectedColor": "green",
"list": [
{
"pagePath": "pathToA",
"iconPath": "imgs/a.png",
"selectedIconPath": "imgs/a-selected.png",
"text": "a"
},
{
"pagePath": "pathToB",
"iconPath": "imgs/b.png",
"selectedIconPath": "imgs/b-selected.png",
"text": "b"
/* annotation */
},
{
"pagePath": "pathToC",
"iconPath": "imgs/c.png",
"selectedIconPath": "imgs/c-selected.png",
"text": "c"
},
{
"pagePath": "pathToD",
"iconPath": "imgs/d.png",
"selectedIconPath": "imgs/d-selected.png",
"text": "d"
}
]
}
}
var tabBar = require('./app.json').tabBar;
Output:
const tabBar = {
backgroundColor: 'red',
borderStyle: 'white',
color: 'blue',
selectedColor: 'green',
list: [{
pagePath: 'pathToA',
iconPath: 'imgs/a.png',
selectedIconPath: 'imgs/a-selected.png',
text: 'a'
}, {
pagePath: 'pathToB',
iconPath: 'imgs/b.png',
selectedIconPath: 'imgs/b-selected.png',
text: 'b'
}, {
pagePath: 'pathToC',
iconPath: 'imgs/c.png',
selectedIconPath: 'imgs/c-selected.png',
text: 'c'
}, {
pagePath: 'pathToD',
iconPath: 'imgs/d.png',
selectedIconPath: 'imgs/d-selected.png',
text: 'd'
}]
};
Installation
$ npm install babel-plugin-inline-app-json
Usage
const plugin = require('babel-plugin-inline-app-json').default
// import plugin from 'babel-plugin-inline-app-json'
const res = babel.transform(code, {
plugins: [plugin]
})
console.log(res.code)
Via .babelrc
{
"plugins": ["inline-app-json"]
}
Via CLI
$ babel --plugins inline-app-json script.js
Via Node API
require('babel-core').transform('code', {
plugins: ['inline-app-json']
});
Thanks for this plugin: babel-plugin-inline-package-json