question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question regarding static CSS file

See original GitHub issue

First, thanks for this awesome project! It’s been a huge help to give me a starting point for my app.

I am using ElementUI in my project, and I have generated a custom theme. I have two questions about how to include this stylesheet in my project:

  1. Where is the proper place to put this file? I am assuming I should use the /static directory?
  2. How should I be including the file? I know that /src/index.ejs automatically includes any stylesheets that are imported in /src/renderer/main.js (for example, import 'bulma/css/bulma.css'). But as this is a static file and not part of a node module, I cannot import the stylesheet in this way.

My current solution is to place the file in the /static directory, and manually add it to the <head> tag in /src/index.ejs (eg. <link rel="stylesheet" href="static/theme.css">), but will that work in production?

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
onekiloparseccommented, Jan 25, 2018

I had similar questions. I found it suprisingly complicated to go through the number of possibilities, without reading tons of barely-related documentation, given that you have to build the app to check whether the production app is also ok, while its config is different.

I :

  • have a global bootstrap theme css
  • have a generated custom style (bought somewhere) generated-custom-style.css and that refer to some fonts (FontAwesome & open-iconic) with paths like ../fonts
  • a personal style that tweaks the one above: my-style-global-tweaks.css
  • import fonts from Google
  • use fontawesome with <i class="fa fa-...">
  • have some static icons and images
  • want to use some icons in css’s files like url('<path>');

Finally, after many trials and errors, I came up with the following setup:

node_modules/ (with bootstrap installed through npm)
static/
β”œβ”€ img/
β”‚  └─ icon1.png
β”‚  └─ icon2.png
src/
β”‚  └─ index.ejs
β”‚  β”œβ”€ main/
β”‚  β”‚  β”œβ”€ index.dev.js
β”‚  β”‚  └─ index.js
β”‚  β”œβ”€ renderer/
β”‚  β”‚  β”œβ”€ assets/
β”‚  β”‚  β”‚  β”œβ”€ css/
β”‚  β”‚  β”‚  β”‚  └─ font-awesome.min.css
β”‚  β”‚  β”‚  β”‚  └─ open-iconic-bootstrap.css
β”‚  β”‚  β”‚  β”‚  └─ generated-custom-style.css
β”‚  β”‚  β”‚  β”‚  └─ my-style-global-tweaks.css
β”‚  β”‚  β”‚  β”œβ”€ fonts/
β”‚  β”‚  β”‚  β”‚  └─ fontawesome-webfont.ttf (+ woff, woff2 etc...)
β”‚  β”‚  β”‚  β”‚  └─ open-iconic.woff (etc...)
β”‚  β”‚  β”‚  β”œβ”€ img/
β”‚  β”‚  β”‚  β”‚  └─ icon1.png (yes duplicate from /static... )
β”‚  β”‚  β”‚  β”‚  └─ icon2.png

and then:

  • In my-style-tweaks.css, I can use background: url('~@/assets/img/...') (note the ~@/, coming from here).
  • Inside any Component.vue file, in the <template> section, I can use <img id="logo" src="static/img/logo-circle.png"> (note the absence of any ~, @, ./ etc…)
  • In src/renderer/main.js I have a line import 'bootstrap3/dist/css/bootstrap.min.css'
  • In the <style> section of the App.vue file, I load all global stuff:
<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
  export default {
    name: 'arcsecond-uploader'
  }
</script>

<style>
  @import url('https://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic');
  @import url('https://fonts.googleapis.com/css?family=Oswald:400,700,300');
  @import url('https://fonts.googleapis.com/css?family=Inconsolata');
  @import url('~@/assets/css/font-awesome.min.css');
  @import url('~@/assets/css/open-iconic-bootstrap.css');
  @import url('~@/assets/css/generated-custom-style.css');
  @import url('~@/assets/css/my-style-global-tweaks.css');
</style>

It works in dev and prod.

I’m happy if anyone come up with a better solution. As for now, I’ll try to produce some real stuff…

1reaction
pixeldesucommented, Dec 6, 2017

There’s a guide for the usage of static files in the documentation, right here!
https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to refer to static files in my css files? - Stack Overflow
Use a relative path. Relative to the folder where the css file reside.
Read more >
Top 30+ CSS Interview Questions (2023) - InterviewBit
Find top CSS interview questions asked. Explore basic, intermediate, and advanced level questions.
Read more >
Top 75+ CSS Interview Questions You Should Prepare
Cover the top CSS interview questions asked by popular companies. Prepare for the frequently ask'd CSS questions from beginners to advancedΒ ...
Read more >
When to Use Static CSS File Generation. : r/divi - Reddit
Hello. I am new to web development and using Divi in particular. I have a question regarding static CSS file generation.
Read more >
Top 50 HTML Interview Questions and Answers in 2023
HTML is one of the most widely used languages on Web to develop web pages. ... When you try to open the external...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found