-
Notifications
You must be signed in to change notification settings - Fork 10
JSX in Node
wvbe edited this page Jan 22, 2023
·
2 revisions
Run the following commands:
npm install docxml
npm install -D @babel/cli @babel/core @babel/plugin-syntax-jsx @babel/plugin-transform-react-jsxCreate file .babelrc:
{
"plugins": [
"@babel/plugin-syntax-jsx",
["@babel/plugin-transform-react-jsx", { "pragma": "jsx" }]
]
}Create a JavaScript file using docxml, call it index.js or whatever:
const { default: Docx, jsx, Paragraph } = require('docxml');
Docx.fromJsx(
<Paragraph>Hello world!</Paragraph>,
)
.toFile('out.docx')
.then(() => console.log('Done'));And then either build (and run):
npx babel index.js --out-dir lib
node lib/index.jsOr run directly:
npx @babel/node index.jsYou will now have a file out.docx with the content per your index.js.