-
Notifications
You must be signed in to change notification settings - Fork 129
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
how to add css files #80
Comments
Hi, Thanks for kind words. 👍 Adding CSS is easy. I think what happens is that you don't have a task to copy CSS in We do use a bit of CSS in Mullvad VPN app and so we do have a task for that, feel free to copy the relevant bits: You will have to plug in the CSS-related tasks in the existing flow. Then update the Cheers, |
Thanks for the quick reply. I'm not familiar with Gulp or hotloading for Electron, so I'm sure in missing something. The CSS file is still not being copied Here is what I've done so far: tasks/assets.js tasks/watch.js gulpfile |
@roscoevanderboom just correct the path in |
I fixed it by including the the style at the top of index.html. I was only trying to add |
@pronebird haha...thanks. That's a lame mistake. I've update paths in assets.js and watch.js, but it still doesn't work. I'll figure it out at some point. For now the work-around is good enough. ps. I've used Mullvad before. Great VPN :) |
@roscoevanderboom add Then it should work. |
Here is the complete patch to add CSS into the boilerplate if someone else is looking to do that, just save the contents below to file, then run diff --git a/app/renderer/index.html b/app/renderer/index.html
index 5ac3b8e..0f3fc06 100644
--- a/app/renderer/index.html
+++ b/app/renderer/index.html
@@ -3,6 +3,7 @@
<head>
<title>My App</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'">
+ <link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="app"></div>
diff --git a/app/renderer/style.css b/app/renderer/style.css
new file mode 100644
index 0000000..a6c117b
--- /dev/null
+++ b/app/renderer/style.css
@@ -0,0 +1,3 @@
+body {
+ background: #fa0;
+}
diff --git a/gulpfile.js b/gulpfile.js
index ce6be41..f8be414 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -9,7 +9,7 @@ const dist = require('./tasks/distribution');
task('clean', function(done) {
rimraf('./build', done);
});
-task('build', series('clean', assets.copyHtml, scripts.build));
+task('build', series('clean', assets.copyHtml, assets.copyCss, scripts.build));
task('develop', series('clean', watch.start));
task('pack-win', series('build', dist.packWin));
task('pack-linux', series('build', dist.packLinux));
diff --git a/tasks/assets.js b/tasks/assets.js
index 0d67bf2..736385d 100644
--- a/tasks/assets.js
+++ b/tasks/assets.js
@@ -4,6 +4,12 @@ function copyHtml() {
return src('app/renderer/index.html').pipe(dest('build/renderer'));
}
+function copyCss() {
+ return src('app/renderer/**/*.css').pipe(dest('build/renderer'));
+}
+
copyHtml.displayName = 'copy-html';
+copyCss.displayName = 'copy-css';
exports.copyHtml = copyHtml;
+exports.copyCss = copyCss;
diff --git a/tasks/watch.js b/tasks/watch.js
index 5e3667d..3d37d69 100644
--- a/tasks/watch.js
+++ b/tasks/watch.js
@@ -19,14 +19,20 @@ function watchHtml() {
);
}
+function watchCss() {
+ return watch(['app/renderer/**/*.css'], series(assets.copyCss, hotreload.reload));
+}
+
watchMainScripts.displayName = 'watch-main-scripts';
watchRendererScripts.displayName = 'watch-renderer-scripts';
watchHtml.displayName = 'watch-html';
+watchCss.displayName = 'watch-css';
exports.start = series(
assets.copyHtml,
+ assets.copyCss,
scripts.developBuild,
hotreload.start,
electron.start,
- parallel(watchMainScripts, watchRendererScripts, watchHtml),
+ parallel(watchMainScripts, watchRendererScripts, watchHtml, watchCss),
); |
@pronebird Thanks. I followed your previous notes and everything is working very well. I learned a lot and can now manage adjusting the code as I need it. I have also set up Hotreload to watch more html files, as I have multiple browser windows in my app. Thanks for all the support and clear instructions. |
@pronebird @roscoevanderboom Where should the I have a file structure where a component such as one defined in
After applying the gulpfile patch, I am still unable to use the CSS definitions from What is the correct way to import the CSS styles? Thanks! |
@athenawisdoms You should be able to put the .css anywhere, as long as you set up the assets.js , watch.js and gulpfile.js to include .css files. |
In this example, I simply copy everything in the main and renderer processes as it changes. It's probably not the best strategy but work well for me. Assets.js Watch.js Gulpfile.js |
@roscoevanderboom Thanks for the fast replies and your .js files. I have replaced the 3 files
I have only added a
Not quite sure why this error is occurring... any help will be greatly appreciated!! |
Sorry. I'm not sure what is creating that error. Did you try the original suggestions made by pronebird? |
Why not ship the boilerplate with CSS support? It seems like a pretty common thing to want to import a CSS file? |
Ahh, I see that webpack isn't being used, and y'all want to keep the boilerplate agnostic. I can live with that, and understand the motivation. |
@athenawisdoms @edsu I forked and updated this boilerplate to include css files in any folder in the app/renderer path. Also updated Electron to latest. https://github.com/roscoevanderboom/electron-react-redux-boilerplate |
Historically, this boilerplate uses CSS in JS. We could probably have a gulp set up out-of-box to support CSS though. |
@roscoevanderboom thanks! I did manage to get CSS copying too. I'm new here, but it seems like a logical thing for this boilerplate to copy html, css and images by default--whatever your CSS preference is. |
@edsu you're welcome. This is a good boilerplate to work with. It's also pretty easy to setup extra browser windows or tray components. If you want to import more file types, start by
But like pronebird said, CSS in JS is the way to go. It's easy to build global style classes, then add to / overwrite properties in individual components. Objects ftw! Checkout MaterialUI templates. Them have great pre-made styles in JS |
First off, thanks for this excellent boilerplate! I've tried a few and I really like that the project is structured like an Electron project and not like a create-react-app project.
In my project, I've also added MaterialUI and everything is looking great. Now I want to add some custom style sheets. Adding css seems like a no-brainer...but I can't seem to get it to work.
I've tried import './styles.css as with React. Can't find module, no matter where I put the file.
I've tried adding link tags in the index.html file. GET request failed. Cannot find resource, unless file is in app/renderer and build/renderer directories. Once I restart application, the css file is removed from the build folder, even though it is still in app folder.
I'm sure it's got to do with the relative path Electron uses to render assets, but I can't seem to figure it.
The text was updated successfully, but these errors were encountered: