zoukankan      html  css  js  c++  java
  • [TypeStyle] Generate static css + html files using TypeStyle

    You can easily use TypeStyle to build static html files with encapsulated CSS. You can use this pattern to generate email and pdf template files. Since TypeStyle supports cssRaw all your css can be easily inlined into a single file making it easy to work with template rendering engines.

    import {style, getStyles} from "typestyle";
    import * as React from "react";
    
    const className = style({
      color: 'red',
      fontSize: '30px'
    });
    
    const App = () =>
        <div className={className}>
          Hello World!
        </div>;
    
    import * as ReactDOMServer from 'react-dom/server';
    const html = ReactDOMServer.renderToStaticMarkup(<App />);
    const css = getStyles();
    
    const renderPage = ({html, css}) => `
      <html>
        <header>
            <style>${css}</style>
        </header>
        <body>
            <div>${html}</div>
        </body>
      </html>
    `;
    const renderedPage = renderPage({html, css});
    import * as fs from 'fs';
    fs.writeFileSync(__dirname + '/index.html', renderedPage);
  • 相关阅读:
    js以字符串方式创建DOM(原生js,jquery,extjs)
    gallery3
    检测标准类型和内置对象类型
    js数据类型和类型检测
    gallery2
    gallery
    如何使用Git上传项目代码到github
    sublime EMMET
    模糊搜索
    导出表格
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6972206.html
Copyright © 2011-2022 走看看