Categorygithub.com/typomedia/lessgo
modulepackage
0.1.1
Repository: https://github.com/typomedia/lessgo.git
Documentation: pkg.go.dev

# README

lessgo

Less compiler for Golang

Builds CSS using original Less compiler and goja for a true cross-platform Less solution.

The original project less-go used Duktape instead of goja.

This is a fork of the https://github.com/tystuyfzand/less-go to be used as go install package.

Status

This project is "stable" but also very much a work in progress. Expect changes as required, and feel free to submit pull requests to improve it.

Installation

go install github.com/typomedia/lessgo@latest

Command Line usage

cd $GOPATH/src/github.com/typomedia/lessgo/lessc
go get
go build
./lessc --input="inputFile" --output="outputFile"
./lessc -i inputFile -o outputFile

Examples:

./lessc --input="./styles.less" --output="./styles.css"
./lessc -i styles.less -o styles.css

More about usage you can see in cli help:

./lessc -h

Programmatic usage

import "github.com/typomedia/lessgo"

func main() {
	output, err := less.RenderFile("./styles.less", map[string]interface{}{"compress": true})
}

Function reference

Render(input string, mods ...map[string]interface{}) (string, error)

Renders Less as raw input and generates output CSS.

RenderFile(input string, mods ...map[string]interface{}) (string, error)

Renders Less files and generates output CSS.

SetReader(customReader Reader)

type Reader interface {
    ReadFile(string) ([]byte, error)
}

Sets a custom reader for .less files. You can use it to replace standard input from file system to another. Example:

type LessReader struct{}

var lessFiles = map[string][]byte{"styles": []byte{".class { width: (1 + 1) }"}}

func (LessReader) ReadFile(path string) ([]byte, error) {
    lessFile, ok := lessFiles[path]
    if !ok {
    	return "", errors.New("path not found")
    }
    return lessFile, nil
}

func main() {
    less.SetReader(LessReader)
    ...
}

Updating Less

Get the latest version of less.js, navigate to packages/less/src.

With npm installed, run:

npm install @babel/core @babel/cli @babel/preset-env

Then, run babel to get a copy that goja can run:

npx babel less/ --out-dir /path/to/less-go/assets/less/ --presets=@babel/preset-env

And finally, re-build the packr files:

packr2

Current limitations

Unlike the original version, this doesn't use any C Javascript engine. It will run on any platform, and cross compile just fine.

CLI interface doesn't support options

# Packages

No description provided by the author