This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Added per mimetype reload strategies and stylesheet live reloading. #187
Open
Mike-Dax
wants to merge
6
commits into
electron-userland:master
Choose a base branch
from
Mike-Dax:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b2363ee
Changed how reloading is defined.
Mike-Dax 08780f9
Removed console.logs
Mike-Dax 7259075
Removed comments that don't pertain to this PR
Mike-Dax 625d6c6
Changed the reload method to hot-stylesheets
Mike-Dax 03842c8
Added vanilla stylesheets to the hot reload list.
Mike-Dax f4d1ce9
Made the reload function backwards compatible. Removed some commented…
Mike-Dax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import mimeTypes from '@paulcbetts/mime-types'; | ||
|
||
let HMR = false; | ||
let stylesheetReload = false; | ||
|
||
const d = require('debug')('electron-compile:require-hook'); | ||
let electron = null; | ||
|
@@ -9,6 +10,7 @@ if (process.type === 'renderer') { | |
window.__hot = []; | ||
electron = require('electron'); | ||
HMR = electron.remote.getGlobal('__electron_compile_hmr_enabled__'); | ||
stylesheetReload = electron.remote.getGlobal('__electron_compile_stylesheet_reload_enabled__'); | ||
|
||
if (HMR) { | ||
electron.ipcRenderer.on('__electron-compile__HMR', () => { | ||
|
@@ -25,6 +27,30 @@ if (process.type === 'renderer') { | |
window.__hot.forEach(fn => fn()); | ||
}); | ||
} | ||
|
||
if (stylesheetReload) { | ||
electron.ipcRenderer.on('__electron-compile__stylesheet_reload', (e, path) => { | ||
/*if (path.match(/.(jpg|jpeg|png|gif)$/i)) { | ||
let images = document.getElementsByTagName('img'); | ||
|
||
for (let img of images) { | ||
let uri = img.src | ||
if (uri.includes(path)) { | ||
img.src = img.src; // trigger an update | ||
} | ||
} | ||
} else {*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the status of this commented out code? Is this related to #188? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to make it so we could hot reload assets like images, but I'm not sure how these are treated by the dependency finder. If it's relatively plug and play I'll finish that up otherwise we can remove it. |
||
let links = document.getElementsByTagName('link'); | ||
|
||
for (let link of links) { | ||
let uri = link.href | ||
if (uri.includes(path)) { | ||
link.href = link.href; // trigger a reload for this stylesheet | ||
} | ||
} | ||
//} | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotta handle the old syntax here (i.e.
{ strategy: 'naive' }
) or else it is a breaking changeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Done in the latest commit.