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

Pull Bulma, FontAwesome and OpenSans locally #281

Closed
rabejens opened this issue Jun 27, 2019 · 8 comments
Closed

Pull Bulma, FontAwesome and OpenSans locally #281

rabejens opened this issue Jun 27, 2019 · 8 comments

Comments

@rabejens
Copy link

Currently, the SAFE template loads Bulma, FontAwesome and OpenSans from the web. This is problematic in many cases, i.e., when the application is to run in an environment without access to the Internet, or in the EU, for GDPR reasons.

There should be an option to pull these dependencies in locally, i.e. via yarn.

@isaacabraham
Copy link
Member

What's the cost of just doing this all the time? I suppose an increase in bundle size?

@rabejens
Copy link
Author

Yes, it inflates the bundle a fair share and makes compilation take longer, but as I said, I want to use the SAFE stack in some in-house web apps, which run on internal servers not connected to the internet, so I have to package everything locally.

If this is not wanted, here is how I did it, should anyone have the same issue:

I basically adapted html-to-elmish by @MangelMaxime - Repository

  1. Add the dependencies
yarn add --dev @fortawesome/fontawesome-free
yarn add --dev file-loader
yarn add bulma@0.7.1
yarn add open-sans-fonts
  1. Remove the imports in index.html
  2. Adjust style.scss:
@charset "utf-8";

// FontAwesome
$fa_font_path: "~@fortawesome/fontawesome-free/webfonts";
@import '~@fortawesome/fontawesome-free/scss/fontawesome.scss';
@import '~@fortawesome/fontawesome-free/scss/regular.scss';
@import '~@fortawesome/fontawesome-free/scss/solid.scss';
@import '~@fortawesome/fontawesome-free/scss/brands.scss';

// OpenSans
$FontPathOpenSans: "~open-sans-fonts/open-sans";
@import '~open-sans-fonts/open-sans';
body {
  font-family: 'Open Sans' !important;
}

// Bulma
@import "~bulma/bulma";
  1. Re-run fake build -t Run (or the other targets)

If bundle size is an issue, this should not be the default, but it could be an option, like dotnet new SAFE --bulma local --fontawesome local --opensans local

@MangelMaxime
Copy link
Contributor

What's the cost of just doing this all the time? I suppose an increase in bundle size?

Yes and no.

The bundle.js will not change because it contains only the JavaScript code but you will have a new file mystyle.css to load instead of using the CDN.

For your application, it will be the same because it doesn't care if you are loading Bulma from a CDN or from your server.

However, using your own version means you can customize everything.

For example, if you want to change the primary colour in Bulma using scss you can just do $primary: red; and that's it.

If you do it using a CDN version, then you have to manually override each component of Bulma:

.navbaris-primary {
    background-color: red;
}

.button.is-primary {
    background-color: red;
}

// etc.
// And you also need to update manually the derived values etc.

Using a CDN make sense if you don't want to customize Bulma (which probably never happen ^^). Or don't want to write your own components using Bulma variables etc.

@MangelMaxime
Copy link
Contributor

Another remark is that by using a local version of Bulma you can import only the feature you need and so decrease overall size loaded by your application.

You can also run it against an autoprefixer which will take care for you to make your CSS works across all the browsers (it similar to what Babel does for example).

@isaacabraham
Copy link
Member

All in favour of moving over to including the CSS locally please thumbs up this comment :-)

@theimowski
Copy link
Member

theimowski commented Jun 28, 2019

Yup seems pros outweigh cons - @rabejens happy to contribute?
I think we don't need that to be an option

@rabejens
Copy link
Author

I am currently looking into it.

@theimowski
Copy link
Member

closed by #286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants