
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Using Babel Macro Extract Metadatas from Codes
Example: https://github.com/fe-since2019/meta.macro/tree/master/example/router-usage
npm install --save-dev meta.macro
// File: /Users/me/workspaces/my-app/src/App.js
import Controller from 'meta.macro';
@Controller('/home', {async: true, chunk: 'main'})
class App extends React.Component {
render() {
return (
<div>Hello World</div>
);
}
}
Data Extract from Code
{
"/Users/me/workspaces/my-app/src/App.js": {
"callee": "Controller",
"params": [
"/home",
{
"async": true,
"chunk": "main"
}
]
}
}
Supportted Config Files: https://github.com/kentcdodds/babel-plugin-macros/blob/HEAD/other/docs/author.md#config-experimental
// babel-plugin-macros.config.js
module.exports = {
'meta.macro': function(metadata){
// TODO
// do something...
},
}
Before
my-app
āāā package.json
āāā babel-plugin-macros.config.js
āāā .gitignore
āāā src
āāā App.js
āāā Loading.js
āāā pages
āāā HomePage.js
āāā LoginPage.js
// src/App.js
import './pages/HomePage.js'
import './pages/LoginPage.js'
ReactDOM.render(
<App />,
document.getElementById('root')
);
// babel-plugin-macros.config.js
const routerCodeGenerator = require('meta.macro/lib/router.code.js');
module.exports = {
'meta.macro': routerCodeGenerator
}
// src/pages/LoginPage.js
import React from 'react';
import Controller from 'meta.macro';
@Controller('/login')
class LoginPage extends React.Component {
render() {
return (
<div>Login</div>
);
}
}
// src/pages/HomePage
import React from 'react';
import Page from 'meta.macro';
@Page('/home', { async: true, chunk: 'main' })
class HomePage extends React.Component {
render() {
return (
<div>Home Page</div>
);
}
}
After
my-app
āāā package.json
āāā babel-plugin-macros.config.js
āāā .gitignore
āāā src
āāā router.js
āāā router-config.json
āāā Loading.js
āāā pages
āāā HomePage.js
āāā LoginPage.js
Generate File src/router.js
// ~ is Webpack Alias for <project>/src folder
import React from 'react';
import Loadable from 'react-loadable';
import Loading from './Loading';
import LoginPage from '~/pages/LoginPage';
const lazy = loader => Loadable({
delay: 400,
loading: Loading,
loader,
});
const rootConfig = [
{
path: "/home",
component: lazy(() => import(/* webpackChunkName: "main" */ '~/react/pages/HomePage.js')),
}, {
path: "/login",
component: LoginPage
}
];
export default rootConfig;
Generate File src/router-config.json
{
"/Users/me/workspaces/my-app/src/pages/LoginPage.js": {
"callee": "Controller",
"params": []
},
"/Users/me/workspaces/my-app/src/pages/HomePage.js": {
"callee": "Page",
"params": [
"/home",
{
"async": true,
"chunk": "main"
}
]
}
}
FAQs
Using Babel Macro Extract Metadatas from Codes
The npm package meta.macro receives a total of 0 weekly downloads. As such, meta.macro popularity was classified as not popular.
We found that meta.macro demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Ć faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.