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 npm to manage fomantic and only build needed components #9561

Merged
merged 14 commits into from
Jan 21, 2020

Conversation

lunny
Copy link
Member

@lunny lunny commented Dec 31, 2019

Fix #9562, #9415

  • Removed semantic.min.css from git and use npm to build fomantic.
  • Only load needed semantic components. Before this PR, semantic.min.css is 1.29MB, after ~650KB.
  • Don't load fonts from google sites since it's slow from some location visit. And the lato fonts has been loaded by gitea itself.

@lunny lunny added the topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile label Dec 31, 2019
@lunny lunny changed the title Use npm to manage fomantic Use npm to manage fomantic and only build needed components Jan 1, 2020
@codecov-io
Copy link

codecov-io commented Jan 1, 2020

Codecov Report

Merging #9561 into master will decrease coverage by 0.03%.
The diff coverage is 11.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9561      +/-   ##
==========================================
- Coverage   42.33%   42.29%   -0.04%     
==========================================
  Files         605      607       +2     
  Lines       79313    79353      +40     
==========================================
- Hits        33577    33565      -12     
- Misses      41597    41645      +48     
- Partials     4139     4143       +4
Impacted Files Coverage Δ
models/repo.go 49.76% <ø> (+2.73%) ⬆️
modules/repository/repo.go 26.28% <0%> (ø) ⬆️
models/context.go 39.28% <0%> (-6.55%) ⬇️
services/wiki/wiki.go 57.08% <0%> (ø) ⬆️
cmd/admin.go 0% <0%> (ø) ⬆️
routers/admin/admin.go 11.2% <0%> (-0.04%) ⬇️
models/migrations/v36.go 0% <0%> (ø) ⬆️
modules/repository/init.go 57.43% <0%> (ø) ⬆️
modules/cron/cron.go 47.19% <0%> (-4%) ⬇️
modules/repository/check.go 0% <0%> (ø)
... and 10 more

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 7818e13...b11bdba. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 1, 2020
Copy link
Contributor

@bagasme bagasme left a comment

Choose a reason for hiding this comment

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

Huge PR, right?

@lunny
Copy link
Member Author

lunny commented Jan 1, 2020

@bagasme I don't think so. Most changes are to delete semantic-ui vendor files and add semantic-ui sources.

package.json Outdated
],
"dependencies": {
"fomantic-ui": "2.8.3",
"gulp": "4.0.2"
Copy link
Member

Choose a reason for hiding this comment

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

Gulp must be devDependency

Copy link
Member

Choose a reason for hiding this comment

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

Can't we just use webpack without gulp?

Copy link
Member Author

Choose a reason for hiding this comment

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

@lafriks I just follow https://fomantic-ui.com/introduction/build-tools.html to use gulp. If we want to use webpack, I think we should do that another PRs.

Copy link
Member

@silverwind silverwind Jan 4, 2020

Choose a reason for hiding this comment

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

Gulp build is necessary to build the fomantic bundle I'm afraid, but we can tweak the Makefile so it only runs when necessary. Optionally, the resulting files could then be integrated in the webpack bundle as most pages do need it (thought, not all).

@lunny
Copy link
Member Author

lunny commented Jan 2, 2020

@lafriks Done. I also moved fomantic-ui to devDependencies.

@sapk sapk added this to the 1.12.0 milestone Jan 2, 2020
@6543
Copy link
Member

6543 commented Jan 2, 2020

@lunny is there a optio to only build fomatic if something has changed?
-> as we do with webpack
it is build every time you build gitea witch is anoing

@lafriks
Copy link
Member

lafriks commented Jan 2, 2020

Fomatic-ui should be dependency, and gulp devDependency

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
.PHONY: fomantic
fomantic: node-check node_modules
cd web_src/fomantic && npx gulp build

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it is possible to have this as a non-phony target that depends on package-lock.json, so it would only run if dependencies change.

Copy link
Member

@silverwind silverwind Jan 4, 2020

Choose a reason for hiding this comment

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

Also, I'd suggest the target to be adjusted to provide one or more output files, like public/fomantic/semantic.min.js and public/fomantic/semantic.min.css. We can still have a phony fomantic target that depends on that file to trigger it on-demand.

semantic.json Outdated Show resolved Hide resolved
Copy link
Contributor

@das7pad das7pad left a comment

Choose a reason for hiding this comment

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

@lunny @6543 I managed to devendor fomantic (8MB on disk) and implement the lazy build.

Feel free to cherry pick das7pad@6a012e9

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@lunny
Copy link
Member Author

lunny commented Jan 7, 2020

@das7pad Thanks! @lafriks @silverwind done.

@silverwind
Copy link
Member

Please remove the gulp dependency.

Not sure I like the approach of writing into node_modules, I think it may be better to do it outside and treat it as read-only.

@das7pad
Copy link
Contributor

das7pad commented Jan 7, 2020

Please remove the gulp dependency.

Can you help me understand why it should be removed?

Not sure I like the approach of writing into node_modules, I think it may be better to do it outside and treat it as read-only.

I do not like it either, but their imports dictate that this config file is placed in the source code:
https://github.com/fomantic/Fomantic-UI/blob/037a0402362fa2ffa44e434fe7e362c8cb753bb8/src/definitions/globals/reset.less#L18

As noted in the TODO, we can work around that with an alias/mock, but I could not find an easy solution for that using the gulp build tool. We could fix the fomantic source too, but i'm not sure it is worth the effort.

Makefile Outdated Show resolved Hide resolved
@silverwind
Copy link
Member

silverwind commented Jan 7, 2020

Can you help me understand why it should be removed?

Because it already comes in as a dependency of fomantic. If we depend on a specific version of it directly and fomantic updates their version, we'd end up with two versions which is not ideal (not sure which one would end up in the .bin scripts in that case).

If you really want to keep it, I'd suggest depending on version * so the more specific definition in fomantic would take precedence.

@das7pad
Copy link
Contributor

das7pad commented Jan 7, 2020

Thanks @silverwind !

Can you help me understand why it should be removed?

Because it already comes in as a dependency of fomantic. If we depend on a specific version of it directly and fomantic updates their version, we'd end up with two versions which is not ideal (not sure which one would end up in the .bin scripts in that case).

If you really want to keep it, I'd suggest depending on version * so the more specific definition in fomantic would take precedence.

Our version would go into .bin, theirs in their node_modules.
I do not think that having two versions is a problem per se. gulp4s' cli could be perfectly compatible with the gulp5 modules that their build-file loads. But gulp5 could also drop the -f option or expect a sub command to trigger the full build process. I would say the it is up to the developer who proposes a new fomantic (or gulp) version to make sure it is compatible with the build tooling.

I agree that we may be better off with a more loose version. ^4.0.0 would leave full room for minor/patch version upgrades but retain the major version at 4. IIRC * does not play nice with lock files and we do not want to end up with gulp9 when fomantic is stuck at 4.

@silverwind
Copy link
Member

In the end, it doesn't really matter much because we already lock dependencies. Still, I would recommend removing it from our dependencies, the fomantic docs also don't recommend adding gulp to the project dependencies.

package.json Outdated Show resolved Hide resolved
@lafriks
Copy link
Member

lafriks commented Jan 19, 2020

gulp should be added as devDependency

@lunny
Copy link
Member Author

lunny commented Jan 19, 2020

In the end, it doesn't really matter much because we already lock dependencies. Still, I would recommend removing it from our dependencies, the fomantic docs also don't recommend adding gulp to the project dependencies.

@lafriks as @silverwind mentioned. fomantic-ui has a dependency on gulp already.

@silverwind
Copy link
Member

@lafriks we discussed this a few times already. Given that gulp comes as a second-level dependency, I think it's better to not directly depend on it to allow fomantic-ui choose their appropriate version.

@lunny lunny merged commit 5cf241b into go-gitea:master Jan 21, 2020
@lunny lunny deleted the lunny/fomantic_npm branch January 21, 2020 05:18
@silverwind
Copy link
Member

@lunny: any specific reason why you added fomantic as prereq to js and css steps? I would prefer to be able to run webpack without fomantic building.

@lunny
Copy link
Member Author

lunny commented Jan 23, 2020

@silverwind I just thought, maybe some js or css files depend on fomantic since it's a basic framework. So I did that. If that's not a thing, I think we can change that.

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom fonts URL on fomantic