简体   繁体   English

在Node.js和React.js中编译LESS

[英]Compile LESS in Node.js & React.js

Is there a way to automatically compile LESS in React.js? 有没有办法在React.js中自动编译LESS?

I've installed it according to the docs 我已经根据文档安装了它

I know it's possible to use the lessc command, but it seems tedious to run that command manually everytime the less is updated. 我知道可以使用lessc命令,但是每次更新较少的命令时手动运行该命令似乎很lessc

I've tried this one too, but it doesn't work: 我也尝试过这种方法,但是不起作用:

import React, {Component}  from 'react';
import ReactDOM from "react-dom";

var less = require('less');
var lessCss = require('./app.less');

console.log(lessCss); //output: /static/media/app.725ced4d.less

less.render(lessCss, function (e, output) {
    console.log(e); //output: Unrecognized Input
    console.log(output); //output: undefined
});

class Main extends Component {
    /* render functions */

React Native comes with everything you need already, i would suggest not using LESS but the preferred way from the official docs: React Native附带了您已经需要的一切,我建议您不要使用LESS,而应使用官方文档中的首选方法:

const styles = StyleSheet.create({
    mainView: {
        flex: 1,
        flexDirection: 'column',
        justifyContent: 'center',
        alignItems: 'center'
    },
    ...
});

Source: https://facebook.github.io/react-native/docs/style.html 资料来源: https : //facebook.github.io/react-native/docs/style.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM