Coder Social home page Coder Social logo

jsx-render-to-html's Introduction

jsx-render-to-html

转换 jsx 文件成 html 文件。

安装依赖

npm install jsx-render-to-html --save-dev

代码示例

var jsxRenderToHtml = require('jsx-render-to-html');
var renderToHtmlString = require('jsx-render-to-html/render-to-html-string');
var sourceJsxPath = ... // 要转换的 JSX 文件路径
var destHtmlPath = ... // 转换后的 HTML 文件路径

// 转换 jsx 文件成 html 文件
jsxRenderToHtml(sourceJsxPath, destHtmlPath);

// 转换时指定字符编码和是否美化格式处理
jsxRenderToHtml(sourceJsxPath, destHtmlPath, {
  encoding: 'utf8', // 默认 utf8 编码
  prettyFormat: true, // 默认不对生成的内容做美化格式处理
  deleteTempFile: true, // 默认删除临时生成的 JS 文件
  afterRender: null // 在保存到 html 文件前修改要保存的内容,比如 (html) => html.replaceAll(''', '\'')
});

// 转换 jsx 字符串成 html 字符串,在转换过程中会生成临时的 JS 文件做编译处理
var htmlString = renderToHtmlString('JSX字符串', {
  tempFilePath: 'temp.js', // 默认临时生成的 JS 文件路径是 ~jsx-render-to-html-temp-file.js
  prettyFormat: true, // 默认不对生成的内容做美化格式处理
  deleteTempFile: true, // 默认删除临时生成的 JS 文件
});

jsx-render-to-html's People

Contributors

magicodex avatar

Watchers

 avatar

jsx-render-to-html's Issues

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.