Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard lessc and minify CSS using Node.js #2337

Merged
merged 5 commits into from Sep 21, 2017

Conversation

silverwind
Copy link
Member

This changes the previous nonstandard lessc to the official one and
enables CSS minification via the clean-css module.

To build CSS, Node.js is required along with a npm install to get the
tools installed locally in node_modules so there is no dependency on
binaries in PATH. Benefits include:

  • Allows one to have a standard lessc in PATH.
  • Can now use command line switches on lessc.
  • Minified CSS brings faster page load times and also has the benefit
    of discouraging contributors from editing CSS directly.

To build CSS, Node.js is required along with a npm install to get the
tools installed locally based on the information in package.json.

@lafriks lafriks added topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile type/enhancement An improvement of existing functionality labels Aug 19, 2017
@lafriks lafriks added this to the 1.x.x milestone Aug 19, 2017
@lafriks
Copy link
Member

lafriks commented Aug 19, 2017

nodejs will be needed anyway to use webpack later so LGTM

@tboerger tboerger added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Aug 19, 2017
@sapk
Copy link
Member

sapk commented Aug 20, 2017

Why not use https://github.com/tdewolff/minify ? I prefer to limit node package for space and dev env.

Advantage of https://github.com/tdewolff/minify : we could use it for other format also.

Makefile Outdated
lessc -i $< -o $@
stylesheets:
node_modules/.bin/lessc --no-ie-compat public/less/index.less public/css/index.css
node_modules/.bin/cleancss -o public/css/index.css public/css/index.css
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should output to public/css/index.min.css (need change also in template for using it) and keep public/css/index.css for readability.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the Less source is meant for reading/editing, wouldn't you agree?

(I'm actually not a fan of Less, would rather use SCSS or plain CSS).

@silverwind
Copy link
Member Author

silverwind commented Aug 20, 2017

minifyseems good for CSS, thought I'm sure cleancss ought to beat it once advanced options are turned on:

$ node_modules/.bin/cleancss public/css/index.css | wc -c
   61084
$ minify public/css/index.css | wc -c
   60996

For JS, it's slightly worse than uglifyjs with default options, but I assume with advanced options, that size can be reduced quite a bit too:

$ uglifyjs public/js/**/*.js | wc -c
   516451
$ minify public/js/**/*.js | wc -c
   517952

I think I'll go with minify.

@sapk
Copy link
Member

sapk commented Aug 21, 2017

Just to find why you want to use lessc version of node.
Is it because it failed to run the makefile if you have lessc (node version) on your host allready installed ? (because the flag between golang version and node version are different)

In this case we could do the same trick and use $(GOPATH)/bin/lessc to select the golang version.

@silverwind
Copy link
Member Author

silverwind commented Aug 21, 2017

Is it because it failed to run the makefile if you have lessc (node version) on your host allready installed

Yes, exactly. With the node version first in PATH, it was failing to build because that one takes different arguments. I guess I could apply your workaround and keep the dependencies go-only for now. There's no real benefit if using the official lessc as far as I can tell. The output files were the same.

But there's still the issue that the go version can break other projects that rely on the standard lessc if the go version comes first in PATH. Is it possible to install a go binary under a different name, or maybe is there a version that uses a different binary name?

@silverwind
Copy link
Member Author

Seems the author of less-go added this to their README:

THIS PROJECT IS NO LONGER MAINTAINED, feel free to fork and use as boilerplate for further usages

So I think I'd rather keep lessc on the Node.js version.

@sapk
Copy link
Member

sapk commented Aug 21, 2017

README.md updated 3 hours ago 😭

My principal point of keeping go version is: we don't have "extra" deps.
But I totally understand that in some time we need to pass to node deps for a lot more of reason.
Maybe at this point, we could split ui in a separate repo (submodule) that we update like sdk or git and that the ui is more relying on the API.

For this PR, if you find enough L-GTM from maintainers it is good for me. I'm not against node deps but rather more prefering go version. 😄

For the PR content itself, it looks good with updated documentation and all. It will just need a new sign for the drone file.

Edit: for keeping a go bin out of PATH : go build -o local-lessc github.com/kib357/less-go/lessc and use ./local-lessc locally.

@bkcsoft
Copy link
Member

bkcsoft commented Aug 24, 2017

Urgh, not more javascript :pukes: Add a check that $GOPATH/bin/lessc exists instead of the current (invalid IMO) check

@lafriks
Copy link
Member

lafriks commented Aug 24, 2017

@bkcsoft we will need nodejs for compiling js anyway so not much point on keeping around unmaintained golang binary

This changes the previous nonstandard `lessc` to the official one and
enables CSS minification via the clean-css module.

To build CSS, Node.js is required along with a `npm install` to get the
tools installed locally in node_modules so there is no dependency on
binaries in PATH. Benefits include:

- Allows one to have a standard lessc in PATH.
- Can now use command line switches on lessc.
- Minified CSS brings faster page load times and also has the benefit
  of discouraging contributors from editing CSS directly.

To build CSS, Node.js is required along with a `npm install` to get the
tools installed locally based on the information in `package.json`.

The 'make stylesheet' task was modified to run without condition. This
makes it easier to work on the make task itself without having to delete
files.

Also fixes: go-gitea#2198
@codecov-io
Copy link

codecov-io commented Sep 20, 2017

Codecov Report

Merging #2337 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2337   +/-   ##
=======================================
  Coverage   26.99%   26.99%           
=======================================
  Files          85       85           
  Lines       17097    17097           
=======================================
  Hits         4615     4615           
  Misses      11807    11807           
  Partials      675      675

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa1cbc2...c00f746. Read the comment docs.

@lafriks
Copy link
Member

lafriks commented Sep 20, 2017

Rebased and resolved conflicts

We need this as our used less-go does not compile anymore on golang 1.9 and there is error:

# gopkg.in/olebedev/go-duktape.v2
../../gopkg.in/olebedev/go-duktape.v2/duktape.go:83: constant 18446744073709551615 overflows int
make: [Makefile:278: public/css/index.css] Error 2 (ignored)
make: lessc: Command not found
make: [Makefile:279: public/css/index.css] Error 127 (ignored)
lessc -i public/less/index.less -o public/css/index.css

To fix its compilation on golang 1.9 go-less needs to be ported to go-duktape.v3 so as go-less is not maintained anymore we should drop it

@sapk
Copy link
Member

sapk commented Sep 20, 2017

LGTM (since less-go is not maintained anymore and fail to build)

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Sep 20, 2017
@lunny lunny modified the milestones: 1.x.x, 1.3.0 Sep 21, 2017
@@ -1,3131 +1 @@
.emoji {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why deleted public/css/index.css ? I don't think is a good idea to delete this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not deleted it is minimized

@lunny lunny merged commit 1fbfccb into go-gitea:master Sep 21, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants